Skip to content

修复 SQL 编辑器表名高亮丢失 - #8944

Merged
t8y2 merged 3 commits into
t8y2:mainfrom
zipg:codex/sql-table-highlight
Sep 12, 2026
Merged

修复 SQL 编辑器表名高亮丢失#8944
t8y2 merged 3 commits into
t8y2:mainfrom
zipg:codex/sql-table-highlight

Conversation

@zipg

@zipg zipg commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

问题

SQL 编辑器中的有效表名在部分内置主题或长 SQL 文件中没有稳定显示表名颜色:滚动后可能退化为普通文本颜色,切换标签后也可能出现高亮缺失。

修复

  • 为内置 CodeMirror 主题提供表名颜色兜底,避免编辑器专用 CSS 变量未定义时退化为普通文本色。
  • 对首次打开且长度受控的 SQL 文档预热完整语义高亮,减少滚动到新区域才临时着色的现象。
  • 语法树尚未准备好时保留已有装饰,避免一次增量计算清空现有高亮。

验证

  • pnpm exec vitest run apps/desktop/src/lib/__tests__/editorThemes.spec.ts apps/desktop/src/lib/__tests__/editor/queryEditorSemanticHighlightPerformance.spec.ts:21 项通过。
  • pnpm typecheck:通过。
  • 本地开发页面实测 query_12.sql 滚动前后表名保持橙色高亮。

Fixes #8942

@github-actions github-actions Bot added area/desktop Desktop application or Tauri shell ui-change Changes user-visible interface, text, or visual assets labels Sep 12, 2026
initialize decorations to Decoration.none in the constructor so the
!tree fallback can never surface undefined into the codemirror
decoration pipeline, and gate the full-document prewarm behind a
one-shot per-document flag so post-edit refreshes return to
visible-range computation
@t8y2

t8y2 commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Thanks — both mechanisms in this PR match the two root causes of #8942. I pushed one follow-up commit (1ee0dbf7) to close a crash path and a perf gap:

  1. buildDecorations now returns this.decorations when the syntax tree isn't ready, but its first call happens from the constructor where that field is still unassigned — returning undefined throws inside CodeMirror's decoration pipeline (RangeSet.compare reads set.maxPoint). Realistic trigger: >128K documents with a cold parser (25ms ensureSyntaxTree budget) crash at mount, and even surviving that would throw on the first keystroke in update(). The constructor now initializes this.decorations = Decoration.none first.
  2. The full-document prewarm re-ran after every edit (the window cache is cleared on each doc change), turning steady-state highlighting cost from O(viewport) into O(document). It's now gated behind a one-shot per-document flag, with a regression assertion added to the perf spec.

Both existing specs stay green (22/22 locally).

@t8y2
t8y2 merged commit 6694e43 into t8y2:main Sep 12, 2026
14 checks passed
@t8y2

t8y2 commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in 6694e43, will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/desktop Desktop application or Tauri shell ui-change Changes user-visible interface, text, or visual assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] SQL 编辑器表名高亮在切换或滚动后丢失

2 participants