Repository navigation
feat(editor): 支持插件叠加文本前景色 - #2396
Merged
xiaoyumuxi merged 2 commits intoNov 24, 2026
Merged
Conversation
Collaborator
|
好的好的,我看看能不能改一下给这个染色的对编辑器性能影响降低一下。这个彩虹括号可以内置一下来着,然后支持用配置文件在设置>编辑器里面进行配置就可以啦,没必要做成插件,确实很常用的一个功能 |
Contributor
Author
那我来做彩虹括号的内置,配置入口放在「设置 → 编辑器」。性能这块你有空帮忙看看,现有实现和性能对比都在这个 PR 里。 |
…egment - Shift provider colors on edit, undo, redo and prepared edits instead of clearing them, so rainbow brackets no longer flash while typing; spans an edit cuts or replaces are dropped, a disk reload still clears. - Store spans as absolute uint32 byte offsets plus a palette index (12 bytes instead of 56) and parse each distinct color pair once. - Resolve the paint style once per token or color segment instead of per character, and find each line's colors by binary search. - Cache the provider lookup per document, path, language and color provider change; a keystroke only restarts the pause, and a generation discards overtaken timers and answers. - Add Paint/colors and Type/colors benchmarks with 10,000 rainbow brackets.
Collaborator
okok |
xiaoyumuxi
marked this pull request as ready for review
November 24, 2026 14:55
xiaoyumuxi
requested review from
1lck,
Mucheen and
xiaoyumuxi
as code owners
November 24, 2026 14:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
扩展需要按文档范围提供前景色,并与当前主题、语法着色和 LSP 语义标记共同呈现。Core 已在 Lithe-core-rust#188 提供颜色图例、范围校验与合并规则。
这一层的主要用途是彩虹括号:括号颜色会写进可修改的配置文件,以后也打算内置一个彩虹括号插件。这样的结果通常有上万个范围(Core 上限 10,000),但只循环使用少数几种颜色,而且每次按键都会改变后面所有括号的位置。第二个提交按这个负载优化了数据结构和处理流程。
改动 / Changes
接入(第一个提交
a40743376)editor.colorDecorations。Core 校验注册、图例、文档版本和范围,按稳定顺序合并多个提供者的结果。彩虹括号负载的性能与处理逻辑(第二个提交
d50851155)editorview/color_decorations.go的shiftColors):edit、restore(撤销/重做)和ApplyPreparedEdit(PreparedEdit新增start/end/newEnd,记录rope.Diff的结果)。磁盘重新加载替换整个文本,仍然直接清空。colorDecorationSpan从{line, start, end int; light, dark gfx.Color}(56 字节)改为{start, end, color uint32}(12 字节):绝对字节偏移加颜色表下标。PrepareColorDecorations里只解析一次(palette)。1 万个括号循环 3 种颜色时,只解析 3 次颜色,范围本身约占 120 KB。MaxUint32的文本不显示颜色。paint.go的runLookAt):runLook和它的结束位置;同一片段内的字符直接复用。Paint中按该行的字节范围二分查找(lineColors),所以帧耗时只和可见内容有关。workbench/color_decorations.go):HasColorDecorationsProvider(加锁并遍历提供者)、创建带超时的 context,再启动一个带计时器的后台 goroutine。EditorColorDecorationsChanged会让缓存失效,并立即重新请求。time.AfterFunc停顿,停顿结束后才创建可取消的请求。generation,过期的计时器和答案直接丢弃;答案应用前仍然核对文档版本。Paint/colors和Type/colors:在光标前后放 10,000 个彩虹括号,测绘制和“按键后平移约 5,000 个范围”的耗时。两者都由已有的^BenchmarkEditorViewPaint/、^BenchmarkEditorViewType/预算覆盖,没有修改预算。TestColorDecorationEditKeepsMovedColorsUntilLatestAnswer,覆盖:按键保留已平移的颜色、不重复查询提供者、上一次停顿被停止、过期答案被丢弃、最新答案生效、提供者变化时重新查询并清空。停顿设为一小时,测试只停止计时器、从不等它触发,不依赖真实时间。overtaken场景。2026-10-31-plugin-editor-extension-apis.md)和功能矩阵说明:编辑、撤销、重做时平移颜色,撤回、改名和重新加载时清空。不在本 PR 范围内 / Out of scope
EditorColorDecorationsChanged刷新已打开的文档。宿主不加入任何括号专属逻辑。类型专属(feat)
多平台对齐
pending。范围检查 / Scope checks
功能矩阵 / Feature matrix
plugin-editor-providers的能力、证据与验证动作,说明已改为编辑时平移。较广的语言提供者条目仍为partial,两平台原生验证仍为pending。generate-platform-feature-matrix.mjs --check)与upstream/main HEAD变更检查。插件归属 / Plugin ownership
UI 验证 / UI evidence
TestVisualColorDecorations在a40743376采集并检查 1000 × 640 逻辑尺寸(2000 × 1280 像素)的离屏截图,覆盖中英文和明暗主题。第二个提交在 macOS 上重新运行该用例,输出与此一致(见“验证”)。统一日志系统 / Structured logging
backgroundFailed统一终态,失效和取消保持静默。Windows 沿用现有 v1 路径。界面文案 / i18n
逻辑归属 / Logic placement
性能与内存 / Performance and memory
1ad00fe0e(base)、第一个提交a40743376(PR)和第二个提交(优化)三个测试二进制交替运行^BenchmarkEditorView6 轮,每轮-benchtime 200ms,下表取每项 6 次中的最小值。机器上还有其他工作(1 分钟负载约 4–7),所以采用交替运行,并取最小值来抵消噪声。Type/colors比无颜色的Type/go多约 2.4 µs,就是平移光标之后约 5,000 个范围的开销,远低于 1 ms 的输入预算。换来的是打字时括号颜色不会消失。-benchmem)。Paste 的分配次数在三个版本里都有 ±30 次的波动,6 次最小值相同。Memory场景的 B/op 完全一致。editor-bench.sh report用参考机 CPU 判定 84 项:83 项在预算内,1 项超预算,即Type/longline-wrap的规模比 2.16×(预算 2×)。base 也超出(2.17×),不是本 PR 引入的,本 PR 让它的 10 MiB 耗时下降 27%。未修改预算,也未删除场景。设置 / Settings
N/A,无新增或修改设置。
插件契约 / Plugin contract
1310ee36包含该提交,验证加载此固定修订。editor.function.register与editor.function.unregister方法。宿主没有新增或改变方法契约。发行包与资源 / Bundle and resources
verify-runtime-bundle-immutability.sh,通过。无用代码与重构 / Dead code and refactoring
runLookAt,旧的逐行颜色切片逻辑已删除,没有留下无用代码。验证 / Verification
desktop-go.sh test -race -tags vivahead,lithevisual,选取 Core、editorview、pluginservice、workbench、marketplace 回归1310ee36(第一个提交)go test -race ./internal/editorviewdesktop-go.sh test ./internal/workbench ./internal/pluginservice;颜色相关用例另跑-race1310ee36(第二个提交)-race通过test-stability-macos.sh,覆盖新增和修改的颜色用例TestMoveOpenDocumentInvalidatesColorDecorations)desktop-go.sh test -tags vivahead,lithevisual -run TestVisualColorDecorationseditor-bench.sh run前后对比与editor-bench.sh compare^BenchmarkEditorView6 轮,再运行editor-bench.sh report --basegit diff --check、Agent Notes、功能矩阵、两项 i18n 检查和插件隔离扫描verify-runtime-bundle-immutability.sh未能执行的检查和原因
提交前确认 / Final checks
upstream/main(1ad00fe0e),目标分支为main。