dsh-gufa-code 1.3.82 → 1.3.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/client.js +315 -49
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float/bin/gufa-float-macos-universal +0 -0
- package/desktop/float/bin/gufa-float-macos-x64 +0 -0
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
- package/docs/KNOWN-PITFALLS.md +15 -0
- package/host/fs.js +4 -0
- package/host/lsp.js +350 -0
- package/package.json +2 -1
- package/src/client/00-core.js +2 -0
- package/src/client/20-editor.js +312 -48
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ dsh plugin add dsh-gufa-code
|
|
|
41
41
|
- Monaco 编辑器(离线随包分发,无需联网下载);
|
|
42
42
|
- 多标签、按扩展名语法高亮、面包屑、状态栏(分支 / 行列 / 保存状态);
|
|
43
43
|
- 保存走磁盘版本冲突检测 + 原子写;未保存标记;
|
|
44
|
-
- **⌘/Ctrl + 点击跳转定义 /
|
|
44
|
+
- **⌘/Ctrl + 点击跳转定义 / 方法实现**:Python 走 **Pyright 语言服务(LSP)**,JS/TS 走 Monaco 内置 TypeScript 语言服务(点击前会按需把当前文件的 import 依赖加载进 Monaco,跨文件变量/函数由 TS 语言服务解析);其他语言暂用项目级定义搜索兜底;优先走 Monaco 语言服务;目标文件没在 Monaco 里打开、或语言没有内置语言服务时,自动用项目级定义搜索兜底(函数 / 类 / 方法 / const / type 等声明)。兜底会解析 import/require 直接定位来源文件,并跳过压缩产物/大文件;同一个文件里的声明、import 命中的定义、目录距离近的定义直接跳,只有多个真正同名的声明才弹「跳转到定义」列表,点同名属性/变量时不会拿远端无关的 const 来凑数;按住 ⌘/Ctrl 悬停时,可跳转的符号会显示下划线 + 手型光标;
|
|
45
45
|
- **全局搜索 / 替换**(左栏放大镜 / `⌘⇧F`):整个项目的文本搜索,支持区分大小写、正则、包含/排除文件(glob);结果按文件分组、高亮匹配,点击跳转行列;替换栏支持保留大小写(AB)、全部替换(需确认)、按文件替换(悬停文件头铅笔)、按单行匹配替换与忽略(悬停结果行);替换前会自动保存未落盘的编辑器内容;Git 项目用 `git ls-files` 枚举文件(尊重 `.gitignore`、含未跟踪文件),非 Git 项目遍历目录并自动跳过 `node_modules` 等依赖/缓存目录;摸鱼悬浮窗里同样可用;
|
|
46
46
|
- 资源管理器右键:新建 / 重命名 / 删除 / 复制 / 粘贴 / 打开所在文件夹 / 两文件对比;
|
|
47
47
|
- **从 Finder 粘贴/拖入文件**:系统剪贴板里复制的文件可直接 ⌘V 粘进资源管理器(写入选中的目录,重名自动加「副本」),也可从 Finder 直接拖进文件树;
|
package/client.js
CHANGED
|
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
|
|
|
16
16
|
const G = {}
|
|
17
17
|
G.NS = GUFA_NS
|
|
18
18
|
/** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
|
|
19
|
-
G.BUILD = '1.3.
|
|
19
|
+
G.BUILD = '1.3.88'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -1685,6 +1685,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1685
1685
|
border-bottom:1px solid var(--gufa-border);overflow:hidden;white-space:nowrap}
|
|
1686
1686
|
.gufa-breadcrumb b{font-weight:500;color:var(--gufa-text)}
|
|
1687
1687
|
.gufa-editor-host{flex:1 1 auto;position:relative;min-height:0;min-width:0;overflow:hidden}
|
|
1688
|
+
.gufa-def-link{text-decoration:underline;text-decoration-color:var(--gufa-accent);text-decoration-thickness:1px;text-underline-offset:2px;cursor:pointer}
|
|
1689
|
+
.monaco-editor.gufa-def-hover .view-lines{cursor:pointer}
|
|
1688
1690
|
.gufa-editor-fallback{position:absolute;inset:0;overflow:auto;margin:0;padding:14px 18px;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre;tab-size:2}
|
|
1689
1691
|
.gufa-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;height:100%;padding:28px;
|
|
1690
1692
|
color:var(--gufa-text-dim);text-align:center}
|
|
@@ -2748,7 +2750,7 @@ G.FooterAction = function FooterAction(props) {
|
|
|
2748
2750
|
}
|
|
2749
2751
|
|
|
2750
2752
|
/** 这些声明类型算「定义级」,多个同名时值得让用户选;普通 const/赋值等弱匹配不轻易弹列表。 */
|
|
2751
|
-
const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'def', 'func', 'fn', 'type', 'export'])
|
|
2753
|
+
const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'def', 'func', 'fn', 'type', 'export', 'lsp'])
|
|
2752
2754
|
|
|
2753
2755
|
/* ── model / URI ────────────────────────────────────────────────────── */
|
|
2754
2756
|
|
|
@@ -3030,12 +3032,21 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3030
3032
|
if (host === null) return undefined
|
|
3031
3033
|
let cancelled = false
|
|
3032
3034
|
let editor = null
|
|
3035
|
+
let definitionCleanup = null
|
|
3033
3036
|
const subscriptions = []
|
|
3034
3037
|
|
|
3035
3038
|
setStatus('loading')
|
|
3036
3039
|
setMonacoError('')
|
|
3037
3040
|
|
|
3038
3041
|
const disposeEditor = () => {
|
|
3042
|
+
if (definitionCleanup !== null) {
|
|
3043
|
+
try {
|
|
3044
|
+
definitionCleanup()
|
|
3045
|
+
} catch {
|
|
3046
|
+
/* ignore */
|
|
3047
|
+
}
|
|
3048
|
+
definitionCleanup = null
|
|
3049
|
+
}
|
|
3039
3050
|
for (const subscription of subscriptions.splice(0)) {
|
|
3040
3051
|
try {
|
|
3041
3052
|
subscription.dispose()
|
|
@@ -3098,11 +3109,274 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3098
3109
|
}
|
|
3099
3110
|
})
|
|
3100
3111
|
|
|
3101
|
-
/* Cmd/Ctrl
|
|
3102
|
-
|
|
3112
|
+
/* Cmd/Ctrl+点击跳转定义 + Cmd 悬停「可点击」提示:先走 Monaco 语言服务;
|
|
3113
|
+
没有提供者(未打开的文件、非 TS/JS 语言等)时回退到 Host 的项目级定义搜索。 */
|
|
3103
3114
|
try {
|
|
3104
|
-
const
|
|
3105
|
-
if (
|
|
3115
|
+
const editorDom = typeof instance.getDomNode === 'function' ? instance.getDomNode() : null
|
|
3116
|
+
if (editorDom !== null && editorDom !== undefined) {
|
|
3117
|
+
const isPrimaryEvent = (event) => {
|
|
3118
|
+
const mac = typeof G.isMacPlatform === 'function' ? G.isMacPlatform() : true
|
|
3119
|
+
return mac ? event.metaKey === true : event.ctrlKey === true
|
|
3120
|
+
}
|
|
3121
|
+
/* JS/TS:把当前文件的 import 依赖按需加载成 Monaco model,让 TS 语言服务
|
|
3122
|
+
能解析跨文件定义;否则 Monaco 只认识已经打开过的标签。 */
|
|
3123
|
+
const tsPreloadState = { seen: new Set() }
|
|
3124
|
+
const preloadTsDependencies = async (model, path, root) => {
|
|
3125
|
+
const language = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
|
|
3126
|
+
if (language !== 'typescript' && language !== 'javascript') return
|
|
3127
|
+
const version = typeof model.getVersionId === 'function' ? model.getVersionId() : 0
|
|
3128
|
+
const key = `${path}|${version}`
|
|
3129
|
+
if (tsPreloadState.seen.has(key) || tsPreloadState.seen.size > 200) return
|
|
3130
|
+
tsPreloadState.seen.add(key)
|
|
3131
|
+
let content = ''
|
|
3132
|
+
try {
|
|
3133
|
+
content = model.getValue()
|
|
3134
|
+
} catch {
|
|
3135
|
+
return
|
|
3136
|
+
}
|
|
3137
|
+
const specs = []
|
|
3138
|
+
for (const pattern of [/import\s+(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]/g, /require\(\s*['"]([^'"]+)['"]\s*\)/g]) {
|
|
3139
|
+
let match = null
|
|
3140
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
3141
|
+
if (typeof match[1] === 'string' && match[1].startsWith('.')) specs.push(match[1])
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
const baseDir = path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : ''
|
|
3145
|
+
const candidates = (spec) => {
|
|
3146
|
+
const raw = `${baseDir}${baseDir === '' ? '' : '/'}${spec}`
|
|
3147
|
+
const parts = []
|
|
3148
|
+
for (const part of raw.split('/')) {
|
|
3149
|
+
if (part === '' || part === '.') continue
|
|
3150
|
+
if (part === '..') parts.pop()
|
|
3151
|
+
else parts.push(part)
|
|
3152
|
+
}
|
|
3153
|
+
const base = parts.join('/')
|
|
3154
|
+
return [base, `${base}.ts`, `${base}.tsx`, `${base}.js`, `${base}.jsx`, `${base}.mjs`, `${base}.cjs`, `${base}.d.ts`, `${base}/index.ts`, `${base}/index.js`, `${base}/index.tsx`]
|
|
3155
|
+
}
|
|
3156
|
+
for (const spec of [...new Set(specs)].slice(0, 30)) {
|
|
3157
|
+
for (const rel of candidates(spec)) {
|
|
3158
|
+
try {
|
|
3159
|
+
const doc = await G.api('fs.read', { root, path: rel })
|
|
3160
|
+
const uri = gufaModelUri(monaco, root, rel)
|
|
3161
|
+
if (monaco.editor.getModel(uri) === null) {
|
|
3162
|
+
monaco.editor.createModel(String(doc.content ?? ''), gufaResolveLanguage(monaco, doc.language), uri)
|
|
3163
|
+
}
|
|
3164
|
+
break
|
|
3165
|
+
} catch {
|
|
3166
|
+
/* 尝试下一个候选 */
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
const queryDefinitions = (position, word, model, path, root) => {
|
|
3172
|
+
const language = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
|
|
3173
|
+
if (language === 'python') {
|
|
3174
|
+
return G.api('lsp.definition', {
|
|
3175
|
+
root,
|
|
3176
|
+
path,
|
|
3177
|
+
line: position.lineNumber,
|
|
3178
|
+
column: position.column,
|
|
3179
|
+
language: 'python',
|
|
3180
|
+
content: model.getValue(),
|
|
3181
|
+
}).then((value) => ({
|
|
3182
|
+
matches: value !== null && value !== undefined && Array.isArray(value.matches) ? value.matches : [],
|
|
3183
|
+
current: value !== null && value !== undefined && value.current !== undefined ? value.current : undefined,
|
|
3184
|
+
word,
|
|
3185
|
+
}))
|
|
3186
|
+
}
|
|
3187
|
+
return G.api('code.definition', {
|
|
3188
|
+
root,
|
|
3189
|
+
path,
|
|
3190
|
+
line: position.lineNumber,
|
|
3191
|
+
column: position.column,
|
|
3192
|
+
word,
|
|
3193
|
+
content: model.getValue(),
|
|
3194
|
+
})
|
|
3195
|
+
}
|
|
3196
|
+
const decideDefinition = (result) => {
|
|
3197
|
+
const matches = result !== null && result !== undefined && Array.isArray(result.matches) ? result.matches : []
|
|
3198
|
+
if (matches.length === 0) return { kind: 'none' }
|
|
3199
|
+
const currentPath = result.current !== null && result.current !== undefined && typeof result.current.path === 'string' ? result.current.path : null
|
|
3200
|
+
const top = matches[0]
|
|
3201
|
+
const topScore = Number(top.score) || 0
|
|
3202
|
+
if (currentPath !== null && top.path === currentPath) return { kind: 'open', match: top }
|
|
3203
|
+
const isStrong = (item) => GUFA_DEFINITION_STRONG_KINDS.has(item.kind)
|
|
3204
|
+
if (!isStrong(top) && topScore < 50) return { kind: 'none' }
|
|
3205
|
+
if (topScore < 30) return { kind: 'none' }
|
|
3206
|
+
const cluster = matches.filter((item) => (Number(item.score) || 0) >= topScore - 8).slice(0, 8)
|
|
3207
|
+
if (cluster.length === 1) return { kind: 'open', match: cluster[0] }
|
|
3208
|
+
const declCluster = cluster.filter((item) => isStrong(item))
|
|
3209
|
+
if (declCluster.length === 0) {
|
|
3210
|
+
const secondScore = matches.length > 1 ? Number(matches[1].score) || 0 : 0
|
|
3211
|
+
return topScore >= 50 && topScore - secondScore >= 10 ? { kind: 'open', match: top } : { kind: 'none' }
|
|
3212
|
+
}
|
|
3213
|
+
const distinctFiles = new Set(declCluster.map((item) => item.path))
|
|
3214
|
+
if (distinctFiles.size === 1) return { kind: 'open', match: declCluster[0] }
|
|
3215
|
+
return { kind: 'pick', matches: declCluster }
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3218
|
+
/* ── Cmd 悬停:可跳转时下划线 + 手型光标 ─────────────── */
|
|
3219
|
+
const hover = { meta: false, timer: 0, seq: 0, cache: new Map(), decorationIds: [], lastClient: null, lastPosition: null, lastWordInfo: null, lastKey: '' }
|
|
3220
|
+
const clearHoverDecoration = () => {
|
|
3221
|
+
if (hover.decorationIds.length > 0) {
|
|
3222
|
+
try {
|
|
3223
|
+
hover.decorationIds = instance.deltaDecorations(hover.decorationIds, [])
|
|
3224
|
+
} catch {
|
|
3225
|
+
hover.decorationIds = []
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
try {
|
|
3229
|
+
editorDom.classList.remove('gufa-def-hover')
|
|
3230
|
+
} catch {
|
|
3231
|
+
/* ignore */
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
const showHoverDecoration = (position, wordInfo) => {
|
|
3235
|
+
if (wordInfo === null || wordInfo === undefined) return clearHoverDecoration()
|
|
3236
|
+
let range = null
|
|
3237
|
+
try {
|
|
3238
|
+
range = new monaco.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn)
|
|
3239
|
+
} catch {
|
|
3240
|
+
return clearHoverDecoration()
|
|
3241
|
+
}
|
|
3242
|
+
try {
|
|
3243
|
+
hover.decorationIds = instance.deltaDecorations(hover.decorationIds, [
|
|
3244
|
+
{ range, options: { inlineClassName: 'gufa-def-link', stickiness: 1 } },
|
|
3245
|
+
])
|
|
3246
|
+
} catch {
|
|
3247
|
+
/* ignore */
|
|
3248
|
+
}
|
|
3249
|
+
try {
|
|
3250
|
+
editorDom.classList.add('gufa-def-hover')
|
|
3251
|
+
} catch {
|
|
3252
|
+
/* ignore */
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
const evaluateHoverPosition = (position, wordInfo) => {
|
|
3256
|
+
if (!hover.meta) {
|
|
3257
|
+
clearHoverDecoration()
|
|
3258
|
+
return
|
|
3259
|
+
}
|
|
3260
|
+
const model = instance.getModel()
|
|
3261
|
+
const word = wordInfo !== null && wordInfo !== undefined && typeof wordInfo.word === 'string' ? wordInfo.word : ''
|
|
3262
|
+
const path = modelPathRef.current
|
|
3263
|
+
const root = modelsRootRef.current
|
|
3264
|
+
if (position === null || position === undefined || model === null || model === undefined
|
|
3265
|
+
|| word.length < 2 || path === null || path === undefined || root === null || root === undefined || root === '') {
|
|
3266
|
+
clearHoverDecoration()
|
|
3267
|
+
return
|
|
3268
|
+
}
|
|
3269
|
+
hover.lastPosition = position
|
|
3270
|
+
hover.lastWordInfo = wordInfo
|
|
3271
|
+
const key = `${path}|${word}`
|
|
3272
|
+
hover.lastKey = key
|
|
3273
|
+
const cached = hover.cache.get(key)
|
|
3274
|
+
if (cached === 'none') {
|
|
3275
|
+
clearHoverDecoration()
|
|
3276
|
+
return
|
|
3277
|
+
}
|
|
3278
|
+
if (cached === 'yes') {
|
|
3279
|
+
showHoverDecoration(position, wordInfo)
|
|
3280
|
+
return
|
|
3281
|
+
}
|
|
3282
|
+
if (hover.timer !== 0) {
|
|
3283
|
+
window.clearTimeout(hover.timer)
|
|
3284
|
+
hover.timer = 0
|
|
3285
|
+
}
|
|
3286
|
+
const seq = ++hover.seq
|
|
3287
|
+
hover.timer = window.setTimeout(() => {
|
|
3288
|
+
hover.timer = 0
|
|
3289
|
+
if (!hover.meta || seq !== hover.seq) return
|
|
3290
|
+
void queryDefinitions(position, word, model, path, root).then((result) => {
|
|
3291
|
+
if (!hover.meta || seq !== hover.seq || hover.lastKey !== key) return
|
|
3292
|
+
const decision = decideDefinition(result)
|
|
3293
|
+
if (decision.kind === 'none') {
|
|
3294
|
+
if (hover.cache.size > 100) hover.cache.clear()
|
|
3295
|
+
hover.cache.set(key, 'none')
|
|
3296
|
+
clearHoverDecoration()
|
|
3297
|
+
return
|
|
3298
|
+
}
|
|
3299
|
+
if (hover.cache.size > 100) hover.cache.clear()
|
|
3300
|
+
hover.cache.set(key, 'yes')
|
|
3301
|
+
showHoverDecoration(position, wordInfo)
|
|
3302
|
+
}).catch(() => {
|
|
3303
|
+
/* ignore */
|
|
3304
|
+
})
|
|
3305
|
+
}, 130)
|
|
3306
|
+
}
|
|
3307
|
+
/* 用 Monaco 自己的 onMouseMove(带修饰键状态 + 精确 position),
|
|
3308
|
+
不依赖 DOM mousedown/getTargetAtClientPoint 的坐标系与包含关系。 */
|
|
3309
|
+
const onMonacoMouseMove = (editorEvent) => {
|
|
3310
|
+
if (editorEvent === null || editorEvent === undefined) return
|
|
3311
|
+
const browser = editorEvent.event !== null && editorEvent.event !== undefined ? editorEvent.event.browserEvent : null
|
|
3312
|
+
const mac = typeof G.isMacPlatform === 'function' ? G.isMacPlatform() : true
|
|
3313
|
+
const pressed = browser !== null && browser !== undefined
|
|
3314
|
+
? (mac ? browser.metaKey === true : browser.ctrlKey === true)
|
|
3315
|
+
: false
|
|
3316
|
+
if (!pressed) {
|
|
3317
|
+
if (hover.meta) {
|
|
3318
|
+
hover.meta = false
|
|
3319
|
+
hover.seq += 1
|
|
3320
|
+
if (hover.timer !== 0) {
|
|
3321
|
+
window.clearTimeout(hover.timer)
|
|
3322
|
+
hover.timer = 0
|
|
3323
|
+
}
|
|
3324
|
+
clearHoverDecoration()
|
|
3325
|
+
}
|
|
3326
|
+
return
|
|
3327
|
+
}
|
|
3328
|
+
hover.meta = true
|
|
3329
|
+
const target = editorEvent.target !== null && editorEvent.target !== undefined ? editorEvent.target : null
|
|
3330
|
+
const position = target !== null ? target.position : null
|
|
3331
|
+
if (position === null || position === undefined) {
|
|
3332
|
+
clearHoverDecoration()
|
|
3333
|
+
return
|
|
3334
|
+
}
|
|
3335
|
+
let wordInfo = null
|
|
3336
|
+
try {
|
|
3337
|
+
const model = instance.getModel()
|
|
3338
|
+
wordInfo = model !== null && model !== undefined ? model.getWordAtPosition(position) : null
|
|
3339
|
+
} catch {
|
|
3340
|
+
wordInfo = null
|
|
3341
|
+
}
|
|
3342
|
+
evaluateHoverPosition(position, wordInfo)
|
|
3343
|
+
}
|
|
3344
|
+
const onMetaDown = (event) => {
|
|
3345
|
+
if (event.key !== 'Meta' && event.key !== 'Control') return
|
|
3346
|
+
if (hover.meta) return
|
|
3347
|
+
hover.meta = true
|
|
3348
|
+
if (hover.lastPosition !== null && hover.lastWordInfo !== null) evaluateHoverPosition(hover.lastPosition, hover.lastWordInfo)
|
|
3349
|
+
}
|
|
3350
|
+
const onMetaUp = (event) => {
|
|
3351
|
+
if (event.key !== 'Meta' && event.key !== 'Control') return
|
|
3352
|
+
hover.meta = false
|
|
3353
|
+
hover.seq += 1
|
|
3354
|
+
if (hover.timer !== 0) {
|
|
3355
|
+
window.clearTimeout(hover.timer)
|
|
3356
|
+
hover.timer = 0
|
|
3357
|
+
}
|
|
3358
|
+
clearHoverDecoration()
|
|
3359
|
+
}
|
|
3360
|
+
const onDefWindowBlur = () => {
|
|
3361
|
+
hover.meta = false
|
|
3362
|
+
clearHoverDecoration()
|
|
3363
|
+
}
|
|
3364
|
+
const hoverSubscriptions = []
|
|
3365
|
+
try {
|
|
3366
|
+
if (typeof instance.onMouseMove === 'function') hoverSubscriptions.push(instance.onMouseMove(onMonacoMouseMove))
|
|
3367
|
+
if (typeof instance.onMouseLeave === 'function') hoverSubscriptions.push(instance.onMouseLeave(() => {
|
|
3368
|
+
hover.meta = false
|
|
3369
|
+
hover.lastPosition = null
|
|
3370
|
+
hover.lastWordInfo = null
|
|
3371
|
+
hover.seq += 1
|
|
3372
|
+
clearHoverDecoration()
|
|
3373
|
+
}))
|
|
3374
|
+
if (typeof instance.onDidChangeModelContent === 'function') hoverSubscriptions.push(instance.onDidChangeModelContent(() => clearHoverDecoration()))
|
|
3375
|
+
if (typeof instance.onDidScrollChange === 'function') hoverSubscriptions.push(instance.onDidScrollChange(() => clearHoverDecoration()))
|
|
3376
|
+
} catch {
|
|
3377
|
+
/* ignore */
|
|
3378
|
+
}
|
|
3379
|
+
for (const subscription of hoverSubscriptions) if (subscription !== null && subscription !== undefined) subscriptions.push(subscription)
|
|
3106
3380
|
const onDefinitionClick = async (event) => {
|
|
3107
3381
|
try {
|
|
3108
3382
|
const currentDom = typeof instance.getDomNode === 'function' ? instance.getDomNode() : null
|
|
@@ -3111,9 +3385,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3111
3385
|
return
|
|
3112
3386
|
}
|
|
3113
3387
|
if (event.button !== 0 || event.defaultPrevented === true) return
|
|
3114
|
-
|
|
3115
|
-
const pressed = primary ? event.metaKey === true : event.ctrlKey === true
|
|
3116
|
-
if (!pressed || event.altKey === true || event.shiftKey === true) return
|
|
3388
|
+
if (!isPrimaryEvent(event) || event.altKey === true || event.shiftKey === true) return
|
|
3117
3389
|
if (event.target instanceof Element && event.target.closest('a') !== null) return
|
|
3118
3390
|
let target = null
|
|
3119
3391
|
try {
|
|
@@ -3134,13 +3406,18 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3134
3406
|
if (word.length < 2) return
|
|
3135
3407
|
const path = modelPathRef.current
|
|
3136
3408
|
const root = modelsRootRef.current
|
|
3137
|
-
if (path === null || root === null || root === '') return
|
|
3409
|
+
if (path === null || path === undefined || root === null || root === undefined || root === '') return
|
|
3138
3410
|
try {
|
|
3139
3411
|
event.preventDefault()
|
|
3140
3412
|
event.stopPropagation()
|
|
3141
3413
|
} catch {
|
|
3142
3414
|
/* ignore */
|
|
3143
3415
|
}
|
|
3416
|
+
try {
|
|
3417
|
+
await preloadTsDependencies(model, path, root)
|
|
3418
|
+
} catch {
|
|
3419
|
+
/* ignore */
|
|
3420
|
+
}
|
|
3144
3421
|
const beforePath = modelPathRef.current
|
|
3145
3422
|
const beforePosition = instance.getPosition()
|
|
3146
3423
|
try {
|
|
@@ -3163,55 +3440,44 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3163
3440
|
} catch {
|
|
3164
3441
|
monacoHandled = false
|
|
3165
3442
|
}
|
|
3443
|
+
clearHoverDecoration()
|
|
3166
3444
|
if (monacoHandled) return
|
|
3167
3445
|
try {
|
|
3168
|
-
const result = await
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
line:
|
|
3172
|
-
column: position.column,
|
|
3173
|
-
word,
|
|
3174
|
-
content: model.getValue(),
|
|
3175
|
-
})
|
|
3176
|
-
const matches = result !== null && result !== undefined && Array.isArray(result.matches) ? result.matches : []
|
|
3177
|
-
if (matches.length === 0) return
|
|
3178
|
-
const openMatch = (item) => G.bus.emit('editor:open-at', { path: item.path, line: item.line, column: item.column })
|
|
3179
|
-
const currentPath = result.current !== null && result.current !== undefined && typeof result.current.path === 'string' ? result.current.path : null
|
|
3180
|
-
const top = matches[0]
|
|
3181
|
-
const topScore = Number(top.score) || 0
|
|
3182
|
-
/* 当前文件里的声明:直接跳,不打扰 */
|
|
3183
|
-
if (currentPath !== null && top.path === currentPath) {
|
|
3184
|
-
openMatch(top)
|
|
3446
|
+
const result = await queryDefinitions(position, word, model, path, root)
|
|
3447
|
+
const decision = decideDefinition(result)
|
|
3448
|
+
if (decision.kind === 'open') {
|
|
3449
|
+
G.bus.emit('editor:open-at', { path: decision.match.path, line: decision.match.line, column: decision.match.column })
|
|
3185
3450
|
return
|
|
3186
3451
|
}
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
return
|
|
3195
|
-
}
|
|
3196
|
-
const declCluster = cluster.filter((item) => isStrong(item))
|
|
3197
|
-
if (declCluster.length === 0) {
|
|
3198
|
-
const secondScore = matches.length > 1 ? Number(matches[1].score) || 0 : 0
|
|
3199
|
-
if (topScore >= 50 && topScore - secondScore >= 10) {
|
|
3200
|
-
openMatch(top)
|
|
3201
|
-
}
|
|
3202
|
-
return
|
|
3203
|
-
}
|
|
3204
|
-
const distinctFiles = new Set(declCluster.map((item) => item.path))
|
|
3205
|
-
if (distinctFiles.size === 1) {
|
|
3206
|
-
openMatch(declCluster[0])
|
|
3207
|
-
return
|
|
3452
|
+
if (decision.kind === 'pick') {
|
|
3453
|
+
G.bus.emit('definition:pick', {
|
|
3454
|
+
word: result !== null && result !== undefined && typeof result.word === 'string' ? result.word : word,
|
|
3455
|
+
matches: decision.matches,
|
|
3456
|
+
x: event.clientX,
|
|
3457
|
+
y: event.clientY,
|
|
3458
|
+
})
|
|
3208
3459
|
}
|
|
3209
|
-
G.bus.emit('definition:pick', { word: result.word ?? word, matches: declCluster, x: event.clientX, y: event.clientY })
|
|
3210
3460
|
} catch {
|
|
3211
3461
|
/* ignore */
|
|
3212
3462
|
}
|
|
3213
3463
|
}
|
|
3214
3464
|
document.addEventListener('mousedown', onDefinitionClick, true)
|
|
3465
|
+
document.addEventListener('keydown', onMetaDown, true)
|
|
3466
|
+
document.addEventListener('keyup', onMetaUp, true)
|
|
3467
|
+
window.addEventListener('blur', onDefWindowBlur)
|
|
3468
|
+
definitionCleanup = () => {
|
|
3469
|
+
document.removeEventListener('mousedown', onDefinitionClick, true)
|
|
3470
|
+
document.removeEventListener('keydown', onMetaDown, true)
|
|
3471
|
+
document.removeEventListener('keyup', onMetaUp, true)
|
|
3472
|
+
window.removeEventListener('blur', onDefWindowBlur)
|
|
3473
|
+
if (hover.timer !== 0) {
|
|
3474
|
+
window.clearTimeout(hover.timer)
|
|
3475
|
+
hover.timer = 0
|
|
3476
|
+
}
|
|
3477
|
+
hover.seq += 1
|
|
3478
|
+
hover.meta = false
|
|
3479
|
+
clearHoverDecoration()
|
|
3480
|
+
}
|
|
3215
3481
|
}
|
|
3216
3482
|
} catch {
|
|
3217
3483
|
/* ignore */
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
|
|
8
8
|
<key>CFBundleExecutable</key><string>gufa-float</string>
|
|
9
9
|
<key>CFBundlePackageType</key><string>APPL</string>
|
|
10
|
-
<key>CFBundleShortVersionString</key><string>1.3.
|
|
11
|
-
<key>CFBundleVersion</key><string>1.3.
|
|
10
|
+
<key>CFBundleShortVersionString</key><string>1.3.88</string>
|
|
11
|
+
<key>CFBundleVersion</key><string>1.3.88</string>
|
|
12
12
|
<key>LSUIElement</key><true/>
|
|
13
13
|
<key>NSHighResolutionCapable</key><true/>
|
|
14
14
|
<key>NSPrincipalClass</key><string>NSApplication</string>
|
|
Binary file
|
package/docs/KNOWN-PITFALLS.md
CHANGED
|
@@ -8,6 +8,21 @@
|
|
|
8
8
|
- **不要用 localStorage / 全局状态判断摸鱼模式**(曾经因此让主窗口的「入口工作区」逻辑失效);
|
|
9
9
|
- 摸鱼相关逻辑一律包在 `G.isFloatMode()` 里;古法编程的功能锁见 `docs/MODES.md`。
|
|
10
10
|
|
|
11
|
+
## 0.5 Cmd/Ctrl+点击跳转定义(1.3.78 起)
|
|
12
|
+
|
|
13
|
+
- 编辑器 DOM 上挂 **document 级 mousedown 捕获**(不要挂 Monaco DOM 节点:标签切换/重建后容易挂到废弃节点)。
|
|
14
|
+
- 流程:`getTargetAtClientPoint` → `model.getWordAtPosition` → 先 `editor.action.revealDefinition`(Monaco 自带语言服务),160ms 内检测跳转/peek;没有则调 `code.definition` Host API 兜底。
|
|
15
|
+
- Host `code.definition` 注册在 `host/fs.js` 里,用带 mtime query 的动态 import 加载 `host/code.js`——Host 热重载只按 `MODULE_FILES`(host/*.js)的 mtime 触发,静态 import code.js 会一直吃老缓存。
|
|
16
|
+
- 兜底匹配会解析 import/require 来源(+220 分)、跳过压缩/生成的大文件(单行超长、>512KB)、按目录距离降权;**不要一有多结果就弹列表**:同文件/import/唯一候选直接跳,`function/class/method/type` 之外的弱匹配先要求分数 ≥50 且领先第二名 ≥10,否则静默;只有多个真正同名声明(不同文件、强类型)才弹 picker(最多 8 条)。
|
|
17
|
+
|
|
18
|
+
## 0.6 语言服务(LSP / Python)与 JS/TS 预加载
|
|
19
|
+
|
|
20
|
+
- Python 定义跳转走 **Pyright LSP**:npm 依赖 `pyright`,Host 用 `spawn(process.execPath, [node_modules/pyright/langserver.index.js, '--stdio'])` 以 JSON-RPC over stdio 管理 initialize/didOpen/didChange/textDocument/definition;client 通过 `lsp.definition` API 调用,不在 renderer 里实现 LSP。
|
|
21
|
+
- pyright 是 optional 安装时自动补的:宿主先找 `node_modules/pyright`,缺失时 `npm install pyright` 兜底一次;Python 第一次点击会有 2~5s 语言服务初始化延迟。
|
|
22
|
+
- JS/TS 用 Monaco 内置 TS worker;它只认识**已加载进 Monaco 的 model**,所以 Cmd+点击前要把当前文件的相对 import 依赖按需 `fs.read` + `createModel` 预加载,跨文件定义/变量才能解析。系统库(lib.d.ts)由 TS worker 自带的 lib 处理。
|
|
23
|
+
- LSP 细节:server→client 请求(workspace/configuration、registerCapability、workDoneProgress)必须回 null,否则 Pyright 初始化会挂住;`textDocument/definition` 返回 LocationLink 也要归一化(targetUri/targetRange)。
|
|
24
|
+
- fs.js 热重载只重载 fs.js 本身,`lsp.js` 是静态 import 缓存的;session 在模块级 Map 里,改 lsp.js 需要重启 Host 才生效(不影响功能)。
|
|
25
|
+
|
|
11
26
|
## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
|
|
12
27
|
|
|
13
28
|
**现象**:弹窗被右侧「古法 AI」聊天栏压住、只显示一半、关闭按钮点不到;或者反过来把官方设置/会话弹窗盖住。
|
package/host/fs.js
CHANGED
|
@@ -12,6 +12,7 @@ import { constants } from 'node:fs'
|
|
|
12
12
|
import { tmpdir } from 'node:os'
|
|
13
13
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
14
14
|
import { ApiError, badRequest } from './context.js'
|
|
15
|
+
import { registerLsp } from './lsp.js'
|
|
15
16
|
|
|
16
17
|
const TEXT_LIMIT = 4 * 1024 * 1024
|
|
17
18
|
const runCommand = promisify(execFile)
|
|
@@ -244,6 +245,9 @@ async function listProjectCandidates(root, project, maxScanned) {
|
|
|
244
245
|
}
|
|
245
246
|
|
|
246
247
|
export function register(router, env) {
|
|
248
|
+
/* Python 语言服务(LSP/pyright):/lsp/definition API;Cmd+点击与悬停由客户端调用 */
|
|
249
|
+
registerLsp(router, env)
|
|
250
|
+
|
|
247
251
|
/* 代码导航(Cmd+点击跳定义):实现放在 code.js,但 Host 热重载只按 host/*.js 的 mtime
|
|
248
252
|
触发,因此这里用带 mtime 的 query 动态 import,code.js 改动后下一次请求就能热生效。 */
|
|
249
253
|
router.method('code.definition', async (body) => {
|