Repository navigation
feat(editor): 内置彩虹配色、缩进参考线与上下文高亮 - #2420
Conversation
支持彩虹括号和彩虹变量设置、点击括号时标出配对端,以及当前文件的符号引用高亮。 本地联调通过 LITHE_CORE_RUST_DIR 加载配套的 Rust Core 检出。 Requires-Core: 4a2bd1262d821528c613c1fba0eb40a0e16543cc
提供普通与彩虹参考线开关,按花括号范围绘制参考线,并突出光标所在的最内层作用域。 Requires-Core: f3b816f0fe7fac2c93699d66bbf5cc4284ece84e
|
@mirakyux 评审后需要修改再转 ready。产品方向和 Lithe-IDEA/Lithe-core-rust#201 的评论一致:彩虹括号、彩虹变量和彩虹缩进参考线保持内置,要有开关和颜色设置。下面的问题请在本 PR 修掉,重点是第 2 点的性能。 必须修改1. 现在编译不过
处理顺序:
在此之前,请在 PR 描述里写明这个依赖。 2. 每次停顿都全量重扫整篇文档(主要问题)当前流程:
同一份文本, 我在 Apple M4 上用
按这个速度,1 MiB 的文档每次停顿约耗 0.4–0.6 s CPU,连续输入时每停一下就重来一次。 建议做法:
3. 触发上限时整篇静默清空
这时整篇的彩虹颜色、括号匹配和缩进参考线会一起消失,也没有任何日志。1 万个括号大约就是几千行的普通源文件,远远达不到 1 MiB 的门槛,用户会发现“文件稍大一点括号匹配就没了”。 建议:
4. 宿主按语言名特判宿主和 Core 不允许按语言名特判,但现在有这些:
建议把这些规则改成语言定义里声明的数据,例如通配符名称( 5. 跟进 Core #201 的修改Core 那边的改动会影响桌面端:
Core 推送后,请把 验证
|
|
本轮评审反馈已处理并推送:
Core #201 已推送功能修复及独立CI测试稳定性修复(4f4cc06c),当前Linux、SDK和契约检查通过,macOS/Windows运行中。Viva #60新增回归及race已通过,同分支上游Draft:vivaui/viva#457 。Viva fork两项Actions为action_required,尝试approve返回403(需仓库管理员);请管理员放行运行。 本机无zsh,资源只读shell门禁仍标记未完成;macOS和原生整机验收不以无头结果替代。三个本地工作区干净,本次应用/测试进程已退出。 |
|
@mirakyux 在 上次的第 1、5 项
新发现的问题
不阻塞,可以以后做
我本地跑过的(PR head
|
这些测试直接用 newHarnessWithOptions 建窗口,设置里没有主题时 New 会向系统查询外观; 测试进程的主线程没有事件循环,查询同步派发到主线程后一直等不到,测试随机卡到超时。 和 newHarnessWithLanguages 一样写入明确的主题即可避开。
|
补了一个提交 原因:这些测试直接用 在
评审意见(高亮器跨越 1 MiB 上限、降级日志去重、只移动位置时复用 Core 结果、Core 升到 |
There was a problem hiding this comment.
Devin Review found 3 potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| found, loadErr := disk.Load(settingsFile, ¤t) | ||
| if pending { | ||
| next.EditorPreferences = snapshot.stored | ||
| } else if found && loadErr == nil { | ||
| next.EditorPreferences = current.EditorPreferences | ||
| } |
There was a problem hiding this comment.
🔴 Unrelated editor option erases saved palette
When a second window changes an editor option before receiving a saved palette, persistSettings writes its stale palette back. The file lock serializes the saves but does not merge the unrelated changes.
Learn more
Open Project in New Window launches a separate process that shares the settings file. Each settings window starts an edit from its last delivered editor preferences, and setEditorPresentation sends the whole editor preferences object. The receiving process does not see external changes until the preferences watcher reloads and resolves them. The save transaction reads the latest disk state under the lock, but discards its editor preferences whenever a local editor edit is pending. The old palette then becomes the new on-disk value, so later watcher updates cannot recover the user's saved colors.
Example: In window A, save a new light palette. In window B, turn off indent guides after A's save completes but before B receives the palette update. The disk ends up with guides off and the old light palette, rather than both changes.
Recommended fix: Carry changed editor fields or an edit baseline with each save. Merge disjoint changes against the preferences read under the file lock, and detect conflicts for edits to the same field. Treat Restore Defaults as an explicit full reset. Resolve and publish the transaction's committed preferences.
Was this helpful? React with 👍 or 👎 to provide feedback.
| view.GoToLine(sp.line) | ||
| } | ||
| sp.view, sp.doc, sp.project = view, d, p | ||
| a.syncSourcePreviewDecorations(d) |
There was a problem hiding this comment.
🟡 Missing decorations in Problems previews
When Problems previews an unopened file, bindSourcePreview copies decorations from a document that has never requested them. The preview opens without bracket matching, enabled rainbow colors, or block-aware indent guides.
Learn more
syncProblemsPreview opens the source for a selected diagnostic. If there is no open document, showEditablePreview creates one through addTablessDocument. This path creates the syntax highlighter but does not start the workbench request that turns its candidates into colors and pairs. That request runs when the user attaches a tab or edits the file, neither of which is needed to preview a diagnostic.
Example: With rainbow colors enabled, select a Problems entry for an unopened Go file and click a brace in the preview. The preview shows ordinary syntax coloring but no rainbow colors or matching-brace highlight.
Recommended fix: Start initial decoration analysis for a tabless document when it becomes an editable preview, after binding the preview. Keep the existing in-flight request or prepared result when the preview binds to an already analyzed document.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if provider < len(p.spans) && p.spans[provider].start < builtin.End { | ||
| continue | ||
| } |
There was a problem hiding this comment.
🟡 Partial overlays erase whole variable colors
When a plugin colors part of an identifier, WithRainbowColors drops the identifier’s entire rainbow span. Its uncovered bytes lose rainbow coloring too.
Learn more
PrepareColorDecorations accepts provider spans in UTF-16 coordinates, and resolveRainbowCandidates produces full identifier spans. Unlike a one-byte bracket, a variable can overlap a provider range without being fully covered. The merge drops the entire variable span instead of drawing its uncovered segments.
Example: A provider colors count in item_count. The item_ prefix keeps its syntax color instead of the rainbow color assigned to item_count.
Recommended fix: During the ordered merge, emit each uncovered portion of a built-in span around intersecting provider spans. Preserve the invariant that the final spans are sorted and disjoint, and test a provider span strictly inside a variable.
Was this helpful? React with 👍 or 👎 to provide feedback.

关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
在多层嵌套代码中,仅靠语法主题色难以持续辨认配对括号、缩进层级和当前符号的引用。本 PR 增加可独立开启的宿主内置配色与背景高亮,主编辑器和 Problems 完整源码预览使用相同的显示偏好。
改动 / Changes
textDocument/documentHighlight,没有对应能力时使用 Core 的完整标识符字面匹配。颜色与背景不覆盖语法身份。$name、Unicode 标识符;覆盖 Vim Visual 选区、关闭 Vim、:q!关闭最后一个标签及 IME/选区修订校验。82530d8a0,合并提交698e8821b、e0070d6b1;保留 fix(editor): 深滚动自动换行只遍历可见折行 #2427 从首个可见折行firstSub开始的循环,将参考线与上下文高亮放在该循环内。设置冲突同时保留跨进程原子保存与 main 的窗口尺寸保存确认,仅在最新快照成功落盘后确认尺寸。本轮评审修复
补入
BenchmarkEditorViewPaint/indent-guides:默认普通参考线开启、安装已准备的作用域,100 KiB/10 MiB 沿用现有 Paint 预算,未修改预算文件。降级原因由文档最近一次被接受的结果保存,只记录新出现的原因;原因恢复后再现仍记录,旧请求不更新状态,避免每次编辑停顿消耗后台失败日志限额。
括号类型/变量名序列相同而仅偏移变化时复用 Core 结果,按旧候选位置找到序号并投影颜色、配对与作用域两端;支持非均匀位移、省略的不匹配闭括号,保留旧结果不可变,不在宿主重做配对或名称哈希。
跨过 1 MiB 上限关闭候选收集时保留词法检查点,只失效编辑范围并丢弃候选;重新进入上限内才重建候选,避免阈值附近反复全文分词。
复用现有 Highlighter 的 32 行增量段收集候选,停止每次停顿重建 tokenizer 扫整篇。访问符/模式绑定的输入状态纳入收敛,跨检查点删除不会保留旧状态。声明名后台汇总;语法差异改为元数据,删除按语言名特判。
整篇候选缓存最多各 10000 个括号和变量。长行、分词超时保留可信前缀;达到上限保留有界前缀,并分别记录既有目录事件。删除前段后按需补回候选。候选及开关相同则复用 Core 结果,失败结果不缓存。
跟进 Core 的失配恢复、fmix32 哈希、
rainbowLightColors/rainbowDarkColors字段和 documentHighlight 的可选 kind/truncated。LSP 截断在宿主边界记录降级。按图片反馈把彩虹括号、彩虹变量、彩虹参考线及两套色板移到独立“彩虹括号”区块;普通缩进参考线保留在编辑器显示区块。复用现有中英词条。
修正资源只读脚本 fixture 缺失设置发布工作流的 Linux 检查失败,保持门禁规则和覆盖范围。
Viva 已从上游 main 单独切分支提交 vivaui/viva #458(已合并),自定义和默认错误文案的回归测试及竞态通过。所需接口已随 main fix(desktop): 同步 Viva 上游 91da94ad(v0.6.9),固定 fork 7696355e #2439 的 Viva 同步进入当前固定版本。
修正本 PR 新增超时用例的真实 1 ns 计时依赖:改用私有 tokenizer 接口注入 stopped 结果,精确验证可信前缀与原因传播;生产仍使用 TextMate tokenizer,时限与超时语义不变。连续 100 次、相关竞态与逐项计时通过。接口调整前后 Go 候选管线 100 KiB 为 1.327→1.310 ms,1 MiB 为 2.638→2.629 ms,分配次数 424/434 均不变(各 6 个空闲样本)。
不在本 PR 范围内 / Out of scope
依赖已经进入当前固定版本,本轮验证使用默认入口,无本地 Core 或 Viva 覆盖:
c269c41153c8da2f2e8d064c68550a8f23260e2c,包含彩虹命令、偏好与完整标识符查找;保留 #2027696355e44b5,包含ColorPickerLabels.InvalidColor;原 fork #60 已关闭,无需继续等待此前阶段的截图和基线使用过本地依赖覆盖,以下历史记录保留其实际口径。本轮默认依赖的构建、测试与性能结果单列在验证表,不将旧覆盖结果当作默认构建证据。
不增加插件 API/协议版本,不复制插件契约或 SDK;不做真实插件端到端测试。macOS 与原生可见窗口完整验收仍待完成。
类型专属:feat
多平台对齐
verificationStatus: pending。本地仅验证 Windows amd64 组件,不宣称 macOS 或两端原生整机工作流通过。范围检查 / Scope checks
功能矩阵 / Feature matrix
editor-global-appearance、editor-context-highlights、editor-indent-guides,两端实现与验证状态分开记录。upstream/main HEAD变更门禁;未提交.artifacts/下生成视图。插件归属 / Plugin ownership
UI 验证 / UI evidence
TestVisualEditorContextHighlights、TestVisualProblemsSourcePreviewRainbow、TestVisualEditorEssentialsSettings/editor-settings-*;工作台源码293d01fd4;设置截图已按彩虹参考线移入彩虹区块的最终布局更新。统一日志系统 / Structured logging
log-exempt原因,未新增日志事件或直接 stderr 输出。界面文案 / i18n
desktop/internal/i18n查询;没有插件文案或手写生成文件。--check与 i18n 测试通过,未放宽规则或扩大豁免。逻辑归属 / Logic placement
c269c411并用默认依赖完成构建与消费者测试。性能与内存 / Performance and memory
候选管线新增基准(同机、相邻 6 样本,200 ms;一次迭代包括两次同宽编辑和快照):
改动后候选场景最多约 1.36 MiB 分配,新增场景预算 3 MiB,原有预算未调整。候选不变的 Core 缓存复用另有回归测试。
合并最新 main 后重新构建 main/当前两侧;相同 Core/Viva、CPU 0、GOMAXPROCS=1、500 ms,每个场景各 6 样本并交替顺序。监测编译器和工作台测试进程,48 个有效样本均未检测到重叠负载。原有文档规模与预算未改。以下为中位数:
小地图原始 1.73 超限没有在空闲条件下复现,两侧仍为 0 B/op、0 allocs/op。长行换行两侧均超规模比预算,属于 main 既有超限,本次未新增超限;10 MiB 耗时变化 +1.4%,分配次数不变。报告由现有 editor-perf-report 生成;非 Apple M4 参考机,不判绝对耗时上限。完整归因与命令见验证说明。
本轮默认路径性能复核
同机 Intel Core Ultra 5 125H、Windows amd64、CPU 0、GOMAXPROCS=1,每侧六个交替的 200 ms 样本。前侧仅覆盖合并前
61f4bc7的 paint/highlighter,两侧使用相同当前依赖与新增参考线场景;没有编译或其他测试重叠。参考线相对同一当前 Go 场景增加约 6.9% / 10.0%,规模比 0.95,保持零分配。所有绘制/滚动场景零分配,42 项视图结果均满足可判定预算,perfhistory 未报告回归。长行换行输入规模比 2.62→1.21,分配次数保持 9/16。语法候选管线六项均满足预算,分配次数不变。非参考机,不判绝对耗时上限。
首轮未固定 CPU 的 48 项预算均通过,但出现十项耗时回归;这些差异在固定同一 CPU、交替顺序的受控复核中未复现。首轮结果保留为观察,不用它证明无回归。命令、范围与限制见 验证说明。
设置 / Settings
插件契约 / Plugin contract
N/A:本 PR 未新增宿主方法/通知或修改插件协议;调用已有 LSP documentHighlight 和前景色接口。Core 应用命令依赖单列在前面的等待表;无 API 编号表或四语 SDK 变更。
发行包与资源 / Bundle and resources
.settings.lock和观察器归属用户配置目录,不写安装目录;对应安装目录只读回归合并后通过。docs/ci-builds.md已说明路径、所有权、释放和不可跨工作树复制的边界。verify-runtime-bundle-immutability.sh与 Node fixture 在 Linux CIFormat and script tests通过(运行 45739420847);覆盖 macOS/Windows 生产路径和 9 个安装包工作流。本机缺少 zsh,未重复执行。无用代码与重构 / Dead code and refactoring
验证 / Verification
test-stability-windows.ps1 -Scope DesktopGo,本地依赖覆盖,受影响的 5 包相关模式-race -count=1 -timeout=120seditor-settings-*,vivahead,lithevisualnode scripts/i18n/verify-app-language-localization.mjs、generate-i18n.mjs --checknode --test --test-timeout=60000 scripts/i18n/test-i18n.mjsnode scripts/platform-feature-matrix/generate-platform-feature-matrix.mjs --check、verify-platform-feature-matrix-change.mjs upstream/main HEADnode scripts/agent-notes/verify-agent-notes.mjsgit diff --check upstream/main...HEAD本轮默认固定依赖验证(Core c269c411 / Viva 7696355e)
build -o ../.artifacts/pr2420-update/lithe.exe ./cmd/lithe,无vivaheadtest ./internal/editor/... ./internal/editorview ./internal/settingswindow ./internal/core -count=1 -timeout=180stest-stability-windows.ps1 -Scope DesktopGo相关模式-race,最终 main 后工作台再次复核vivahead,lithevisualtest ./... -timeout=300s--check、矩阵、Agent Note、插件零依赖自查、diff 检查未能执行的检查和原因:
先前阶段的性能与超时归因(2026-11-26,历史依赖覆盖)
b6eab0b364,结果 Already up to date。此次诊断对应e0244463a;本轮只补验证资料。-test.count=1 -test.v -test.timeout=180s,配相同 Trace2 诊断,两侧都到期。main/当前分别完成 25/26 个顶层用例,共同 25 项报告耗时合计 160.84/153.17 s。main 在远程分支删除用例运行 19 s 时到期;当前通过它(18.88 s),在下一用例运行 8 s 时到期。本次对照没有观察到共同场景变慢,仍不宣称全量通过。测量环境、命令、限制与详细数据见 验证说明。两项既有问题按独立 Issue 跟踪。
提交前确认 / Final checks
upstream/main82530d8a0(698e8821b、e0070d6b1);目标为main,未 rebase/force push。.artifacts/、编译产物、凭据或个人路径;截图为隔离合成场景,已检查。上游范围更正:原 #457 错误包含 fork 历史,已关闭。替代 PR vivaui/viva#458 从上游 main 创建,仅 1 个提交、3 个文件(+41/-1),只含 InvalidColor 文案修复和回归测试。fork #60 已关闭;上游 #458 已合并且进入当前固定版本。
彩虹参考线分组调整
将彩虹参考线开关从编辑器显示移入彩虹括号区块,去掉旧的子项缩进;普通缩进参考线保留原处。保留禁用/恢复原选择、共享色板显隐与帮助按钮。中英文分区回归先失败后通过,8 项定向计时结果和同组竞态检查通过;浅色英文/深色中文设置、色板及选色器截图已更新并检查。只移动设置控件,不改编辑器性能路径和 Core 行为。功能矩阵/i18n 检查通过;该先前阶段使用物理 Windows amd64、本地 Core/Viva 覆盖;本轮默认依赖验证见上表,原生 macOS 验收仍未完成。