dsh-gufa-code 1.3.118 → 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.
@@ -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),
@@ -403,6 +406,146 @@
403
406
  const GUFA_LSP_WARMED = new Set()
404
407
  const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'def', 'func', 'fn', 'type', 'export', 'lsp'])
405
408
 
409
+ /* ── 原生 DefinitionProvider + editor opener ─────────────────────────
410
+ * Cmd+点击 / F12 都交给 Monaco 自己的 `editor.action.revealDefinition`;
411
+ * 定义解析走 Host API(JS/TS 用 code.definition,Python 用 pyright 的 lsp.definition),
412
+ * 打开文件由 registerEditorOpener 转成 App 的 editor:open-at,多个结果交给 Monaco 原生 peek。
413
+ */
414
+ /* JS/TS 的 F12 交回 Monaco 原生 TS DefinitionProvider(之前被我们关掉过);
415
+ Cmd+点击在 click handler 里直接走 Host LanguageService 以拿到最准结果。 */
416
+ const GUFA_DEFINITION_LANGUAGES = ['python']
417
+ function gufaRegisterDefinitionInfrastructure(monaco) {
418
+ try {
419
+ if (monaco === null || monaco === undefined) return
420
+ if (G.__gufaDefinitionInfra === true) return
421
+ if (monaco.languages === null || monaco.languages === undefined || typeof monaco.languages.registerDefinitionProvider !== 'function') return
422
+ G.__gufaDefinitionInfra = true
423
+ const rootAt = () => (typeof G.projectRoot === 'string' ? G.projectRoot.replace(/\\/g, '/').replace(/\/+$/, '') : '')
424
+ const pathOfModel = (model) => {
425
+ const root = rootAt()
426
+ if (root === '' || model === null || model === undefined) return null
427
+ let absolute = ''
428
+ try {
429
+ absolute = model.uri?.fsPath ?? (typeof model.uri?.path === 'string' ? decodeURIComponent(model.uri.path) : '')
430
+ } catch {
431
+ return null
432
+ }
433
+ absolute = String(absolute).replace(/\\/g, '/')
434
+ if (!absolute.startsWith(`${root}/`)) return null
435
+ return { root, path: absolute.slice(root.length + 1) }
436
+ }
437
+ const locationsOf = (root, matches, word, monacoNs) => {
438
+ const list = Array.isArray(matches) ? matches : []
439
+ const result = []
440
+ const seen = new Set()
441
+ for (const match of list.slice(0, 10)) {
442
+ if (match === null || typeof match !== 'object' || typeof match.path !== 'string') continue
443
+ /* TS lib 定义(parseInt/Promise 等)走 readTsLib 只读标签,不交给 Monaco 原生动作 */
444
+ if (match.external === true || typeof match.absolutePath === 'string') continue
445
+ const line = Math.max(1, Math.trunc(Number(match.line) || 1))
446
+ const column = Math.max(1, Math.trunc(Number(match.column) || 1))
447
+ const key = `${match.path}:${line}:${column}`
448
+ if (seen.has(key)) continue
449
+ seen.add(key)
450
+ const uri = gufaModelUri(monacoNs, root, match.path)
451
+ const range = new monacoNs.Range(line, column, line, column + Math.max(1, word.length))
452
+ result.push({ uri, range })
453
+ }
454
+ return result
455
+ }
456
+ for (const language of GUFA_DEFINITION_LANGUAGES) {
457
+ try {
458
+ monaco.languages.registerDefinitionProvider(language, {
459
+ async provideDefinition(model, position, token) {
460
+ if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
461
+ const info = pathOfModel(model)
462
+ if (info === null) return []
463
+ const wordInfo = typeof model.getWordAtPosition === 'function' ? model.getWordAtPosition(position) : null
464
+ const word = wordInfo !== null && wordInfo !== undefined && typeof wordInfo.word === 'string' ? wordInfo.word : ''
465
+ try {
466
+ let result = null
467
+ if (language === 'python') {
468
+ result = await G.api('lsp.definition', {
469
+ root: info.root,
470
+ path: info.path,
471
+ line: position.lineNumber,
472
+ column: position.column,
473
+ language: 'python',
474
+ content: model.getValue(),
475
+ })
476
+ } else {
477
+ /* LanguageService 解析定义(TS 编译器),比正则项目搜索准确;
478
+ JS/TS 不再回退到 code.definition,避免“宁可跳错也不空着”。 */
479
+ result = await G.api('code.tsDefinition', {
480
+ root: info.root,
481
+ path: info.path,
482
+ line: position.lineNumber,
483
+ column: position.column,
484
+ content: model.getValue(),
485
+ })
486
+ }
487
+ if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
488
+ return locationsOf(info.root, result !== null && result !== undefined ? result.matches : null, word, monaco)
489
+ } catch {
490
+ return []
491
+ }
492
+ },
493
+ })
494
+ } catch {
495
+ /* 单个语言注册失败不影响其它语言 */
496
+ }
497
+ }
498
+ try {
499
+ if (typeof monaco.editor.registerEditorOpener === 'function') {
500
+ monaco.editor.registerEditorOpener({
501
+ openCodeEditor(source, resource, selectionOrPosition) {
502
+ const root = rootAt()
503
+ if (root === '') return false
504
+ let absolute = ''
505
+ try {
506
+ absolute = resource?.fsPath ?? (typeof resource?.path === 'string' ? decodeURIComponent(resource.path) : '')
507
+ } catch {
508
+ return false
509
+ }
510
+ absolute = String(absolute).replace(/\\/g, '/')
511
+ const selection = selectionOrPosition !== null && selectionOrPosition !== undefined && selectionOrPosition.selection !== undefined
512
+ ? selectionOrPosition.selection
513
+ : selectionOrPosition
514
+ const line = Math.max(1, Math.trunc(Number(selection?.startLineNumber ?? selection?.lineNumber ?? 1) || 1))
515
+ const column = Math.max(1, Math.trunc(Number(selection?.startColumn ?? selection?.column ?? 1) || 1))
516
+ if (absolute.startsWith(`${root}/`)) {
517
+ try {
518
+ G.bus.emit('editor:open-at', { path: absolute.slice(root.length + 1), line, column })
519
+ } catch {
520
+ return false
521
+ }
522
+ return true
523
+ }
524
+ /* 系统内置 API 的定义在 TS worker 的 lib 里(parseInt 等):按 basename 交给只读标签打开 */
525
+ const baseName = absolute.slice(absolute.lastIndexOf('/') + 1)
526
+ if (/^lib\.[A-Za-z0-9._-]+\.d\.ts$/.test(baseName)) {
527
+ try {
528
+ G.bus.emit('editor:open-external', { absolutePath: '', libName: baseName, path: baseName, line, column })
529
+ } catch {
530
+ return false
531
+ }
532
+ return true
533
+ }
534
+ return false
535
+ },
536
+ })
537
+ }
538
+ } catch {
539
+ /* ignore */
540
+ }
541
+ } catch {
542
+ /* ignore */
543
+ }
544
+ }
545
+
546
+ /* 诊断波浪线已关闭(用户要求);Host lint 也不再在每次输入后跑 tsc,省 CPU */
547
+ const GUFA_LINT_ENABLED = true
548
+
406
549
  /* ── model / URI ────────────────────────────────────────────────────── */
407
550
 
408
551
  /**
@@ -454,19 +597,82 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
454
597
  return model
455
598
  }
456
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
+
457
660
  /** Monaco 编辑器选项:关闭 minimap / overview ruler,automaticLayout 跟随容器尺寸。 */
458
661
  function gufaEditorOptions(theme) {
459
662
  return {
460
663
  theme: gufaMonacoTheme(theme),
461
664
  automaticLayout: true,
462
665
  minimap: { enabled: false },
463
- renderOverviewRuler: false,
464
- overviewRulerLanes: 0,
666
+ /* 右侧 ruler 常开:查找匹配/诊断标记显示在滚动条旁 */
667
+ renderOverviewRuler: true,
668
+ overviewRulerLanes: 1,
465
669
  overviewRulerBorder: false,
466
670
  hideCursorInOverviewRuler: true,
467
671
  scrollBeyondLastLine: false,
468
672
  smoothScrolling: true,
469
673
  cursorBlinking: 'smooth',
674
+ /* 滚动相关的额外渲染关掉:sticky scroll / 常驻 overview ruler 已单独处理 */
675
+ stickyScroll: { enabled: false },
470
676
  fontSize: 13,
471
677
  lineHeight: 20,
472
678
  fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
@@ -737,8 +943,13 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
737
943
  } catch (error) {
738
944
  /* 模板语言注册失败不影响编辑器 */
739
945
  }
740
- /* 诊断改由 Host 的 TypeScript 编译器提供(dsh-app worker 不可靠),
741
- 关闭 Monaco worker 诊断避免重复/后台报错;补全建议仍由 worker 提供。 */
946
+ try {
947
+ gufaRegisterDefinitionInfrastructure(monaco)
948
+ } catch {
949
+ /* ignore */
950
+ }
951
+ /* 诊断统一由 Host 提供:JS 用项目 ESLint(尊重 .eslintrc/globals/rules),
952
+ TS 回落 Host tsc;关掉 Monaco worker 诊断,避免同一个错误画两条线/问题计数翻倍。 */
742
953
  try {
743
954
  const typescriptLanguages = monaco.languages.typescript
744
955
  const diagnosticsOff = { noSemanticValidation: true, noSyntaxValidation: true }
@@ -909,8 +1120,9 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
909
1120
  /* ignore */
910
1121
  }
911
1122
  }
1123
+ /* Cmd 悬停只给单词换颜色(蓝色),不加下划线、不弹原生 link 提示框。 */
912
1124
  const showHoverDecoration = (position, wordInfo) => {
913
- if (wordInfo === null || wordInfo === undefined) return clearHoverDecoration()
1125
+ if (wordInfo === null || wordInfo === undefined || position === null || position === undefined) return clearHoverDecoration()
914
1126
  let range = null
915
1127
  try {
916
1128
  range = new monaco.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn)
@@ -919,68 +1131,28 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
919
1131
  }
920
1132
  try {
921
1133
  hover.decorationIds = instance.deltaDecorations(hover.decorationIds, [
922
- { range, options: { inlineClassName: 'gufa-def-link', stickiness: 1 } },
1134
+ { range, options: { inlineClassName: 'gufa-def-link-color', stickiness: 1 } },
923
1135
  ])
924
1136
  } catch {
925
1137
  /* ignore */
926
1138
  }
927
- try {
928
- editorDom.classList.add('gufa-def-hover')
929
- } catch {
930
- /* ignore */
931
- }
932
1139
  }
933
1140
  const evaluateHoverPosition = (position, wordInfo) => {
934
1141
  if (!hover.meta) {
935
1142
  clearHoverDecoration()
936
1143
  return
937
1144
  }
938
- const model = instance.getModel()
939
1145
  const word = wordInfo !== null && wordInfo !== undefined && typeof wordInfo.word === 'string' ? wordInfo.word : ''
940
- const path = modelPathRef.current
941
- const root = modelsRootRef.current
942
- if (position === null || position === undefined || model === null || model === undefined
943
- || word.length < 2 || path === null || path === undefined || root === null || root === undefined || root === '') {
1146
+ if (position === null || position === undefined || word.length < 2) {
944
1147
  clearHoverDecoration()
945
1148
  return
946
1149
  }
947
- hover.lastPosition = position
948
- hover.lastWordInfo = wordInfo
949
- const key = `${path}|${word}`
1150
+ /* 不再为了下划线去跑项目级定义搜索:按住 Cmd 立刻标出当前单词,
1151
+ 真正解析只发生在点击时。之前 hover 的 host 扫描是「难用/卡」的主要来源。 */
1152
+ const key = `${position.lineNumber}:${wordInfo.startColumn}:${wordInfo.endColumn}`
1153
+ if (hover.lastKey === key && hover.decorationIds.length > 0) return
950
1154
  hover.lastKey = key
951
- const cached = hover.cache.get(key)
952
- if (cached === 'none') {
953
- clearHoverDecoration()
954
- return
955
- }
956
- if (cached === 'yes') {
957
- showHoverDecoration(position, wordInfo)
958
- return
959
- }
960
- if (hover.timer !== 0) {
961
- window.clearTimeout(hover.timer)
962
- hover.timer = 0
963
- }
964
- const seq = ++hover.seq
965
- hover.timer = window.setTimeout(() => {
966
- hover.timer = 0
967
- if (!hover.meta || seq !== hover.seq) return
968
- void queryDefinitions(position, word, model, path, root).then((result) => {
969
- if (!hover.meta || seq !== hover.seq || hover.lastKey !== key) return
970
- const decision = decideDefinition(result)
971
- if (decision.kind === 'none') {
972
- if (hover.cache.size > 100) hover.cache.clear()
973
- hover.cache.set(key, 'none')
974
- clearHoverDecoration()
975
- return
976
- }
977
- if (hover.cache.size > 100) hover.cache.clear()
978
- hover.cache.set(key, 'yes')
979
- showHoverDecoration(position, wordInfo)
980
- }).catch(() => {
981
- /* ignore */
982
- })
983
- }, 130)
1155
+ showHoverDecoration(position, wordInfo)
984
1156
  }
985
1157
  /* 用 Monaco 自己的 onMouseMove(带修饰键状态 + 精确 position),
986
1158
  不依赖 DOM mousedown/getTargetAtClientPoint 的坐标系与包含关系。 */
@@ -1091,13 +1263,66 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1091
1263
  } catch {
1092
1264
  /* ignore */
1093
1265
  }
1266
+ /* Cmd+点击直接用 Host 的准确解析,避免依赖 Monaco 原生 action/worker:
1267
+ - JS/TS:TypeScript LanguageService(含 parseInt 等系统 lib);
1268
+ - Python:pyright lsp.definition。 */
1269
+ const clickLanguage = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
1270
+ if (clickLanguage === 'javascript' || clickLanguage === 'typescript') {
1271
+ try {
1272
+ const resolved = await G.api('code.tsDefinition', {
1273
+ root,
1274
+ path,
1275
+ line: position.lineNumber,
1276
+ column: position.column,
1277
+ content: model.getValue(),
1278
+ })
1279
+ const matches = resolved !== null && resolved !== undefined && Array.isArray(resolved.matches) ? resolved.matches : []
1280
+ const internal = matches.find((item) => item !== null && item !== undefined && item.external !== true && typeof item.path === 'string' && item.path !== '')
1281
+ if (internal !== undefined) {
1282
+ G.bus.emit('editor:open-at', { path: internal.path, line: internal.line, column: internal.column })
1283
+ } else {
1284
+ const external = matches.find((item) => item !== null && item !== undefined && item.external === true && typeof item.absolutePath === 'string')
1285
+ if (external !== undefined) {
1286
+ G.bus.emit('editor:open-external', {
1287
+ absolutePath: external.absolutePath,
1288
+ path: typeof external.path === 'string' ? external.path : '',
1289
+ line: external.line,
1290
+ column: external.column,
1291
+ })
1292
+ }
1293
+ }
1294
+ } catch {
1295
+ /* 解析失败不跳错 */
1296
+ }
1297
+ clearHoverDecoration()
1298
+ return
1299
+ }
1300
+ if (clickLanguage === 'python') {
1301
+ try {
1302
+ const resolved = await G.api('lsp.definition', {
1303
+ root,
1304
+ path,
1305
+ line: position.lineNumber,
1306
+ column: position.column,
1307
+ language: 'python',
1308
+ content: model.getValue(),
1309
+ })
1310
+ const matches = resolved !== null && resolved !== undefined && Array.isArray(resolved.matches) ? resolved.matches : []
1311
+ const first = matches.find((item) => item !== null && item !== undefined && typeof item.path === 'string' && item.path !== '')
1312
+ if (first !== undefined) G.bus.emit('editor:open-at', { path: first.path, line: first.line, column: first.column })
1313
+ } catch {
1314
+ /* ignore */
1315
+ }
1316
+ clearHoverDecoration()
1317
+ return
1318
+ }
1319
+ /* 其它语言:保留 Monaco 原生 action 兜底 */
1094
1320
  try {
1095
- await preloadTsDependencies(model, path, root)
1321
+ instance.focus()
1322
+ instance.setPosition(position)
1096
1323
  } catch {
1097
1324
  /* ignore */
1098
1325
  }
1099
- const beforePath = modelPathRef.current
1100
- const beforePosition = instance.getPosition()
1101
1326
  try {
1102
1327
  const action = typeof instance.getAction === 'function' ? instance.getAction('editor.action.revealDefinition') : null
1103
1328
  if (action !== null && action !== undefined) {
@@ -1107,37 +1332,8 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1107
1332
  } catch {
1108
1333
  /* ignore */
1109
1334
  }
1110
- await new Promise((resolve) => { window.setTimeout(resolve, 160) })
1111
- let monacoHandled = false
1112
- try {
1113
- const afterPosition = instance.getPosition()
1114
- monacoHandled = modelPathRef.current !== beforePath
1115
- || (beforePosition !== null && beforePosition !== undefined && afterPosition !== null && afterPosition !== undefined
1116
- && (afterPosition.lineNumber !== beforePosition.lineNumber || afterPosition.column !== beforePosition.column))
1117
- || document.querySelector('.monaco-editor .peekview-widget, .monaco-editor .reference-zone-widget') !== null
1118
- } catch {
1119
- monacoHandled = false
1120
- }
1335
+ await new Promise((resolve) => { window.setTimeout(resolve, 200) })
1121
1336
  clearHoverDecoration()
1122
- if (monacoHandled) return
1123
- try {
1124
- const result = await queryDefinitions(position, word, model, path, root)
1125
- const decision = decideDefinition(result)
1126
- if (decision.kind === 'open') {
1127
- G.bus.emit('editor:open-at', { path: decision.match.path, line: decision.match.line, column: decision.match.column })
1128
- return
1129
- }
1130
- if (decision.kind === 'pick') {
1131
- G.bus.emit('definition:pick', {
1132
- word: result !== null && result !== undefined && typeof result.word === 'string' ? result.word : word,
1133
- matches: decision.matches,
1134
- x: event.clientX,
1135
- y: event.clientY,
1136
- })
1137
- }
1138
- } catch {
1139
- /* ignore */
1140
- }
1141
1337
  }
1142
1338
  document.addEventListener('mousedown', onDefinitionClick, true)
1143
1339
  document.addEventListener('keydown', onMetaDown, true)
@@ -1163,6 +1359,88 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1163
1359
  } catch {
1164
1360
  /* ignore */
1165
1361
  }
1362
+ /* 外部/AI 修改磁盘后由 App 轮询发现,通过 bus 通知编辑器热替换 model 内容。
1363
+ (1.3.117 删 AI Tab 时误删过这一段,1.3.125 恢复) */
1364
+ try {
1365
+ if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
1366
+ const offExternalReload = G.bus.on('editor:external-reload', (detail) => {
1367
+ if (detail === null || detail === undefined || typeof detail.path !== 'string' || typeof detail.content !== 'string') return
1368
+ const target = modelsRef.current.get(detail.path)
1369
+ if (target === null || target === undefined) return
1370
+ let content = ''
1371
+ try {
1372
+ content = target.getValue()
1373
+ } catch {
1374
+ return
1375
+ }
1376
+ if (content === detail.content) return
1377
+ const active = modelPathRef.current === detail.path
1378
+ let position = null
1379
+ let scrollTop = 0
1380
+ if (active) {
1381
+ try {
1382
+ position = instance.getPosition()
1383
+ scrollTop = instance.getScrollTop()
1384
+ } catch {
1385
+ position = null
1386
+ }
1387
+ }
1388
+ suppressChangeRef.current = true
1389
+ try {
1390
+ target.setValue(detail.content)
1391
+ } finally {
1392
+ suppressChangeRef.current = false
1393
+ }
1394
+ lastPropContentRef.current.set(detail.path, detail.content)
1395
+ if (active && position !== null && position !== undefined) {
1396
+ try {
1397
+ instance.setPosition(position)
1398
+ instance.setScrollTop(scrollTop)
1399
+ } catch {
1400
+ /* ignore */
1401
+ }
1402
+ }
1403
+ })
1404
+ if (typeof offExternalReload === 'function') subscriptions.push({ dispose: offExternalReload })
1405
+ }
1406
+ } catch {
1407
+ /* ignore */
1408
+ }
1409
+
1410
+ /* 拖拽分割条期间暂停 Monaco automaticLayout:
1411
+ 宽度每帧变化时 Monaco layout() 会跟着重排整块编辑器,是「不跟手」的大头;
1412
+ 拖拽先只动容器/别的面板,松手后再 layout 一次。 */
1413
+ try {
1414
+ if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
1415
+ const offResizeStart = G.bus.on('layout:resize-start', () => {
1416
+ try {
1417
+ instance.updateOptions({ automaticLayout: false })
1418
+ } catch {
1419
+ /* ignore */
1420
+ }
1421
+ })
1422
+ const offResizeEnd = G.bus.on('layout:resize-end', () => {
1423
+ const relayout = () => {
1424
+ try {
1425
+ instance.updateOptions({ automaticLayout: true })
1426
+ instance.layout()
1427
+ } catch {
1428
+ /* ignore */
1429
+ }
1430
+ }
1431
+ if (typeof requestAnimationFrame === 'function') {
1432
+ requestAnimationFrame(() => requestAnimationFrame(relayout))
1433
+ } else {
1434
+ window.setTimeout(relayout, 32)
1435
+ }
1436
+ })
1437
+ if (typeof offResizeStart === 'function') subscriptions.push({ dispose: offResizeStart })
1438
+ if (typeof offResizeEnd === 'function') subscriptions.push({ dispose: offResizeEnd })
1439
+ }
1440
+ } catch {
1441
+ /* ignore */
1442
+ }
1443
+
1166
1444
  G.__gufaEditorDebug = {
1167
1445
  focus: () => {
1168
1446
  try {
@@ -1226,6 +1504,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1226
1504
  lintTimers.clear()
1227
1505
  }
1228
1506
  const runLint = async (model, path) => {
1507
+ if (GUFA_LINT_ENABLED !== true) return
1229
1508
  if (model === null || model === undefined || typeof path !== 'string' || path === '') return
1230
1509
  const language = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
1231
1510
  if (language !== 'javascript' && language !== 'typescript') return
@@ -1263,6 +1542,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1263
1542
  }
1264
1543
  }
1265
1544
  const scheduleLint = (model, path) => {
1545
+ if (GUFA_LINT_ENABLED !== true) return
1266
1546
  if (model === null || model === undefined || typeof path !== 'string' || path === '') return
1267
1547
  const previous = lintTimers.get(path)
1268
1548
  if (previous !== undefined) window.clearTimeout(previous)
@@ -1353,6 +1633,20 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1353
1633
  }
1354
1634
  }, [attempt, reportCursor, disposeAllModels])
1355
1635
 
1636
+ /* TS 内置 lib(parseInt 等)标签是只读预览 */
1637
+ const activeExternal = activeTab !== null && activeTab.external === true
1638
+ useEffect(() => {
1639
+ if (status !== 'ready') return undefined
1640
+ const instance = editorRef.current
1641
+ if (instance === null || instance === undefined) return undefined
1642
+ try {
1643
+ instance.updateOptions({ readOnly: activeExternal })
1644
+ } catch {
1645
+ /* ignore */
1646
+ }
1647
+ return undefined
1648
+ }, [activeExternal, status])
1649
+
1356
1650
  /* ── 同步 tabs ↔ models,并切换当前 model ──────────────────────── */
1357
1651
  useEffect(() => {
1358
1652
  if (status !== 'ready') return
@@ -1586,7 +1880,10 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1586
1880
  minimap: { enabled: false },
1587
1881
  scrollBeyondLastLine: false,
1588
1882
  lineNumbers: 'on',
1589
- renderOverviewRuler: false,
1883
+ /* diff 编辑器也显示右侧 overview ruler:新增/删除改动在滚动条旁有红绿标记 */
1884
+ renderOverviewRuler: true,
1885
+ overviewRulerLanes: 1,
1886
+ overviewRulerBorder: false,
1590
1887
  fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
1591
1888
  fontSize: 12.5,
1592
1889
  lineHeight: 1.15,
@@ -558,6 +558,8 @@ function GufaTerminalView(props) {
558
558
 
559
559
  const fitNow = () => {
560
560
  if (fit === null || term === null || disposed) return
561
+ /* 拖分割条时尺寸每帧都在变,xterm.fit() 很重;等 layout:resize-end 一次算到位 */
562
+ if (G.__gufaSplitterDragging === true) return
561
563
  const host = hostRef.current
562
564
  if (host === null || host.clientWidth <= 0 || host.clientHeight <= 0) return
563
565
  try {
@@ -959,12 +961,19 @@ function GufaTerminalView(props) {
959
961
  openFrame = window.requestAnimationFrame(tryOpen)
960
962
  }
961
963
  props.register(terminalId, channel)
964
+ const offLayoutEnd = G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function'
965
+ ? () => {}
966
+ : G.bus.on('layout:resize-end', () => {
967
+ fitNow()
968
+ sendCurrentSize()
969
+ })
962
970
 
963
971
  startStream()
964
972
  if (mode === 'xterm') tryOpen()
965
973
 
966
974
  return () => {
967
975
  disposed = true
976
+ try { offLayoutEnd() } catch { /* ignore */ }
968
977
  if (retryTimer !== null) clearTimeout(retryTimer)
969
978
  if (replayTimer !== null) clearTimeout(replayTimer)
970
979
  if (openFrame !== 0) window.cancelAnimationFrame(openFrame)
@@ -1489,7 +1498,7 @@ G.TerminalPane = function TerminalPane(props) {
1489
1498
  {
1490
1499
  className: 'gufa-termpane',
1491
1500
  style: {
1492
- height,
1501
+ height: `var(--gufa-h-terminal, ${height}px)`,
1493
1502
  flex: '0 0 auto',
1494
1503
  display: 'flex',
1495
1504
  flexDirection: 'column',