dsh-gufa-code 1.3.133 → 1.3.179

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.
@@ -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 {
package/host/lint.js CHANGED
@@ -6,9 +6,12 @@
6
6
  * importScripts 自定义协议资源会失败,导致语法/语义诊断时有时无;Host 侧
7
7
  * 编译结果稳定,且可以随插件依赖(typescript)一起分发。
8
8
  */
9
+ import { existsSync, readFileSync, statSync } from 'node:fs'
9
10
  import { readFile } from 'node:fs/promises'
10
- import { dirname, isAbsolute, relative, resolve, sep } from 'node:path'
11
+ import { createRequire } from 'node:module'
12
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
11
13
 
14
+ import { ESLint } from 'eslint'
12
15
  import ts from 'typescript'
13
16
 
14
17
  import { ApiError, badRequest } from './context.js'
@@ -60,7 +63,7 @@ function severityOf(category) {
60
63
  return 2
61
64
  }
62
65
 
63
- export async function diagnose(body, env) {
66
+ async function diagnoseWithTsc(body, env) {
64
67
  if (typeof body.root !== 'string' || body.root === '') throw badRequest('root is required')
65
68
  const project = env.projects.ensure(body.root)
66
69
  const root = project.root
@@ -196,6 +199,153 @@ export async function diagnose(body, env) {
196
199
  return { diagnostics }
197
200
  }
198
201
 
202
+ const FLAT_CONFIG_FILES = ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
203
+ const LEGACY_CONFIG_FILES = ['.eslintrc', '.eslintrc.js', '.eslintrc.cjs', '.eslintrc.json', '.eslintrc.yml', '.eslintrc.yaml']
204
+ const eslintCache = new Map()
205
+
206
+ function configSignature(root) {
207
+ const parts = []
208
+ for (const name of [...FLAT_CONFIG_FILES, ...LEGACY_CONFIG_FILES, 'package.json']) {
209
+ const file = join(root, name)
210
+ try {
211
+ parts.push(`${name}:${statSync(file).mtimeMs}`)
212
+ } catch {
213
+ /* ignore */
214
+ }
215
+ }
216
+ return parts.join('|')
217
+ }
218
+
219
+ function hasLegacyRegexConfig(root) {
220
+ for (const name of LEGACY_CONFIG_FILES) {
221
+ if (existsSync(join(root, name))) return true
222
+ }
223
+ try {
224
+ const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
225
+ return pkg !== null && typeof pkg === 'object' && pkg.eslintConfig !== undefined
226
+ } catch {
227
+ return false
228
+ }
229
+ }
230
+
231
+ function fallbackEslintConfig() {
232
+ return {
233
+ env: { browser: true, node: true, es2022: true },
234
+ parserOptions: { ecmaVersion: 'latest', sourceType: 'module', ecmaFeatures: { jsx: true } },
235
+ rules: {
236
+ 'no-undef': 'error',
237
+ 'no-unused-vars': 'off',
238
+ },
239
+ }
240
+ }
241
+
242
+ /** 优先用项目自己的 eslint(支持 eslint.config.js / 自定义规则),否则用插件内置 ESLint。 */
243
+ async function getEslint(root) {
244
+ const signature = configSignature(root)
245
+ const cached = eslintCache.get(root)
246
+ if (cached !== undefined && cached.signature === signature) return cached.instance
247
+ let instance = null
248
+ const flatConfig = FLAT_CONFIG_FILES.find((name) => existsSync(join(root, name)))
249
+ if (flatConfig !== undefined) {
250
+ try {
251
+ const projectRequire = createRequire(join(root, 'package.json'))
252
+ const projectModule = projectRequire('eslint')
253
+ const ProjectESLint = projectModule?.ESLint
254
+ if (typeof ProjectESLint === 'function') {
255
+ instance = new ProjectESLint({ cwd: root, errorOnUnmatchedPattern: false })
256
+ }
257
+ } catch {
258
+ instance = null
259
+ }
260
+ }
261
+ if (instance === null) {
262
+ try {
263
+ const legacy = hasLegacyRegexConfig(root) || flatConfig !== undefined
264
+ instance = new ESLint({
265
+ cwd: root,
266
+ useEslintrc: true,
267
+ errorOnUnmatchedPattern: false,
268
+ resolvePluginsRelativeTo: root,
269
+ ...(legacy ? {} : { overrideConfig: fallbackEslintConfig() }),
270
+ })
271
+ } catch {
272
+ instance = null
273
+ }
274
+ }
275
+ eslintCache.set(root, { signature, instance })
276
+ return instance
277
+ }
278
+
279
+ async function eslintDiagnostics(root, absolute, content) {
280
+ const eslint = await getEslint(root)
281
+ if (eslint === null || eslint === undefined) return null
282
+ let results = []
283
+ try {
284
+ results = await eslint.lintText(content, { filePath: absolute, warnIgnored: false })
285
+ } catch {
286
+ return null
287
+ }
288
+ const result = Array.isArray(results) ? results[0] : null
289
+ if (result === null || result === undefined) return []
290
+ const diagnostics = []
291
+ const seen = new Set()
292
+ for (const message of Array.isArray(result.messages) ? result.messages : []) {
293
+ if (message === null || typeof message !== 'object') continue
294
+ if (Number(message.severity) < 1) continue
295
+ const ruleId = typeof message.ruleId === 'string' && message.ruleId !== '' ? message.ruleId : (message.fatal === true ? 'parsing-error' : 'eslint')
296
+ const line = Math.max(1, Math.trunc(Number(message.line) || 1))
297
+ const column = Math.max(1, Math.trunc(Number(message.column) || 1))
298
+ const endLine = Math.max(line, Math.trunc(Number(message.endLine) || line))
299
+ const endColumn = Math.max(column + 1, Math.trunc(Number(message.endColumn) || (column + 1)))
300
+ const text = String(message.message ?? '')
301
+ const key = `${ruleId}:${line}:${column}:${text}`
302
+ if (seen.has(key)) continue
303
+ seen.add(key)
304
+ diagnostics.push({
305
+ severity: Number(message.severity) === 2 ? 1 : 0,
306
+ message: text,
307
+ code: ruleId,
308
+ line,
309
+ column,
310
+ endLine,
311
+ endColumn,
312
+ })
313
+ if (diagnostics.length >= 200) break
314
+ }
315
+ return diagnostics
316
+ }
317
+
318
+ export async function diagnose(body, env) {
319
+ if (typeof body.root !== 'string' || body.root === '') throw badRequest('root is required')
320
+ const project = env.projects.ensure(body.root)
321
+ const root = project.root
322
+ const rawPath = typeof body.path === 'string' ? body.path : ''
323
+ if (rawPath === '') throw badRequest('path is required')
324
+ const absolute = resolve(root, rawPath)
325
+ if (!inside(root, absolute)) throw new ApiError('path-outside', '路径超出项目范围', 403)
326
+ const extension = rawPath.split('.').pop()?.toLowerCase() ?? ''
327
+ if (!['js', 'jsx', 'mjs', 'cjs', 'ts', 'tsx', 'mts', 'cts'].includes(extension)) return { diagnostics: [] }
328
+ let content = typeof body.content === 'string' ? body.content : ''
329
+ if (content === '') {
330
+ try {
331
+ content = await readFile(absolute, 'utf8')
332
+ } catch {
333
+ throw new ApiError('not-found', `文件不存在:${rawPath}`, 404)
334
+ }
335
+ }
336
+ /* JS/JSX 用 ESLint(尊重项目 .eslintrc / eslint.config.js 的 globals、rules、插件);
337
+ TS/TSX 仍用 TypeScript 编译器(ESLint 默认 parser 不解析 TS 语法)。 */
338
+ if (['js', 'jsx', 'mjs', 'cjs'].includes(extension)) {
339
+ try {
340
+ const diagnostics = await eslintDiagnostics(root, absolute, content)
341
+ if (diagnostics !== null) return { diagnostics }
342
+ } catch {
343
+ /* 配置/插件加载失败时回落 tsc,避免完全没诊断 */
344
+ }
345
+ }
346
+ return diagnoseWithTsc(body, env)
347
+ }
348
+
199
349
  export function registerLint(router, env) {
200
350
  router.method('lint.javascript', (body) => diagnose(body, env))
201
351
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.133",
3
+ "version": "1.3.179",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -40,6 +40,7 @@
40
40
  "desktop"
41
41
  ],
42
42
  "dependencies": {
43
+ "eslint": "^8.57.1",
43
44
  "pyright": "^1.1.414",
44
45
  "typescript": "^5.9.3",
45
46
  "ws": "^8.22.0"
@@ -133,6 +133,11 @@ try {
133
133
  const missingMtimes = await call(router, 'fs.mtimes', { root, paths: [] })
134
134
  check('fs.mtimes handles empty list', missingMtimes.files !== null && typeof missingMtimes.files === 'object' && Object.keys(missingMtimes.files).length === 0)
135
135
 
136
+ const resolvedPath = await call(router, 'code.resolvePath', { root, path: 'main.ts' })
137
+ check('code.resolvePath resolves basename', resolvedPath.path === 'src/main.ts', JSON.stringify(resolvedPath))
138
+ const resolvedMissing = await call(router, 'code.resolvePath', { root, path: 'not-exist-file.ts' })
139
+ check('code.resolvePath returns null for missing', resolvedMissing.path === null, JSON.stringify(resolvedMissing))
140
+
136
141
  console.log('lint.javascript')
137
142
  await call(router, 'fs.create', { root, path: 'src/lint-sample.js', kind: 'file' })
138
143
  const lintResult = await call(router, 'lint.javascript', {
@@ -141,14 +146,14 @@ try {
141
146
  language: 'javascript',
142
147
  content: 'const lintValue = undefinedVariable\n',
143
148
  })
144
- check('lint reports undefined variable', lintResult.diagnostics.some((item) => item.code === 2304 && item.line === 1), JSON.stringify(lintResult.diagnostics))
149
+ check('lint reports undefined variable', lintResult.diagnostics.some((item) => item.code === 'no-undef' && item.line === 1 && String(item.message).includes('not defined')), JSON.stringify(lintResult.diagnostics))
145
150
  const lintSyntax = await call(router, 'lint.javascript', {
146
151
  root,
147
152
  path: 'src/lint-sample.js',
148
153
  language: 'javascript',
149
154
  content: 'const = 1\n',
150
155
  })
151
- check('lint reports syntax error', lintSyntax.diagnostics.some((item) => item.severity === 1 && item.code === 1134), JSON.stringify(lintSyntax.diagnostics))
156
+ check('lint reports syntax error', lintSyntax.diagnostics.some((item) => item.severity === 1 && item.code === 'parsing-error'), JSON.stringify(lintSyntax.diagnostics))
152
157
  const lintNoisy = await call(router, 'lint.javascript', {
153
158
  root,
154
159
  path: 'src/lint-sample.js',
@@ -156,6 +161,16 @@ try {
156
161
  content: 'const someObject = {}\nsomeObject.missingProperty\n',
157
162
  })
158
163
  check('lint suppresses dynamic property warnings', lintNoisy.diagnostics.length === 0, JSON.stringify(lintNoisy.diagnostics))
164
+ await call(router, 'fs.create', { root, path: '.eslintrc.json', kind: 'file' })
165
+ await call(router, 'fs.write', { root, path: '.eslintrc.json', content: JSON.stringify({ globals: { zzConfiguredGlobal: 'readonly' } }) })
166
+ const lintConfigured = await call(router, 'lint.javascript', {
167
+ root,
168
+ path: 'src/lint-sample.js',
169
+ language: 'javascript',
170
+ content: 'zzConfiguredGlobal\n',
171
+ })
172
+ check('lint respects project eslint globals', lintConfigured.diagnostics.length === 0, JSON.stringify(lintConfigured.diagnostics))
173
+ await call(router, 'fs.delete', { root, path: '.eslintrc.json' }).catch(() => {})
159
174
  await call(router, 'fs.delete', { root, path: 'src/lint-sample.js' }).catch(() => {})
160
175
 
161
176
  console.log('code.tsDefinition')
@@ -268,12 +268,12 @@ test('主题映射 dark→vs-dark / light→vs', () => {
268
268
  assert.equal(monacoTheme(undefined), 'vs')
269
269
  })
270
270
 
271
- test('编辑器选项:automaticLayout 开、minimap/overview ruler 关', () => {
271
+ test('编辑器选项:automaticLayout 开、minimap 关、ruler 开(查找标记)', () => {
272
272
  const options = G.EditorPane.internals.editorOptions('dark')
273
273
  assert.equal(options.automaticLayout, true)
274
274
  assert.equal(options.minimap.enabled, false)
275
- assert.equal(options.overviewRulerLanes, 0)
276
- assert.equal(options.renderOverviewRuler, false)
275
+ assert.equal(options.overviewRulerLanes, 1)
276
+ assert.equal(options.renderOverviewRuler, true)
277
277
  assert.equal(options.theme, 'vs-dark')
278
278
  assert.equal(G.EditorPane.internals.editorOptions('light').theme, 'vs')
279
279
  })
@@ -1153,6 +1153,7 @@ G.errorText = (error) => {
1153
1153
  G.CSS = `
1154
1154
  .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}
1155
1155
  .gufa-backdrop{position:absolute;inset:0;z-index:0;overflow:hidden;pointer-events:none}
1156
+
1156
1157
  /* 桌面悬浮层(摸鱼)模式:整窗半透明,透明度由 --gufa-float-alpha 控制(标题栏滑块) */
1157
1158
  html[data-gufa-float]{--gufa-float-alpha:0.55}
1158
1159
  html[data-gufa-float] body{background:transparent!important;color-scheme:dark;
@@ -1293,7 +1294,17 @@ html[data-gufa-float] #root [data-gufa-dock],
1293
1294
  html[data-gufa-float] #root .gufa-overlay-root *,
1294
1295
  html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
1295
1296
  /* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
1297
+ /* 古法覆盖层打开时,DSH 右侧栏被覆盖却仍参与 layout/paint;
1298
+ myrta 这类会话会给右侧栏渲染 7000+ 节点,导致编辑器滚动每帧 style/layout 50ms。 */
1299
+ html[data-gufa-ide] [class*="rightbarCol"],
1300
+ html[data-gufa-float] [class*="rightbarCol"]{display:none!important}
1301
+
1296
1302
  html[data-gufa-ide] .dsh-pet-root{z-index:2147483050!important}
1303
+ /* 聊天栏收起时,把覆盖层下面的官方会话(可能几千个 DOM 节点)真正隐藏,
1304
+ 避免编辑器滚动时整页 layout/paint 把它一起算进去。 */
1305
+ /* 古法/摸鱼模式下皮肤自身的粒子 canvas 不参与绘制(防止 WebGL/rAF 在覆盖层下面持续跑) */
1306
+ html[data-gufa-ide] .liang-ambient,
1307
+ html[data-gufa-float] .liang-ambient{display:none!important}
1297
1308
  /* 外部弹窗(DSH 设置等)打开时:停靠会话、古法 portal、桌宠全部降到官方弹窗之下 */
1298
1309
  html[data-gufa-external-modal] [data-gufa-dock]{z-index:2!important}
1299
1310
  html[data-gufa-external-modal] #gufa-portal-root{z-index:1!important}
@@ -130,6 +130,9 @@
130
130
  'editorLink.activeForeground': gufaHex(accent),
131
131
  'editorInfo.foreground': gufaHex(accent),
132
132
  'editorOverviewRuler.border': '#00000000',
133
+ 'editorOverviewRuler.findMatchForeground': dark ? '#d7ba7d' : '#b58900',
134
+ 'editorOverviewRuler.errorForeground': '#f14c4c',
135
+ 'editorOverviewRuler.warningForeground': '#cca700',
133
136
  'scrollbarSlider.background': gufaHexAlpha(fg, 0.16),
134
137
  'scrollbarSlider.hoverBackground': gufaHexAlpha(fg, 0.26),
135
138
  'scrollbarSlider.activeBackground': gufaHexAlpha(fg, 0.34),
@@ -541,7 +544,7 @@ function gufaRegisterDefinitionInfrastructure(monaco) {
541
544
  }
542
545
 
543
546
  /* 诊断波浪线已关闭(用户要求);Host lint 也不再在每次输入后跑 tsc,省 CPU */
544
- const GUFA_LINT_ENABLED = false
547
+ const GUFA_LINT_ENABLED = true
545
548
 
546
549
  /* ── model / URI ────────────────────────────────────────────────────── */
547
550
 
@@ -594,19 +597,82 @@ const GUFA_LINT_ENABLED = false
594
597
  return model
595
598
  }
596
599
 
600
+ /**
601
+ * 查找框可见时才打开 overview ruler(查找匹配标记),关闭时收起。
602
+ * 常开 ruler 会在每次滚动时额外渲染诊断/查找标记,体感卡。
603
+ */
604
+ function gufaInstallFindRuler(instance) {
605
+ try {
606
+ const dom = typeof instance.getDomNode === 'function' ? instance.getDomNode() : null
607
+ if (dom === null || dom === undefined) return null
608
+ let frame = 0
609
+ const apply = () => {
610
+ frame = 0
611
+ let visible = false
612
+ try {
613
+ const widget = dom.querySelector('.find-widget')
614
+ visible = widget !== null && widget !== undefined && widget.classList.contains('visible')
615
+ } catch {
616
+ visible = false
617
+ }
618
+ try {
619
+ instance.updateOptions({ renderOverviewRuler: visible, overviewRulerLanes: visible ? 1 : 0 })
620
+ } catch {
621
+ /* ignore */
622
+ }
623
+ }
624
+ const schedule = () => {
625
+ if (frame !== 0) return
626
+ frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(apply) : window.setTimeout(apply, 16)
627
+ }
628
+ const observer = typeof MutationObserver === 'function' ? new MutationObserver((records) => {
629
+ for (const record of records) {
630
+ if (record.type === 'attributes' && record.target instanceof Element && record.target.classList.contains('find-widget')) {
631
+ schedule()
632
+ return
633
+ }
634
+ if (record.type === 'childList') {
635
+ for (const node of record.addedNodes) {
636
+ if (node instanceof Element && (node.classList.contains('find-widget') || node.querySelector('.find-widget') !== null)) {
637
+ schedule()
638
+ return
639
+ }
640
+ }
641
+ }
642
+ }
643
+ }) : null
644
+ observer?.observe(dom, { subtree: true, attributes: true, attributeFilter: ['class'], childList: true })
645
+ return () => {
646
+ try { observer?.disconnect() } catch { /* ignore */ }
647
+ if (frame !== 0) {
648
+ try {
649
+ if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
650
+ else window.clearTimeout(frame)
651
+ } catch { /* ignore */ }
652
+ frame = 0
653
+ }
654
+ }
655
+ } catch {
656
+ return null
657
+ }
658
+ }
659
+
597
660
  /** Monaco 编辑器选项:关闭 minimap / overview ruler,automaticLayout 跟随容器尺寸。 */
598
661
  function gufaEditorOptions(theme) {
599
662
  return {
600
663
  theme: gufaMonacoTheme(theme),
601
664
  automaticLayout: true,
602
665
  minimap: { enabled: false },
603
- renderOverviewRuler: false,
604
- overviewRulerLanes: 0,
666
+ /* 右侧 ruler 常开:查找匹配/诊断标记显示在滚动条旁 */
667
+ renderOverviewRuler: true,
668
+ overviewRulerLanes: 1,
605
669
  overviewRulerBorder: false,
606
670
  hideCursorInOverviewRuler: true,
607
671
  scrollBeyondLastLine: false,
608
672
  smoothScrolling: true,
609
673
  cursorBlinking: 'smooth',
674
+ /* 滚动相关的额外渲染关掉:sticky scroll / 常驻 overview ruler 已单独处理 */
675
+ stickyScroll: { enabled: false },
610
676
  fontSize: 13,
611
677
  lineHeight: 20,
612
678
  fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
@@ -882,27 +948,13 @@ const GUFA_LINT_ENABLED = false
882
948
  } catch {
883
949
  /* ignore */
884
950
  }
885
- /* 错误诊断恢复 Monaco 原生 TS worker:语法/语义/类型错误都正常画线。
886
- Monaco 的 javascriptDefaults 默认关掉了 JS 语义诊断(noSemanticValidation=true),
887
- 这里显式打开并开 checkJs,否则 .js 里只有语法错误、没有未定义变量等诊断。 */
951
+ /* 诊断统一由 Host 提供:JS 用项目 ESLint(尊重 .eslintrc/globals/rules),
952
+ TS 回落 Host tsc;关掉 Monaco worker 诊断,避免同一个错误画两条线/问题计数翻倍。 */
888
953
  try {
889
954
  const typescriptLanguages = monaco.languages.typescript
890
- if (typescriptLanguages !== null && typescriptLanguages !== undefined) {
891
- const diagnosticsOn = { noSemanticValidation: false, noSyntaxValidation: false }
892
- typescriptLanguages.typescriptDefaults?.setDiagnosticsOptions(diagnosticsOn)
893
- typescriptLanguages.javascriptDefaults?.setDiagnosticsOptions(diagnosticsOn)
894
- typescriptLanguages.javascriptDefaults?.setCompilerOptions({
895
- allowNonTsExtensions: true,
896
- allowJs: true,
897
- checkJs: true,
898
- target: 99,
899
- moduleResolution: 2,
900
- module: 99,
901
- jsx: 1,
902
- esModuleInterop: true,
903
- allowSyntheticDefaultImports: true,
904
- })
905
- }
955
+ const diagnosticsOff = { noSemanticValidation: true, noSyntaxValidation: true }
956
+ typescriptLanguages?.typescriptDefaults?.setDiagnosticsOptions(diagnosticsOff)
957
+ typescriptLanguages?.javascriptDefaults?.setDiagnosticsOptions(diagnosticsOff)
906
958
  } catch (error) {
907
959
  /* ignore */
908
960
  }
@@ -1828,7 +1880,10 @@ const GUFA_LINT_ENABLED = false
1828
1880
  minimap: { enabled: false },
1829
1881
  scrollBeyondLastLine: false,
1830
1882
  lineNumbers: 'on',
1831
- renderOverviewRuler: false,
1883
+ /* diff 编辑器也显示右侧 overview ruler:新增/删除改动在滚动条旁有红绿标记 */
1884
+ renderOverviewRuler: true,
1885
+ overviewRulerLanes: 1,
1886
+ overviewRulerBorder: false,
1832
1887
  fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
1833
1888
  fontSize: 12.5,
1834
1889
  lineHeight: 1.15,
@@ -504,6 +504,57 @@ G.BackdropParticles = function BackdropParticles(props) {
504
504
  return h('canvas', { ref: canvasRef, className: 'gufa-backdrop-particles', 'aria-hidden': 'true', style: { mixBlendMode: 'screen' } })
505
505
  }
506
506
 
507
+ /** 进入古法 IDE 时临时关掉皮肤自身的粒子/动效(它们会在覆盖层下面持续跑 WebGL/rAF);
508
+ * 退出时恢复用户原设置,不改变用户偏好。 */
509
+ let gufaSkinEffectsSaved = null
510
+ G.suspendSkinEffects = function suspendSkinEffects() {
511
+ try {
512
+ if (gufaSkinEffectsSaved !== null) return
513
+ const raw = localStorage.getItem(SKIN_SETTINGS_KEY)
514
+ if (raw === null || raw === '') return
515
+ const record = JSON.parse(raw)
516
+ if (record === null || typeof record !== 'object' || record.values === null || typeof record.values !== 'object') return
517
+ const values = record.values
518
+ if (values.particlesEnabled !== true && values.motionEnabled !== true) return
519
+ gufaSkinEffectsSaved = raw
520
+ const next = { ...record, values: { ...values, particlesEnabled: false, motionEnabled: false } }
521
+ const payload = JSON.stringify(next)
522
+ localStorage.setItem(SKIN_SETTINGS_KEY, payload)
523
+ try {
524
+ window.dispatchEvent(new StorageEvent('storage', {
525
+ key: SKIN_SETTINGS_KEY,
526
+ oldValue: raw,
527
+ newValue: payload,
528
+ storageArea: localStorage,
529
+ }))
530
+ } catch {
531
+ /* ignore */
532
+ }
533
+ } catch {
534
+ gufaSkinEffectsSaved = null
535
+ }
536
+ }
537
+ G.resumeSkinEffects = function resumeSkinEffects() {
538
+ try {
539
+ if (gufaSkinEffectsSaved === null) return
540
+ const raw = gufaSkinEffectsSaved
541
+ gufaSkinEffectsSaved = null
542
+ localStorage.setItem(SKIN_SETTINGS_KEY, raw)
543
+ try {
544
+ window.dispatchEvent(new StorageEvent('storage', {
545
+ key: SKIN_SETTINGS_KEY,
546
+ oldValue: null,
547
+ newValue: raw,
548
+ storageArea: localStorage,
549
+ }))
550
+ } catch {
551
+ /* ignore */
552
+ }
553
+ } catch {
554
+ /* ignore */
555
+ }
556
+ }
557
+
507
558
  /** 背景浓度滑杆(无级、连续;双击恢复「跟随皮肤」)。 */
508
559
  G.BackdropStrengthSlider = function BackdropStrengthSlider(props) {
509
560
  const t = G.useT()