dsh-gufa-code 1.3.133 → 1.3.173
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 +2 -2
- package/client.js +287 -31
- 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 +26 -0
- package/host/code.js +41 -0
- package/host/fs.js +11 -0
- package/host/lint.js +152 -2
- package/package.json +2 -1
- package/scripts/selftest-host.mjs +17 -2
- package/scripts/test-editor.mjs +3 -3
- package/src/client/00-core.js +11 -0
- package/src/client/20-editor.js +78 -23
- package/src/client/55-backdrop.js +51 -0
- package/src/client/60-dock.js +144 -6
- package/src/client/90-app.js +2 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
一个 DSH 插件。点工作区行「…」菜单里的 **古法编程** 后,主面板切换成一个三栏 IDE:
|
|
13
13
|
|
|
14
14
|
- **左**:活动栏 + 资源管理器 / 全局搜索 / 源代码管理 / SSH / 终端;
|
|
15
|
-
- **中**:Monaco 编辑器(标签页、面包屑、状态栏、两文件对比、Git diff、⌘+点击/F12 跳转定义;系统内置 API 如 `parseInt` 会打开 TypeScript lib
|
|
15
|
+
- **中**:Monaco 编辑器(标签页、面包屑、状态栏、两文件对比、Git diff、⌘+点击/F12 跳转定义;系统内置 API 如 `parseInt` 会打开 TypeScript lib 的只读标签;会话里的文件引用 chip 点击直接跳到古法编辑器对应行);
|
|
16
16
|
- **右**:**官方 DSH 会话面板原样停靠** —— 工具调用、自动读写文件、审批弹窗、斜杠命令、上下文引用、会话历史都还在。
|
|
17
17
|
|
|
18
18
|
从哪个工作区点进来,IDE 就打开哪个工作区,右侧也自动是你在这个工作区正在聊的那个会话。
|
|
@@ -41,7 +41,7 @@ dsh plugin add dsh-gufa-code
|
|
|
41
41
|
- Monaco 编辑器(离线随包分发,无需联网下载);Monaco 自带 81 种语言全部映射(ABAP、Apex、Clojure、Elixir、F#、GraphQL、HCL/Terraform、Julia、Objective-C、Pascal、Perl、Protobuf、R、RST、Scheme、Solidity、SystemVerilog/Verilog、Tcl、TypeSpec、VB、WGSL、Bicep、Batch、CoffeeScript、Cypher、DAX、Logstash/ECL、MIPS、Power Query、Q#、Redis、SPARQL、Structured Text、Modula-3、ATS、Pony 系列等);
|
|
42
42
|
- **HTML 模板语法高亮**:EJS / Eta、ERB、Nunjucks / Jinja2(`.njk/.nunjucks/.jinja/.jinja2/.j2`)、Blade(`.blade.php`)、Haml、Slim,以及 Monaco 内置的 Handlebars / Mustache / Pug / Twig / Liquid / Razor / FreeMarker;扩展名自动识别;
|
|
43
43
|
- 多标签、按扩展名语法高亮、面包屑、状态栏(分支 / 行列 / 保存状态);
|
|
44
|
-
- **JS/TS 实时诊断**:
|
|
44
|
+
- **JS/TS 实时诊断**:JS 用项目自己的 **ESLint**(自动读取 `.eslintrc.*` / `eslint.config.js` / package.json 的 eslintConfig,`globals` 里声明的全局变量不会误报;没有配置时用内置默认规则 `no-undef`);TS 用 Host TypeScript 编译器兜底;Monaco 的自动缩进/括号引号自动闭合保持开启;
|
|
45
45
|
- **AI Tab 行内补全已移除**(结果质量不稳定且增加输入延迟);基础代码联想(Monaco 建议列表 / 当前文档单词)保持开启;
|
|
46
46
|
- **AI/外部修改自动刷新**:已打开的标签每 1.6s 检查一次磁盘 mtime/size,AI 在会话里改完代码后编辑器自动换成新内容(保留光标位置),不需要关闭重开;点击文件树里的已打开文件也会重新对齐磁盘;有未保存修改时不会覆盖用户内容;
|
|
47
47
|
- 保存走磁盘版本冲突检测 + 原子写;未保存标记;
|
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.173'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -1161,6 +1161,7 @@ G.errorText = (error) => {
|
|
|
1161
1161
|
G.CSS = `
|
|
1162
1162
|
.gufa-overlay-root{position:fixed;inset:0;z-index:1;display:flex;box-sizing:border-box;background:var(--gufa-solid-bg, var(--dsw-alias-bg-base));pointer-events:auto;overflow:hidden}
|
|
1163
1163
|
.gufa-backdrop{position:absolute;inset:0;z-index:0;overflow:hidden;pointer-events:none}
|
|
1164
|
+
|
|
1164
1165
|
/* 桌面悬浮层(摸鱼)模式:整窗半透明,透明度由 --gufa-float-alpha 控制(标题栏滑块) */
|
|
1165
1166
|
html[data-gufa-float]{--gufa-float-alpha:0.55}
|
|
1166
1167
|
html[data-gufa-float] body{background:transparent!important;color-scheme:dark;
|
|
@@ -1301,7 +1302,17 @@ html[data-gufa-float] #root [data-gufa-dock],
|
|
|
1301
1302
|
html[data-gufa-float] #root .gufa-overlay-root *,
|
|
1302
1303
|
html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
|
|
1303
1304
|
/* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
|
|
1305
|
+
/* 古法覆盖层打开时,DSH 右侧栏被覆盖却仍参与 layout/paint;
|
|
1306
|
+
myrta 这类会话会给右侧栏渲染 7000+ 节点,导致编辑器滚动每帧 style/layout 50ms。 */
|
|
1307
|
+
html[data-gufa-ide] [class*="rightbarCol"],
|
|
1308
|
+
html[data-gufa-float] [class*="rightbarCol"]{display:none!important}
|
|
1309
|
+
|
|
1304
1310
|
html[data-gufa-ide] .dsh-pet-root{z-index:2147483050!important}
|
|
1311
|
+
/* 聊天栏收起时,把覆盖层下面的官方会话(可能几千个 DOM 节点)真正隐藏,
|
|
1312
|
+
避免编辑器滚动时整页 layout/paint 把它一起算进去。 */
|
|
1313
|
+
/* 古法/摸鱼模式下皮肤自身的粒子 canvas 不参与绘制(防止 WebGL/rAF 在覆盖层下面持续跑) */
|
|
1314
|
+
html[data-gufa-ide] .liang-ambient,
|
|
1315
|
+
html[data-gufa-float] .liang-ambient{display:none!important}
|
|
1305
1316
|
/* 外部弹窗(DSH 设置等)打开时:停靠会话、古法 portal、桌宠全部降到官方弹窗之下 */
|
|
1306
1317
|
html[data-gufa-external-modal] [data-gufa-dock]{z-index:2!important}
|
|
1307
1318
|
html[data-gufa-external-modal] #gufa-portal-root{z-index:1!important}
|
|
@@ -2758,6 +2769,9 @@ G.registerTemplateLanguages = function registerTemplateLanguages(monaco) {
|
|
|
2758
2769
|
'editorLink.activeForeground': gufaHex(accent),
|
|
2759
2770
|
'editorInfo.foreground': gufaHex(accent),
|
|
2760
2771
|
'editorOverviewRuler.border': '#00000000',
|
|
2772
|
+
'editorOverviewRuler.findMatchForeground': dark ? '#d7ba7d' : '#b58900',
|
|
2773
|
+
'editorOverviewRuler.errorForeground': '#f14c4c',
|
|
2774
|
+
'editorOverviewRuler.warningForeground': '#cca700',
|
|
2761
2775
|
'scrollbarSlider.background': gufaHexAlpha(fg, 0.16),
|
|
2762
2776
|
'scrollbarSlider.hoverBackground': gufaHexAlpha(fg, 0.26),
|
|
2763
2777
|
'scrollbarSlider.activeBackground': gufaHexAlpha(fg, 0.34),
|
|
@@ -3169,7 +3183,7 @@ function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
|
3169
3183
|
}
|
|
3170
3184
|
|
|
3171
3185
|
/* 诊断波浪线已关闭(用户要求);Host lint 也不再在每次输入后跑 tsc,省 CPU */
|
|
3172
|
-
const GUFA_LINT_ENABLED =
|
|
3186
|
+
const GUFA_LINT_ENABLED = true
|
|
3173
3187
|
|
|
3174
3188
|
/* ── model / URI ────────────────────────────────────────────────────── */
|
|
3175
3189
|
|
|
@@ -3222,19 +3236,82 @@ const GUFA_LINT_ENABLED = false
|
|
|
3222
3236
|
return model
|
|
3223
3237
|
}
|
|
3224
3238
|
|
|
3239
|
+
/**
|
|
3240
|
+
* 查找框可见时才打开 overview ruler(查找匹配标记),关闭时收起。
|
|
3241
|
+
* 常开 ruler 会在每次滚动时额外渲染诊断/查找标记,体感卡。
|
|
3242
|
+
*/
|
|
3243
|
+
function gufaInstallFindRuler(instance) {
|
|
3244
|
+
try {
|
|
3245
|
+
const dom = typeof instance.getDomNode === 'function' ? instance.getDomNode() : null
|
|
3246
|
+
if (dom === null || dom === undefined) return null
|
|
3247
|
+
let frame = 0
|
|
3248
|
+
const apply = () => {
|
|
3249
|
+
frame = 0
|
|
3250
|
+
let visible = false
|
|
3251
|
+
try {
|
|
3252
|
+
const widget = dom.querySelector('.find-widget')
|
|
3253
|
+
visible = widget !== null && widget !== undefined && widget.classList.contains('visible')
|
|
3254
|
+
} catch {
|
|
3255
|
+
visible = false
|
|
3256
|
+
}
|
|
3257
|
+
try {
|
|
3258
|
+
instance.updateOptions({ renderOverviewRuler: visible, overviewRulerLanes: visible ? 1 : 0 })
|
|
3259
|
+
} catch {
|
|
3260
|
+
/* ignore */
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
const schedule = () => {
|
|
3264
|
+
if (frame !== 0) return
|
|
3265
|
+
frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(apply) : window.setTimeout(apply, 16)
|
|
3266
|
+
}
|
|
3267
|
+
const observer = typeof MutationObserver === 'function' ? new MutationObserver((records) => {
|
|
3268
|
+
for (const record of records) {
|
|
3269
|
+
if (record.type === 'attributes' && record.target instanceof Element && record.target.classList.contains('find-widget')) {
|
|
3270
|
+
schedule()
|
|
3271
|
+
return
|
|
3272
|
+
}
|
|
3273
|
+
if (record.type === 'childList') {
|
|
3274
|
+
for (const node of record.addedNodes) {
|
|
3275
|
+
if (node instanceof Element && (node.classList.contains('find-widget') || node.querySelector('.find-widget') !== null)) {
|
|
3276
|
+
schedule()
|
|
3277
|
+
return
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
}) : null
|
|
3283
|
+
observer?.observe(dom, { subtree: true, attributes: true, attributeFilter: ['class'], childList: true })
|
|
3284
|
+
return () => {
|
|
3285
|
+
try { observer?.disconnect() } catch { /* ignore */ }
|
|
3286
|
+
if (frame !== 0) {
|
|
3287
|
+
try {
|
|
3288
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
3289
|
+
else window.clearTimeout(frame)
|
|
3290
|
+
} catch { /* ignore */ }
|
|
3291
|
+
frame = 0
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
} catch {
|
|
3295
|
+
return null
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3225
3299
|
/** Monaco 编辑器选项:关闭 minimap / overview ruler,automaticLayout 跟随容器尺寸。 */
|
|
3226
3300
|
function gufaEditorOptions(theme) {
|
|
3227
3301
|
return {
|
|
3228
3302
|
theme: gufaMonacoTheme(theme),
|
|
3229
3303
|
automaticLayout: true,
|
|
3230
3304
|
minimap: { enabled: false },
|
|
3231
|
-
|
|
3232
|
-
|
|
3305
|
+
/* 右侧 ruler 常开:查找匹配/诊断标记显示在滚动条旁 */
|
|
3306
|
+
renderOverviewRuler: true,
|
|
3307
|
+
overviewRulerLanes: 1,
|
|
3233
3308
|
overviewRulerBorder: false,
|
|
3234
3309
|
hideCursorInOverviewRuler: true,
|
|
3235
3310
|
scrollBeyondLastLine: false,
|
|
3236
3311
|
smoothScrolling: true,
|
|
3237
3312
|
cursorBlinking: 'smooth',
|
|
3313
|
+
/* 滚动相关的额外渲染关掉:sticky scroll / 常驻 overview ruler 已单独处理 */
|
|
3314
|
+
stickyScroll: { enabled: false },
|
|
3238
3315
|
fontSize: 13,
|
|
3239
3316
|
lineHeight: 20,
|
|
3240
3317
|
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
|
|
@@ -3510,27 +3587,13 @@ const GUFA_LINT_ENABLED = false
|
|
|
3510
3587
|
} catch {
|
|
3511
3588
|
/* ignore */
|
|
3512
3589
|
}
|
|
3513
|
-
/*
|
|
3514
|
-
|
|
3515
|
-
这里显式打开并开 checkJs,否则 .js 里只有语法错误、没有未定义变量等诊断。 */
|
|
3590
|
+
/* 诊断统一由 Host 提供:JS 用项目 ESLint(尊重 .eslintrc/globals/rules),
|
|
3591
|
+
TS 回落 Host tsc;关掉 Monaco worker 诊断,避免同一个错误画两条线/问题计数翻倍。 */
|
|
3516
3592
|
try {
|
|
3517
3593
|
const typescriptLanguages = monaco.languages.typescript
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
typescriptLanguages.javascriptDefaults?.setDiagnosticsOptions(diagnosticsOn)
|
|
3522
|
-
typescriptLanguages.javascriptDefaults?.setCompilerOptions({
|
|
3523
|
-
allowNonTsExtensions: true,
|
|
3524
|
-
allowJs: true,
|
|
3525
|
-
checkJs: true,
|
|
3526
|
-
target: 99,
|
|
3527
|
-
moduleResolution: 2,
|
|
3528
|
-
module: 99,
|
|
3529
|
-
jsx: 1,
|
|
3530
|
-
esModuleInterop: true,
|
|
3531
|
-
allowSyntheticDefaultImports: true,
|
|
3532
|
-
})
|
|
3533
|
-
}
|
|
3594
|
+
const diagnosticsOff = { noSemanticValidation: true, noSyntaxValidation: true }
|
|
3595
|
+
typescriptLanguages?.typescriptDefaults?.setDiagnosticsOptions(diagnosticsOff)
|
|
3596
|
+
typescriptLanguages?.javascriptDefaults?.setDiagnosticsOptions(diagnosticsOff)
|
|
3534
3597
|
} catch (error) {
|
|
3535
3598
|
/* ignore */
|
|
3536
3599
|
}
|
|
@@ -4456,7 +4519,10 @@ const GUFA_LINT_ENABLED = false
|
|
|
4456
4519
|
minimap: { enabled: false },
|
|
4457
4520
|
scrollBeyondLastLine: false,
|
|
4458
4521
|
lineNumbers: 'on',
|
|
4459
|
-
|
|
4522
|
+
/* diff 编辑器也显示右侧 overview ruler:新增/删除改动在滚动条旁有红绿标记 */
|
|
4523
|
+
renderOverviewRuler: true,
|
|
4524
|
+
overviewRulerLanes: 1,
|
|
4525
|
+
overviewRulerBorder: false,
|
|
4460
4526
|
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
|
|
4461
4527
|
fontSize: 12.5,
|
|
4462
4528
|
lineHeight: 1.15,
|
|
@@ -9955,6 +10021,57 @@ G.BackdropParticles = function BackdropParticles(props) {
|
|
|
9955
10021
|
return h('canvas', { ref: canvasRef, className: 'gufa-backdrop-particles', 'aria-hidden': 'true', style: { mixBlendMode: 'screen' } })
|
|
9956
10022
|
}
|
|
9957
10023
|
|
|
10024
|
+
/** 进入古法 IDE 时临时关掉皮肤自身的粒子/动效(它们会在覆盖层下面持续跑 WebGL/rAF);
|
|
10025
|
+
* 退出时恢复用户原设置,不改变用户偏好。 */
|
|
10026
|
+
let gufaSkinEffectsSaved = null
|
|
10027
|
+
G.suspendSkinEffects = function suspendSkinEffects() {
|
|
10028
|
+
try {
|
|
10029
|
+
if (gufaSkinEffectsSaved !== null) return
|
|
10030
|
+
const raw = localStorage.getItem(SKIN_SETTINGS_KEY)
|
|
10031
|
+
if (raw === null || raw === '') return
|
|
10032
|
+
const record = JSON.parse(raw)
|
|
10033
|
+
if (record === null || typeof record !== 'object' || record.values === null || typeof record.values !== 'object') return
|
|
10034
|
+
const values = record.values
|
|
10035
|
+
if (values.particlesEnabled !== true && values.motionEnabled !== true) return
|
|
10036
|
+
gufaSkinEffectsSaved = raw
|
|
10037
|
+
const next = { ...record, values: { ...values, particlesEnabled: false, motionEnabled: false } }
|
|
10038
|
+
const payload = JSON.stringify(next)
|
|
10039
|
+
localStorage.setItem(SKIN_SETTINGS_KEY, payload)
|
|
10040
|
+
try {
|
|
10041
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
10042
|
+
key: SKIN_SETTINGS_KEY,
|
|
10043
|
+
oldValue: raw,
|
|
10044
|
+
newValue: payload,
|
|
10045
|
+
storageArea: localStorage,
|
|
10046
|
+
}))
|
|
10047
|
+
} catch {
|
|
10048
|
+
/* ignore */
|
|
10049
|
+
}
|
|
10050
|
+
} catch {
|
|
10051
|
+
gufaSkinEffectsSaved = null
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
G.resumeSkinEffects = function resumeSkinEffects() {
|
|
10055
|
+
try {
|
|
10056
|
+
if (gufaSkinEffectsSaved === null) return
|
|
10057
|
+
const raw = gufaSkinEffectsSaved
|
|
10058
|
+
gufaSkinEffectsSaved = null
|
|
10059
|
+
localStorage.setItem(SKIN_SETTINGS_KEY, raw)
|
|
10060
|
+
try {
|
|
10061
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
10062
|
+
key: SKIN_SETTINGS_KEY,
|
|
10063
|
+
oldValue: null,
|
|
10064
|
+
newValue: raw,
|
|
10065
|
+
storageArea: localStorage,
|
|
10066
|
+
}))
|
|
10067
|
+
} catch {
|
|
10068
|
+
/* ignore */
|
|
10069
|
+
}
|
|
10070
|
+
} catch {
|
|
10071
|
+
/* ignore */
|
|
10072
|
+
}
|
|
10073
|
+
}
|
|
10074
|
+
|
|
9958
10075
|
/** 背景浓度滑杆(无级、连续;双击恢复「跟随皮肤」)。 */
|
|
9959
10076
|
G.BackdropStrengthSlider = function BackdropStrengthSlider(props) {
|
|
9960
10077
|
const t = G.useT()
|
|
@@ -10804,6 +10921,8 @@ function gufaRestoreDockTarget(node, saved) {
|
|
|
10804
10921
|
}
|
|
10805
10922
|
}
|
|
10806
10923
|
|
|
10924
|
+
G.findConversationRoot = gufaFindConversationRoot
|
|
10925
|
+
|
|
10807
10926
|
/**
|
|
10808
10927
|
* 把会话根浮到停靠区的位置与尺寸;返回是否成功。
|
|
10809
10928
|
*
|
|
@@ -10815,6 +10934,7 @@ function gufaRestoreDockTarget(node, saved) {
|
|
|
10815
10934
|
* 用「测实际位置 → 补偿差值」迭代 2 次把会话对齐到停靠区。
|
|
10816
10935
|
*/
|
|
10817
10936
|
function gufaPlaceDockedConversation(root, host, options) {
|
|
10937
|
+
try { root.removeAttribute('data-gufa-hide') } catch { /* ignore */ }
|
|
10818
10938
|
const rect = host.getBoundingClientRect()
|
|
10819
10939
|
if (!(rect.width >= 80 && rect.height >= 80)) return false
|
|
10820
10940
|
const target = { left: Math.round(rect.left), top: Math.round(rect.top), width: Math.round(rect.width), height: Math.round(rect.height) }
|
|
@@ -10840,10 +10960,20 @@ function gufaPlaceDockedConversation(root, host, options) {
|
|
|
10840
10960
|
let floatMode = false
|
|
10841
10961
|
try { floatMode = document.documentElement.hasAttribute('data-gufa-float') } catch { floatMode = false }
|
|
10842
10962
|
if (floatMode) root.style.background = dockBackground === '' ? 'rgba(13, 15, 19, 0.55)' : `color-mix(in srgb, ${dockBackground} 45%, transparent)`
|
|
10843
|
-
else if (backdropMode
|
|
10963
|
+
else if (backdropMode) {
|
|
10964
|
+
/* 背景模式下必须半透明:解析不到实色时也用 color-mix + 变量兜底,
|
|
10965
|
+
不能掉进不透明实色分支(之前右侧对话背景变实色就是这个原因)。 */
|
|
10966
|
+
root.style.background = dockBackground === ''
|
|
10967
|
+
? 'color-mix(in srgb, var(--gufa-solid-bg, #1a1b1f) 34%, transparent)'
|
|
10968
|
+
: `color-mix(in srgb, ${dockBackground} 34%, transparent)`
|
|
10969
|
+
}
|
|
10844
10970
|
else root.style.background = dockBackground === '' ? 'var(--gufa-solid-bg, #1a1b1f)' : dockBackground
|
|
10845
10971
|
root.style.borderLeft = '1px solid var(--dsw-alias-border-l1)'
|
|
10846
10972
|
root.style.boxSizing = 'border-box'
|
|
10973
|
+
/* 注意:不要给会话根加 will-change/contain——实测会增加每次滚动时的样式/布局成本 */
|
|
10974
|
+
try {
|
|
10975
|
+
root.style.contain = 'layout paint'
|
|
10976
|
+
} catch { /* ignore */ }
|
|
10847
10977
|
root.style.setProperty('--dsh-chat-user-width', 'calc(100% - 24px)')
|
|
10848
10978
|
root.style.setProperty('--dsh-conversation-column-width', `${target.width}px`)
|
|
10849
10979
|
root.setAttribute('data-gufa-dock', '1')
|
|
@@ -11168,6 +11298,68 @@ G.__dock = {
|
|
|
11168
11298
|
restore: gufaRestoreDockTarget,
|
|
11169
11299
|
}
|
|
11170
11300
|
|
|
11301
|
+
/** 从 DSH 会话里的文件引用按钮提取路径/行号,然后在古法编辑器里打开。 */
|
|
11302
|
+
function gufaParseMentionButton(button) {
|
|
11303
|
+
if (button === null || button === undefined || typeof button.closest !== 'function') return null
|
|
11304
|
+
const className = typeof button.className === 'string' ? button.className : ''
|
|
11305
|
+
const dataRef = typeof button.getAttribute === 'function' ? (button.getAttribute('data-ref-chip') ?? '') : ''
|
|
11306
|
+
const isMention = className.includes('fileMention') || className.includes('fileLink') || dataRef !== ''
|
|
11307
|
+
if (!isMention) return null
|
|
11308
|
+
const title = typeof button.getAttribute === 'function' ? (button.getAttribute('title') ?? '').trim() : ''
|
|
11309
|
+
const text = String(button.textContent ?? '').replace(/\s+/g, ' ').trim()
|
|
11310
|
+
const parseRef = (value) => {
|
|
11311
|
+
const source = String(value ?? '').trim()
|
|
11312
|
+
if (source === '') return null
|
|
11313
|
+
const match = /^(.*?)(?::(\d+)(?:\s*[-,]\s*\d+)*|#L(\d+)(?:-L?\d+)?)$/.exec(source)
|
|
11314
|
+
if (match === null) return { path: source, line: 0 }
|
|
11315
|
+
return { path: match[1].trim(), line: Number(match[2] ?? match[3]) || 0 }
|
|
11316
|
+
}
|
|
11317
|
+
const titleLooksPath = /[\\/]/.test(title) || /\.[A-Za-z0-9]{1,8}$/.test(title)
|
|
11318
|
+
const fromTitle = titleLooksPath ? parseRef(title) : null
|
|
11319
|
+
const fromText = parseRef(text)
|
|
11320
|
+
/* 关键:title 通常只有完整路径(无行号),行号在按钮文本 `xxx.js:165` 里;
|
|
11321
|
+
两者要合并,不能 title 命中就忽略文本的行号。 */
|
|
11322
|
+
let path = fromTitle !== null && fromTitle.path !== '' ? fromTitle.path : (fromText !== null ? fromText.path : '')
|
|
11323
|
+
let line = (fromTitle !== null ? fromTitle.line : 0) || (fromText !== null ? fromText.line : 0)
|
|
11324
|
+
if (path === '') return null
|
|
11325
|
+
if (dataRef !== '') {
|
|
11326
|
+
let dataPath = ''
|
|
11327
|
+
let dataLine = 0
|
|
11328
|
+
if (dataRef.trim().startsWith('{')) {
|
|
11329
|
+
try {
|
|
11330
|
+
const parsedData = JSON.parse(dataRef)
|
|
11331
|
+
dataPath = typeof parsedData?.path === 'string' ? parsedData.path : ''
|
|
11332
|
+
dataLine = Number(parsedData?.line) || 0
|
|
11333
|
+
} catch {
|
|
11334
|
+
/* ignore */
|
|
11335
|
+
}
|
|
11336
|
+
}
|
|
11337
|
+
if (dataPath !== '') {
|
|
11338
|
+
path = dataPath
|
|
11339
|
+
if (dataLine > 0) line = dataLine
|
|
11340
|
+
}
|
|
11341
|
+
}
|
|
11342
|
+
return { path: path.replace(/^\.\//, ''), line }
|
|
11343
|
+
}
|
|
11344
|
+
|
|
11345
|
+
async function gufaOpenMention(mention) {
|
|
11346
|
+
if (mention === null || mention === undefined || typeof mention.path !== 'string' || mention.path === '') return
|
|
11347
|
+
const root = typeof G.projectRoot === 'string' ? G.projectRoot.replace(/\\/g, '/').replace(/\/+$/, '') : ''
|
|
11348
|
+
if (root === '') return
|
|
11349
|
+
let resolved = null
|
|
11350
|
+
try {
|
|
11351
|
+
resolved = await G.api('code.resolvePath', { root, path: mention.path })
|
|
11352
|
+
} catch {
|
|
11353
|
+
return
|
|
11354
|
+
}
|
|
11355
|
+
if (resolved === null || resolved === undefined || typeof resolved.path !== 'string' || resolved.path === '') return
|
|
11356
|
+
try {
|
|
11357
|
+
G.bus.emit('editor:open-at', { path: resolved.path, line: Math.max(1, Number(mention.line) || 1), column: 1 })
|
|
11358
|
+
} catch {
|
|
11359
|
+
/* ignore */
|
|
11360
|
+
}
|
|
11361
|
+
}
|
|
11362
|
+
|
|
11171
11363
|
/**
|
|
11172
11364
|
* 停靠栏:官方会话本体(浮动) + 顶部工具条(新建会话 / 打开完整对话 / 收起)。
|
|
11173
11365
|
* props = { project, activeFile, selection, theme, width, onInsertCode, backdrop, active, sessionTitle, sessions, onOpenSession }
|
|
@@ -11181,11 +11373,56 @@ G.ChatDock = function ChatDock(props) {
|
|
|
11181
11373
|
if (followRef.current === null) followRef.current = gufaCreateChatFollowKeeper()
|
|
11182
11374
|
const tickRef = useRef(null)
|
|
11183
11375
|
const startedRef = useRef(0)
|
|
11376
|
+
const mentionRootRef = useRef(null)
|
|
11377
|
+
const mentionHandlerRef = useRef(null)
|
|
11378
|
+
const detachMentionRef = useRef(null)
|
|
11184
11379
|
const [phase, setPhase] = useState('searching')
|
|
11185
11380
|
const [error, setError] = useState('')
|
|
11186
11381
|
const active = props.active !== false && props.paused !== true
|
|
11187
11382
|
|
|
11383
|
+
const detachMention = useCallback(() => {
|
|
11384
|
+
const root = mentionRootRef.current
|
|
11385
|
+
const handler = mentionHandlerRef.current
|
|
11386
|
+
if (root !== null && handler !== null) {
|
|
11387
|
+
try { root.removeEventListener('click', handler, true) } catch { /* ignore */ }
|
|
11388
|
+
}
|
|
11389
|
+
mentionRootRef.current = null
|
|
11390
|
+
mentionHandlerRef.current = null
|
|
11391
|
+
}, [])
|
|
11392
|
+
detachMentionRef.current = detachMention
|
|
11393
|
+
|
|
11394
|
+
const ensureMentionHandler = useCallback((root) => {
|
|
11395
|
+
if (root === null) {
|
|
11396
|
+
detachMention()
|
|
11397
|
+
return
|
|
11398
|
+
}
|
|
11399
|
+
if (mentionRootRef.current === root && mentionHandlerRef.current !== null) return
|
|
11400
|
+
detachMention()
|
|
11401
|
+
const handler = (event) => {
|
|
11402
|
+
try {
|
|
11403
|
+
if (event.button !== 0 || event.defaultPrevented === true) return
|
|
11404
|
+
const target = event.target instanceof Element ? event.target.closest('button, [data-ref-chip]') : null
|
|
11405
|
+
if (target === null) return
|
|
11406
|
+
const mention = gufaParseMentionButton(target)
|
|
11407
|
+
if (mention === null) return
|
|
11408
|
+
event.preventDefault()
|
|
11409
|
+
event.stopPropagation()
|
|
11410
|
+
void gufaOpenMention(mention)
|
|
11411
|
+
} catch {
|
|
11412
|
+
/* ignore */
|
|
11413
|
+
}
|
|
11414
|
+
}
|
|
11415
|
+
try {
|
|
11416
|
+
root.addEventListener('click', handler, true)
|
|
11417
|
+
mentionRootRef.current = root
|
|
11418
|
+
mentionHandlerRef.current = handler
|
|
11419
|
+
} catch {
|
|
11420
|
+
/* ignore */
|
|
11421
|
+
}
|
|
11422
|
+
}, [detachMention])
|
|
11423
|
+
|
|
11188
11424
|
const undock = useCallback(() => {
|
|
11425
|
+
detachMentionRef.current?.()
|
|
11189
11426
|
const current = dockRef.current
|
|
11190
11427
|
if (current.root !== null) gufaRestoreDockTarget(current.root, current.saved)
|
|
11191
11428
|
dockRef.current = { root: null, saved: null }
|
|
@@ -11211,6 +11448,7 @@ G.ChatDock = function ChatDock(props) {
|
|
|
11211
11448
|
dockRef.current = { root, saved: gufaSnapshotDockTarget(root) }
|
|
11212
11449
|
}
|
|
11213
11450
|
if (gufaPlaceDockedConversation(root, host, { translucent: props.backdrop === true })) {
|
|
11451
|
+
ensureMentionHandler(root)
|
|
11214
11452
|
try {
|
|
11215
11453
|
const scroller = root.querySelector(GUFA_CONVERSATION_SCROLL_SELECTOR)
|
|
11216
11454
|
if (scroller !== null && scroller !== undefined) followRef.current?.attach(scroller)
|
|
@@ -11219,7 +11457,7 @@ G.ChatDock = function ChatDock(props) {
|
|
|
11219
11457
|
}
|
|
11220
11458
|
setPhase((previous) => (previous === 'docked' ? previous : 'docked'))
|
|
11221
11459
|
}
|
|
11222
|
-
}, [active, undock, props.backdrop])
|
|
11460
|
+
}, [active, undock, props.backdrop, ensureMentionHandler])
|
|
11223
11461
|
|
|
11224
11462
|
/* 拖拽分割条时的轻量重定位:只改宿主几何,不 getComputedStyle、不读自身 rect、不 setState。
|
|
11225
11463
|
完整 tick 每次都会 getComputedStyle + 最多两次 getBoundingClientRect,按帧跑会把拖拽拖卡。 */
|
|
@@ -11259,13 +11497,30 @@ G.ChatDock = function ChatDock(props) {
|
|
|
11259
11497
|
startedRef.current = Date.now()
|
|
11260
11498
|
setPhase((previous) => (previous === 'docked' ? previous : 'searching'))
|
|
11261
11499
|
let disposed = false
|
|
11500
|
+
/* dock 住之后彻底断开 body MutationObserver:Monaco 滚动会不断增删行 DOM,
|
|
11501
|
+
observer 即使不跑 tick,浏览器也要为整棵 body 维护/遍历 mutation record,依然拖慢滚动。
|
|
11502
|
+
发现/替换会话根交给 300ms 轮询(未 dock 时才观察)。 */
|
|
11503
|
+
let observer = typeof MutationObserver === 'function' ? new MutationObserver(() => { run() }) : null
|
|
11504
|
+
let observing = false
|
|
11505
|
+
const setObserving = (next) => {
|
|
11506
|
+
if (observer === null || observing === next) return
|
|
11507
|
+
observing = next
|
|
11508
|
+
try {
|
|
11509
|
+
if (next) observer.observe(document.body, { childList: true, subtree: true })
|
|
11510
|
+
else observer.disconnect()
|
|
11511
|
+
} catch {
|
|
11512
|
+
/* ignore */
|
|
11513
|
+
}
|
|
11514
|
+
}
|
|
11262
11515
|
const run = () => {
|
|
11263
|
-
if (
|
|
11516
|
+
if (disposed) return
|
|
11517
|
+
tickRef.current?.()
|
|
11518
|
+
const current = dockRef.current.root
|
|
11519
|
+
setObserving(!(current !== null && current.isConnected === true))
|
|
11264
11520
|
}
|
|
11521
|
+
setObserving(true)
|
|
11265
11522
|
run()
|
|
11266
|
-
const timer = window.setInterval(run,
|
|
11267
|
-
const observer = typeof MutationObserver === 'function' ? new MutationObserver(run) : null
|
|
11268
|
-
if (observer !== null) observer.observe(document.body, { childList: true, subtree: true })
|
|
11523
|
+
const timer = window.setInterval(run, 300)
|
|
11269
11524
|
let resizeObserver = null
|
|
11270
11525
|
if (typeof ResizeObserver === 'function') {
|
|
11271
11526
|
resizeObserver = new ResizeObserver(run)
|
|
@@ -12401,7 +12656,8 @@ G.useSplitter = function useSplitter(options) {
|
|
|
12401
12656
|
return [size, onMouseDown, setSize]
|
|
12402
12657
|
}
|
|
12403
12658
|
|
|
12404
|
-
|
|
12659
|
+
|
|
12660
|
+
|
|
12405
12661
|
G.GufaApp = function GufaApp(props) {
|
|
12406
12662
|
const t = G.useT()
|
|
12407
12663
|
const theme = G.useTheme()
|
|
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.173</string>
|
|
11
|
+
<key>CFBundleVersion</key><string>1.3.173</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
|
@@ -140,6 +140,32 @@
|
|
|
140
140
|
3. 同一个 `registerEditorOpener` 打开项目文件或只读 `~typescript/lib*.d.ts`。
|
|
141
141
|
- 也就是说 Cmd+点击现在和 F12 **完全同一条代码路径**,不再有自己的解析/兜底。唯一的自定义只是「把鼠标事件翻译成这个 action」这一层。
|
|
142
142
|
|
|
143
|
+
## 0.21 诊断改用 ESLint(1.3.138)
|
|
144
|
+
|
|
145
|
+
- 之前 Host tsc 单文件 Program 不认识项目里自定义的全局变量,把业务里的 global 变量全报成未定义;Monaco 原生 worker 在桌面壳又不稳定。
|
|
146
|
+
- 现在 JS/JSX/MJS/CJS 用 ESLint:
|
|
147
|
+
- 优先用项目自己的 ESLint(存在 `eslint.config.js` 时从项目 node_modules 加载);
|
|
148
|
+
- 否则用插件内置 ESLint 8 + `useEslintrc`,自动读取 `.eslintrc.*` / package.json `eslintConfig`;没有配置时用内置 `no-undef` 规则 + node/browser globals;
|
|
149
|
+
- `.eslintrc` 里的 `globals` / `rules` / 插件会生效,自定义全局变量不再误报;
|
|
150
|
+
- TS/TSX 仍走 Host tsc(ESLint 默认 parser 不解析 TS 语法)。
|
|
151
|
+
- Monaco 原生 worker 诊断关闭,避免同一错误双份 marker;Host lint 仍 debounce 650ms 更新。
|
|
152
|
+
- 项目示例 `.eslintrc.json`:
|
|
153
|
+
```json
|
|
154
|
+
{ "env": { "node": true, "browser": true, "es2022": true },
|
|
155
|
+
"globals": { "myGlobal": "readonly" },
|
|
156
|
+
"rules": { "no-undef": "error" } }
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 0.22 会话文件引用跳古法编辑器(1.3.139)
|
|
160
|
+
|
|
161
|
+
- DSH 对话里的文件引用(MarkdownText 的 `fileMention`/`fileLink` 按钮、用户引用 chip)原生 onClick 调用的是 ChatView 的 `openFile`,它打开 `ctx.sidebarRight` 资源面板;在古法 IDE 覆盖层下这个面板被挡住,所以点了“没反应”。
|
|
162
|
+
- 修复:ChatDock 停靠成功后,在**官方会话根节点**上挂 capture click 监听:
|
|
163
|
+
- 命中 `button.fileMention / .fileLink / [data-ref-chip]`;
|
|
164
|
+
- 从 `title`(完整路径)+ 文本(`xxx.js:165` / `#L165`)解析 path/line;
|
|
165
|
+
- 调 Host `code.resolvePath` 把 basename/相对路径解析成项目内路径(优先当前目录、层级更浅);
|
|
166
|
+
- `editor:open-at` 打开古法编辑器并定位,同时 preventDefault/stopPropagation 阻止 DSH 侧边栏打开;
|
|
167
|
+
- `undock()`/根节点变化时移除监听。
|
|
168
|
+
|
|
143
169
|
## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
|
|
144
170
|
|
|
145
171
|
**现象**:弹窗被右侧「古法 AI」聊天栏压住、只显示一半、关闭按钮点不到;或者反过来把官方设置/会话弹窗盖住。
|
package/host/code.js
CHANGED
|
@@ -371,6 +371,47 @@ export async function definition(body, env) {
|
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
+
function insideProject(root, target) {
|
|
375
|
+
const rel = relative(root, target)
|
|
376
|
+
return rel === '' || (!rel.startsWith(`..${sep}`) && rel !== '..' && !isAbsolute(rel))
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* 会话里的文件引用(`tasks.js:165`、`engine/x/service.js`)解析成项目内相对路径。
|
|
381
|
+
* 支持完整相对路径、以 / 结尾的部分路径、纯 basename;多个同名时优先当前文件同目录、层级更浅的。
|
|
382
|
+
*/
|
|
383
|
+
export async function resolvePath(body, env) {
|
|
384
|
+
const project = env.projects.ensure(typeof body.root === 'string' ? body.root : '')
|
|
385
|
+
const root = project.root
|
|
386
|
+
let hint = String(body.path ?? '').replace(/\\/g, '/').trim()
|
|
387
|
+
if (hint === '') return { path: null, matches: [] }
|
|
388
|
+
hint = hint.replace(/^file:\/\//, '').replace(/^\.\//, '')
|
|
389
|
+
if (isAbsolute(hint)) {
|
|
390
|
+
const absolute = resolve(hint)
|
|
391
|
+
if (!insideProject(root, absolute)) return { path: null, matches: [] }
|
|
392
|
+
hint = relative(root, absolute).split(sep).join('/')
|
|
393
|
+
}
|
|
394
|
+
hint = hint.replace(/^\/+/, '')
|
|
395
|
+
if (hint === '' || hint.includes('..')) return { path: null, matches: [] }
|
|
396
|
+
const candidates = await listCandidates(root, null)
|
|
397
|
+
const activePath = String(body.activePath ?? '').replace(/\\/g, '/').replace(/^\/+/, '')
|
|
398
|
+
const activeDir = activePath.includes('/') ? activePath.slice(0, activePath.lastIndexOf('/')) : ''
|
|
399
|
+
let pool = candidates.filter((candidate) => candidate === hint)
|
|
400
|
+
if (pool.length === 0) pool = candidates.filter((candidate) => candidate.endsWith(`/${hint}`) || candidate.split('/').pop() === hint)
|
|
401
|
+
pool = [...new Set(pool)]
|
|
402
|
+
pool.sort((a, b) => {
|
|
403
|
+
const aNear = activeDir !== '' && a.startsWith(`${activeDir}/`) ? 0 : 1
|
|
404
|
+
const bNear = activeDir !== '' && b.startsWith(`${activeDir}/`) ? 0 : 1
|
|
405
|
+
if (aNear !== bNear) return aNear - bNear
|
|
406
|
+
const depthDiff = a.split('/').length - b.split('/').length
|
|
407
|
+
if (depthDiff !== 0) return depthDiff
|
|
408
|
+
return a.localeCompare(b)
|
|
409
|
+
})
|
|
410
|
+
if (pool.length === 0) return { path: null, matches: [] }
|
|
411
|
+
return { path: pool[0], matches: pool.slice(0, 10) }
|
|
412
|
+
}
|
|
413
|
+
|
|
374
414
|
export function register(router, env) {
|
|
375
415
|
router.method('code.definition', (body) => definition(body, env))
|
|
416
|
+
router.method('code.resolvePath', (body) => resolvePath(body, env))
|
|
376
417
|
}
|
package/host/fs.js
CHANGED
|
@@ -336,6 +336,17 @@ export function register(router, env) {
|
|
|
336
336
|
|
|
337
337
|
/* 代码导航(Cmd+点击跳定义):实现放在 code.js,但 Host 热重载只按 host/*.js 的 mtime
|
|
338
338
|
触发,因此这里用带 mtime 的 query 动态 import,code.js 改动后下一次请求就能热生效。 */
|
|
339
|
+
router.method('code.resolvePath', async (body) => {
|
|
340
|
+
let stamp = '0'
|
|
341
|
+
try {
|
|
342
|
+
stamp = String(statSync(new URL('./code.js', import.meta.url)).mtimeMs)
|
|
343
|
+
} catch {
|
|
344
|
+
stamp = '0'
|
|
345
|
+
}
|
|
346
|
+
const module = await import(new URL(`./code.js?gufa-code-resolve=${stamp}`, import.meta.url).href)
|
|
347
|
+
return module.resolvePath(body, env)
|
|
348
|
+
})
|
|
349
|
+
|
|
339
350
|
router.method('code.definition', async (body) => {
|
|
340
351
|
let stamp = '0'
|
|
341
352
|
try {
|