Repository navigation
feat(desktop): 编辑器为 Python、PHP 等 18 种语言提供语法高亮,TextMate 分词器支持 injections - #2115
Merged
Merged
Conversation
- 编辑器内置 Python、Shell、Kotlin、Groovy、CMake、Dockerfile、SQL、PHP、 Ruby、Swift、C#、Lua、PowerShell、Zig、Protobuf、Objective-C/C++、 Makefile、GraphQL 的 TextMate 语法,首次打开对应文件时才解析,来源与许 可证见 syntax/grammars/NOTICE.txt - 分词器按 vscode-textmate 移植 injections:根语法的选择器命中时按 L:/R: 优先级尝试注入规则,并翻译 Oniguruma 的 absent 运算符 (?~X); PHP 由此使用 VS Code 的 text.html.php,HTML 与 <?php ?>/<?= ?> 片段 分别着色 - 新语言的作用域按 Dark+ 归类,并补齐分词金样与语言识别测试 - Core 固定版本升到 885f2a6(Lithe-core-rust#83),插件语法可以声明 injections - 更新功能矩阵;新增 bundled_grammars_visual_test 生成每种语言的无头截图
项目树里 main.zig、order.lua、order.proto、schema.graphql 原来显示问号, CMakeLists.txt 显示文本图标,现在各用自己的语言图标: - GraphQL、Protobuf:JetBrains 的 New UI 图标(intellij-community 与 intellij-plugins,Apache 2.0),带深色版本 - Lua:vscode-icons 绘制的官方 Lua 标志,只把具名颜色写成十六进制 - Zig:ziglang/logo 的官方 zig-mark(CC BY-SA 4.0),放进 16×16 画布 - CMake:vscode-cmake-tools 标志中的 CMake 三角(MIT),去掉扳手 来源、版本与修改写在 fileicons/NOTICE,补 MIT 与 Lua 标志条款原文; CMakeLists.txt 按文件名识别,.zon 归 Zig,.gql 归 GraphQL,与语法匹配 的文件一致。更新功能矩阵。
深色中文与浅色英文两套:18 种语言的编辑器拼图,以及 PHP 文件的整窗截图。 before 取自 origin/main 1ce4085(Core 临时固定 885f2a6),after 取自本分支。
xiaoyumuxi
marked this pull request as ready for review
November 17, 2026 15:12
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
编辑器原来只内置了 Go、Java、Rust、C/C++、JS/TS、JSON、YAML、TOML、Markdown、HTML、XML、CSS、INI、.env、Makefile 的语法。Python、Shell、Kotlin、PHP、SQL 这些常见文件打开后整片没有颜色;Makefile 虽然有语法,变量等作用域没有归类,只有一部分颜色。项目树里
.lua、.zig、.proto、.graphql显示问号图标,CMakeLists.txt显示普通文本图标。PHP 文件是 HTML 里嵌
<?php ?>。VS Code 的 PHP 语法(text.html.php)要靠 TextMate 的 injections 才能把 PHP 片段注入到 HTML 里,而我们的分词器原来不支持 injections,所以只加语法文件不够,分词器也要改。改动 / Changes
1. 18 种语言有语法高亮(
desktop/internal/editor/syntax/)grammars/下。另加 PHP 依赖的text.html.derivative(html-derivative.tmLanguage.json)。$符号等作用域的归类(见第 3 项)。languages.go原来已经登记了这些语言的 ID、扩展名和文件名(CMakeLists.txt、Dockerfile、.gql等),只是没有语法。这次给它们填上语法的根 scope 和着色规则,.zon也归到 Zig。go:embed打进程序,首次打开对应语言的文件时才解析(sync.OnceValue)。没打开过的语言不占解析时间和内存。grammars/NOTICE.txt,每个上游的许可证原文以LICENSE.*.txt放在同一目录:microsoft/vscodee646868227c3e3a9e3f24277c8c7220be42c0be7),各自的上游如下:NOTICE.moby.txt)text.html.derivative、Makefile2. TextMate 分词器支持 injections(
desktop/internal/editor/textmate/)injection.go,按 vscode-textmate 9.3.2 移植:injections的 scope 选择器,支持逗号分隔、-排除和L:/R:优先级。L:的注入规则能胜过当前规则。多条注入规则之间按L:、无前缀、R:排序。tokenizer.go在每次扫描时合并注入规则,grammar.go读取injections字段。regex.go把 Oniguruma 的 absent 运算符(?~X)改写成等价的普通正则,因为 PHP 语法用了它,而 Go 的正则引擎不支持。injectionSelector(一个语法把自己注入到别的语法)不运行,这些都和 vscode-textmate 处理根语法的方式一致。插件语法不能借此注入别的语法。text.html.php:HTML 标签、属性、实体与<?php ?>、<?= ?>片段分别着色,HTML 属性值里的<?= ?>也按 PHP 着色。3. 着色归类与测试
languages.go)。主要新增:$、@前缀,关键字和常量的#、@、:前缀,都归入它们所属的变量、关键字或常量。and、in、as这类单词运算符按关键字着色。ScriptRules只多一条“正则字面量整体按 regexp 着色”,这条规则移进通用的CodeRules,ScriptRules删掉。JS/TS 着色不变,Ruby 等语言的正则也能整体着色。PHPRules:HTML 部分按 HTML 规则着色,meta.embedded里的 PHP 代码按CodeRules着色,<?php、?>按标签符号着色。textmate/testdata/为每种新语言加一份样例和由 vscode-textmate 生成的金样(*.tokens),textmate_test.go逐个比对。另有sample.injection和sample.html专门覆盖 injections。Markdown 语法里的 HTML 块引用text.html.derivative,原来缺这份语法,所以 HTML 块没有作用域。补上后,sample.md.tokens里那一行有了 HTML 作用域。injection_test.go覆盖:injections 字段的解析和非法格式,选择器匹配(含-排除、括号、逗号),L:/R:优先级,begin/end 形式的注入规则,以及被 include 语法的 injections 不生效。textmate_test.go覆盖(?~X)的改写和匹配。language_test.go覆盖新扩展名和文件名的语言识别。4. 文件图标(
desktop/internal/fileicons/)fileicons.go按扩展名和文件名映射,范围和语法识别一致:.zon。.gql。CMakeLists.txt和*.cmake。gray、navy写成十六进制,因为图标编译器只认数字颜色。fileicons/NOTICE,补上 MIT 许可证和 Lua 标志使用条款原文。icons.go、icons_tree.go由scripts/desktop/generate-desktop-file-icons.sh重新生成。5. Core 固定版本
scripts/desktop/build-desktop-core.sh的PINNED_CORE_REVISION从 cf2f260 升到 885f2a6,即 feat(plugin-grammar): 校验 TextMate 语法的 injections Lithe-IDEA/Lithe-core-rust#83 合入后的 main。这个版本的插件语法可以声明 injections,Core 负责校验格式和数量上限。6. 功能矩阵与截图
editor-language-basics、plugin-editor-grammars、project-file-type-icons。desktop/internal/workbench/bundled_grammars_visual_test.go(构建标签vivahead lithevisual,只在设置LITHE_VISUAL_OUTPUT_DIR时运行),生成下面的截图。截图提交在docs/assets/bundled-grammars/。不在本 PR 范围内 / Out of scope
pending。injectionSelector。目前内置语法都用不到,插件语法也不允许注入别的语法。类型专属:feat
多平台对齐
platform-specific),理由:范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/<id>.json:editor-language-basics、plugin-editor-grammars和project-file-type-icons三条。证据路径和验证动作已补,两端验证状态保持pending./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh和./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD.artifacts/下生成的矩阵视图插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空plugin-editor-grammars只补了“插件语法可声明 injections”这一项通用能力shared/i18n/;插件的构建步骤、资源路径和补丁没有写进docs/ci-builds.md、Agent Note 或 SkillUI 验证 / UI evidence
LITHE_VISUAL_OUTPUT_DIR=<目录> ./scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' -run TestVisualBundledGrammars ./internal/workbench18 种语言的编辑器拼图(深色、中文)
改动前:只有 Makefile 有部分颜色,其余整片无高亮。
改动后:
18 种语言的编辑器拼图(浅色、英文)
改动前:
改动后:
PHP 文件整窗(HTML 与 PHP 片段分别着色;左侧项目树能看到新的 CMake、Lua、Zig、Protobuf、GraphQL 图标)
改动前(深色):
改动后(深色):
改动前(浅色):
改动后(浅色):
统一日志系统 / Structured logging
N/A:没有新增生命周期、用户操作终态或失败路径。语法解析失败沿用原有处理。
界面文案 / i18n
N/A:没有新增界面文案。语言名和图标不显示文字,截图里的界面文字都是原有词条。已运行
node scripts/i18n/verify-app-language-localization.mjs和node scripts/i18n/generate-i18n.mjs --check,均通过。逻辑归属 / Logic placement
editor/textmate、editor/syntax),属于编辑器呈现,本 PR 沿用现有位置languages.go的通用表驱动,PHP 用 injections 是语法文件自己声明的性能与内存 / Performance and memory
scripts/desktop/perf/editor-bench.sh,Apple M4,125 项结果,rebase 到 1ce4085 之前测的(1ce4085e7 不涉及编辑器)BenchmarkEditorSyntaxFullPass的 100 KiB 场景,不是本 PR 引入的:matchRuleOrInjections先判断 injections 是否为空,为空就直接返回原来的匹配结果。内置语法里只有 PHP 声明了 injections,Go、Java、Markdown 等原有语言的扫描路径只多这一次判断。设置 / Settings
N/A:不涉及设置。
插件契约 / Plugin contract
injections,Core 的限制如下:scripts/desktop/build-desktop-core.sh的PINNED_CORE_REVISION已升到 885f2a6958a9e475c88c5fb39d48068f41b08ae1sdk-e2e.mjs:只改语法清单的数据格式,没有改插件后端协议发行包与资源 / Bundle and resources
./scripts/desktop/verify/verify-runtime-bundle-immutability.sh,通过无用代码与重构 / Dead code and refactoring
验证 / Verification
make -C desktop check(gofmt、vet、./...全部测试)textmate包:18 种语言及 injection、HTML 的金样比对,injection_test.gosyntax、fileicons包:语言识别、图标映射TestVisualBundledGrammars(vivahead lithevisual),改动前后各跑一次node scripts/i18n/verify-app-language-localization.mjs、node scripts/i18n/generate-i18n.mjs --check./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh、verify-platform-feature-matrix-change.sh origin/main HEAD./scripts/agent-notes/verify-agent-notes.sh./scripts/desktop/verify/verify-runtime-bundle-immutability.sh.agents/skills/write-stable-tests/scripts/verify-test-stability.sh --base origin/maindevelop-lithe第三节插件归属自查命令未能执行的检查和原因:
提交前确认 / Final checks
main创建(rebase 到 origin/main 1ce4085);目标分支为main.build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图