From a9b5b3f3908505eb43cd41ddac29003ac3b9e5f8 Mon Sep 17 00:00:00 2001 From: Mucheen <1528136628@qq.com> Date: Fri, 20 Nov 2026 07:51:49 +0800 Subject: [PATCH 1/4] feat(python): recognize and analyze extensionless scripts --- README.md | 4 +- docs/feature-matrix.md | 5 +- docs/releases/v1.0.0.md | 6 +- .../workbench/python_shebang_e2e_test.go | 74 +++++++++++++++++++ e2e/host/lithe-host.json | 2 +- .../plugin.json | 3 +- scripts/test.mjs | 22 +++++- 7 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go diff --git a/README.md b/README.md index 2c9c265..8fc02d7 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Python language support plugin for Lithe (`schemaVersion: 0`, `pluginAPIVersion: ## 核心能力(Capabilities) 1. **语言与编辑器基础(`languages: python`)** - - 识别 `.py`、`.pyi`、`.pyw`,配置 `#` 行注释与括号/引号自动配对,声明 `pyproject.toml` / `setup.py` / `setup.cfg` / `requirements.txt` / `Pipfile` / `pyrefly.toml` 项目标记及 `.venv` / `venv` / `.conda` 项目依赖目录。 + - 识别 `.py`、`.pyi`、`.pyw`,以及首行指定 Python 解释器的无后缀脚本(需要宿主支持 `languages: 1`),配置 `#` 行注释与括号/引号自动配对,声明 `pyproject.toml` / `setup.py` / `setup.cfg` / `requirements.txt` / `Pipfile` / `pyrefly.toml` 项目标记及 `.venv` / `venv` / `.conda` 项目依赖目录。 2. **后端解析的语言服务器启动与解释器自动注入(`backend` + `languageServers: python` / Pyrefly `1.4.1`)** - 插件包内的 Rust 后端直接启动 Pyrefly,无需先找到 Python。宿主会传入可用于自动启动的解释器路径,缺失时由 Pyrefly 按自身规则发现项目环境。构建、测试与调试仍用宿主选择的 Python。 - 构建期按平台固定版本与 SHA-256 打包 `pyrefly 1.4.1`(Unix:`bin/pyrefly`,Windows:`bin/pyrefly.exe`),每个包也包含同一目标架构的 `bin/lithe-python-backend`(Windows 为 `.exe`)。 @@ -112,7 +112,7 @@ node --test --test-timeout=60000 scripts/package/*.test.mjs cargo test --locked --manifest-path backend/Cargo.toml node scripts/test.mjs -# 使用 e2e/host/lithe-host.json 固定的兼容桌面主线提交 +# 使用 e2e/host/lithe-host.json 固定的兼容桌面提交 node scripts/e2e-host.mjs # 也可使用另一个兼容的本地检出和提交 diff --git a/docs/feature-matrix.md b/docs/feature-matrix.md index 33f6caf..fb4c227 100644 --- a/docs/feature-matrix.md +++ b/docs/feature-matrix.md @@ -13,6 +13,7 @@ | 能力域 | 功能项 | `darwin-arm64` | `darwin-x64` | `windows-x64` / `windows-arm64` | `linux-x64` / `linux-arm64` | 最近实机验证 | 实现与测试证据路径(本仓库) | | --- | --- | --- | --- | --- | --- | --- | --- | | 语言基础 (`languages`) | `.py` / `.pyi` / `.pyw` 识别、`#` 行注释、括号/引号配对、项目标记与 `.venv` / `venv` / `.conda` 依赖目录 | ✅ 已验证 | ⏳ pending(归档与清单已校验) | ⏳ pending(归档与 Windows 清单已校验) | ⏳ pending(归档与清单已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | +| 无后缀 Python 脚本 (`languages: 1`) | 按解释器路径或 `env` shebang 打开,用 Python 高亮、注释与 Pyrefly 编辑 | ✅ 已验证(真实 ZIP 与宿主) | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | 2026-11-20(macOS ARM64) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | | 插件后端与语言服务器启动解析 (`backend` + `languageServers`) | 包内 Rust SDK 后端协商 `litheLogging` 0 与 `litheFunctions` 0。解析 `pyrefly lsp` 启动,传入宿主提供的解释器,缺失时使用 Pyrefly 原生检测。 | ✅ 已验证(桌面主线) | ⏳ 归档已校验 | ⏳ 待 CI 与宿主验收 | ⏳ 待 CI 与宿主验收 | 2026-11-20(macOS ARM64,桌面主线) | `backend/src/pyrefly.rs`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go`
`e2e/host/desktop/internal/workbench/python_editor_debug_e2e_test.go` | | 工具链与环境自动发现 (`toolDefinitions`) | `python` 4 层解析:项目绑定 → `.venv` / `venv` / `.conda`(受工作区信任门控,保留字面软链路径)→ 全局设置 → `VIRTUAL_ENV` + `PATH` → 16 条跨平台自动发现规则(覆盖 `UV_PYTHON_INSTALL_DIR`、`XDG_DATA_HOME`、`PYENV_ROOT`、`CONDA_ENVS_PATH`、`CONDA_PREFIX`、`WORKON_HOME`、`LOCALAPPDATA`、`APPDATA`、Homebrew、Framework、`~/.pyenv`、`~/.local/share/uv`、`*conda*/envs/*`、`miniforge*/envs/*`) | ✅ 已验证 | ⏳ pending(清单与 Core 规则已校验) | ⏳ pending(`Scripts/python.exe` / `python.exe` 布局与环境变量发现规则已通过 Core 校验) | ⏳ pending(清单与 Core 规则已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | | 构建模型与运行 (`buildSystems: python` + `provider`) | `scripts/build_provider.py`(`python -I -B`,`lithe/build/model`)复用 `scripts/build_model.py` 纯 AST + `tomllib` / `vendor/tomli` 静态提取 `[project.scripts]`、包 `__main__.py`、顶层 `__main__` 脚本、Django `manage.py`、FastAPI ASGI、Flask WSGI 并派生 7 类声明式 `run` 配置;支持损坏 `pyproject.toml` 降级与修复后恢复诊断,并在协商 `litheBuild` 1 时支持 `lithe/build/runEntrypoints` | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/scripts/build_model.py`
`io.github.lithe-idea.python-support/scripts/build_provider.py`
`io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | @@ -26,8 +27,8 @@ ## 宿主版本与验证 -- 插件要求宿主声明 `toolchainProviders: 0` 和 `buildSystems: 1`。桌面稳定版 `desktop-v0.8.8` 缺少这组能力。 -- `e2e/host/lithe-host.json` 固定桌面主线 `761e6f882848d754515ca16c5a78431d85d3b154`(#2192、#2193),其 Core 为 `6a2c0826`。 +- 插件要求宿主声明 `toolchainProviders: 0`、`buildSystems: 1` 和 `languages: 1`。桌面稳定版 `desktop-v0.8.8` 缺少这组能力。 +- 现有 M3 在兼容桌面主线 `761e6f882`(#2192、#2193)独立验过。加入无后缀识别后,`e2e/host/lithe-host.json` 指向包含 Core 首行契约的桌面候选 `3630758b9`。 - macOS ARM64 的工作台测试从 ZIP 安装插件,改变项目版本要求以切换外部解释器,检查全局候选和项目 `.venv` 信任,精确重跑一个参数化 pytest 用例并核对 JUnit。 - 无头工作台打开 `.py` 后,Pyrefly 返回所选环境独有模块的类型诊断。debugpy 使用同一环境执行当前文件,并将日志写入宿主分配目录。关闭后,已安装插件的文件清单和 SHA-256 与启动前一致。 - 宿主按 Core 的文件事实校验安装。外部虚拟环境里指向环境外的 Python 链接不可作为提供者候选,项目内环境由宿主信任流程单独处理。 diff --git a/docs/releases/v1.0.0.md b/docs/releases/v1.0.0.md index 86e76aa..470b044 100644 --- a/docs/releases/v1.0.0.md +++ b/docs/releases/v1.0.0.md @@ -1,21 +1,23 @@ ## 中文 +- 无后缀 Python 脚本按 shebang 打开后,可以使用 Python 高亮、注释和 Pyrefly 诊断。 - Toolchains 可从 Conda 环境登记表、uv 自定义安装目录和其他受支持的环境位置发现 Python。项目的 `.python-version` 和 `requires-python` 参与解释器选择。 - Pyrefly 与宿主选定的解释器保持一致。插件包内的后端可以在尚未安装 Python 时启动 Pyrefly。 - Build 面板可用 pytest 收集测试,按已发现的套件和用例精确运行。运行 pytest 和 debugpy 仍需要可用的项目解释器。 ### 升级与兼容性 -升级需要支持 `toolchainProviders` 0 和 `buildSystems` 1 的 Lithe 桌面版。确认桌面已支持这两项能力后,再安装对应操作系统和架构的插件 ZIP。使用较早桌面版本时,可继续使用 Python Support v0.1.1。 +升级需要支持 `toolchainProviders` 0、`buildSystems` 1 和 `languages` 1 的 Lithe 桌面版。确认桌面已支持这些能力后,再安装对应操作系统和架构的插件 ZIP。使用较早桌面版本时,可继续使用 Python Support v0.1.1。 --- ## English +- Open extensionless Python scripts with a shebang to get Python highlighting, comments, and Pyrefly diagnostics. - Toolchains can find Python from the Conda environment registry, a custom uv installation directory, and other supported environment locations. The project's `.python-version` and `requires-python` help select an interpreter. - Pyrefly uses the interpreter selected in Lithe. The bundled backend can start Pyrefly before Python is installed. - The Build panel can collect tests with pytest and run an exact discovered suite or case. Running pytest and debugpy still requires an available project interpreter. ### Upgrade and compatibility -This upgrade requires a Lithe desktop version that supports `toolchainProviders` 0 and `buildSystems` 1. Once your desktop version supports both capabilities, install the plugin ZIP for your operating system and architecture. Python Support v0.1.1 remains available for earlier versions of Lithe. +This upgrade requires a Lithe desktop version that supports `toolchainProviders` 0, `buildSystems` 1, and `languages` 1. Once your desktop version supports these capabilities, install the plugin ZIP for your operating system and architecture. Python Support v0.1.1 remains available for earlier versions of Lithe. diff --git a/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go b/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go new file mode 100644 index 0000000..1ca7690 --- /dev/null +++ b/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go @@ -0,0 +1,74 @@ +package workbench + +import ( + "context" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" + "github.com/vivaui/viva/app" +) + +func TestPythonSupportPluginShebang(t *testing.T) { + archive := pythonArchiveForE2E(t) + ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second) + defer cancel() + kernel := core.NewClient() + preferences := store.At(t.TempDir()) + service, err := pluginservice.Open(kernel, preferences, t.TempDir()) + if err != nil { + t.Fatal(err) + } + installPythonArchive(t, ctx, service, archive) + if err := os.WriteFile(filepath.Join(preferences.Dir(), settingsFile), []byte(`{"theme":"dark"}`), 0o600); err != nil { + t.Fatal(err) + } + h := newHarnessWithOptions(t, Options{ + Kernel: kernel, PluginKernel: kernel, PluginRoot: service.Root, Store: preferences, Languages: []string{"en"}, + Logs: &pluginFilesLog{directory: t.TempDir()}, LogKernel: kernel, + }) + h.app.reloadPluginLanguages() + h.settle() + root := t.TempDir() + h.open(root) + p := h.app.project + path := filepath.Join(p.root, "script") + const body = "#!/usr/bin/env -S python3 -I\ncount: int = 42\n" + if err := os.WriteFile(path, []byte(body), 0o600); err != nil { + t.Fatal(err) + } + h.app.openFile(p, path) + h.settle() + doc := p.docs.byPath(path) + if doc == nil || doc.languageID != "python" { + t.Fatal("extensionless script did not open as Python") + } + if len(doc.view.SyntaxLine(nil, 1)) == 0 { + t.Fatal("extensionless script has no Python syntax tokens") + } + awaitStateWithin(t, h, 15*time.Second, "Pyrefly to open the extensionless document", func() bool { + if failure := h.app.pluginServerFailed["python"]; failure != nil { + t.Fatalf("Pyrefly start: %s", failure.message) + } + return doc.sync.opened + }) + if !doc.view.GoToNavigation(1, 13, false) { + t.Fatal("could not place the caret before the integer literal") + } + input := doc.view.TextInput(app.TextInputContext{ID: doc.hit}) + if _, err := input.OnEvent(app.TextEvent{Kind: app.TextInsert, Text: `"bad" # `}); err != nil { + t.Fatal(err) + } + if !strings.Contains(doc.view.TextSnapshot().String(), `count: int = "bad" # 42`) { + t.Fatal("extensionless script edit was not applied") + } + awaitStateWithin(t, h, 15*time.Second, "Pyrefly to diagnose the edited extensionless script", func() bool { + return diagnosticsForFile(h.app, path) > 0 && + problemMessagesContain(h.app, "int") && problemMessagesContain(h.app, "bad") + }) +} diff --git a/e2e/host/lithe-host.json b/e2e/host/lithe-host.json index f5317a6..678f216 100644 --- a/e2e/host/lithe-host.json +++ b/e2e/host/lithe-host.json @@ -1,6 +1,6 @@ { "repository": "https://github.com/1lck/Lithe-IDEA.git", - "revision": "761e6f882848d754515ca16c5a78431d85d3b154", + "revision": "3630758b9a446ee36bd36fc5dd2acd3eb78928c3", "packages": { "./internal/projectgen": "^TestPythonPlugin", "./internal/workbench": "^TestPythonSupportPlugin" diff --git a/io.github.lithe-idea.python-support/plugin.json b/io.github.lithe-idea.python-support/plugin.json index 535f78e..097f21d 100644 --- a/io.github.lithe-idea.python-support/plugin.json +++ b/io.github.lithe-idea.python-support/plugin.json @@ -16,7 +16,7 @@ "buildSystems": 1, "debugAdapters": 0, "languageServers": 0, - "languages": 0, + "languages": 1, "outputLinkMatchers": 0, "projectGenerators": 0, "settings": 0, @@ -52,6 +52,7 @@ "id": "python", "displayName": "Python", "fileExtensions": ["py", "pyi", "pyw"], + "firstLineMatch": "^#![ \\t]*(?:/(?:[^ \\t]*/)?env[ \\t]+(?:-S[ \\t]+)?|/(?:[^ \\t]*/)?)(?:python(?:[0-9]+(?:\\.[0-9]+)*t?)?|pypy[0-9]*)(?:[ \\t]|$)", "projectFileNames": [ "pyproject.toml", "setup.py", diff --git a/scripts/test.mjs b/scripts/test.mjs index eeec627..4d9b7ba 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -345,7 +345,7 @@ try { "toolchainProviders", ]); for (const [capability, version] of Object.entries(variant.requires)) { - assert.equal(version, capability === "buildSystems" ? 1 : 0); + assert.equal(version, ["buildSystems", "languages"].includes(capability) ? 1 : 0); } assert.deepEqual([...variant.permissions].sort(), [ "backend.launch", @@ -362,7 +362,25 @@ try { }); const pyLang = variant.languages[0]; - assert.equal("shebang" in pyLang, false); + const firstLine = new RegExp(pyLang.firstLineMatch); + for (const line of [ + "#!/usr/bin/python", + "#!/usr/bin/env python3", + "#!/usr/bin/env -S python3.13 -I", + "#!/opt/venv/bin/python3.13t", + "#!/usr/bin/env pypy3", + ]) { + assert.match(line, firstLine); + } + for (const line of [ + "#!/usr/bin/env bash", + "#!/usr/bin/env python-wrapper", + "#!/usr/bin/python3.13.exe", + "#!/usr/bin/env node python3", + "# Mention #!/usr/bin/env python3", + ]) { + assert.doesNotMatch(line, firstLine); + } assert.deepEqual(pyLang.fileExtensions, ["py", "pyi", "pyw"]); assert.deepEqual(pyLang.dependencies.projectDependencyPaths, [".venv", "venv", ".conda"]); From b90696eacd93ca141166fd7c4e00654342feb040 Mon Sep 17 00:00:00 2001 From: Mucheen <1528136628@qq.com> Date: Fri, 20 Nov 2026 09:07:08 +0800 Subject: [PATCH 2/4] fix(python): place shebang matching in packaged grammar --- README.md | 7 +- docs/feature-matrix.md | 8 +-- docs/releases/v1.0.0.md | 8 +-- .../workbench/python_shebang_e2e_test.go | 67 ++++++++++++++++++- e2e/host/lithe-host.json | 2 +- .../grammars/python.tmLanguage.json | 9 +++ .../plugin.json | 7 +- scripts/package/archives.test.mjs | 9 +++ scripts/test.mjs | 44 ++++++------ 9 files changed, 126 insertions(+), 35 deletions(-) create mode 100644 io.github.lithe-idea.python-support/grammars/python.tmLanguage.json diff --git a/README.md b/README.md index 8fc02d7..27f107a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ Python language support plugin for Lithe (`schemaVersion: 0`, `pluginAPIVersion: ## 核心能力(Capabilities) 1. **语言与编辑器基础(`languages: python`)** - - 识别 `.py`、`.pyi`、`.pyw`,以及首行指定 Python 解释器的无后缀脚本(需要宿主支持 `languages: 1`),配置 `#` 行注释与括号/引号自动配对,声明 `pyproject.toml` / `setup.py` / `setup.cfg` / `requirements.txt` / `Pipfile` / `pyrefly.toml` 项目标记及 `.venv` / `venv` / `.conda` 项目依赖目录。 + - 识别 `.py`、`.pyi`、`.pyw`,配置 `#` 行注释与括号/引号自动配对,声明 `pyproject.toml` / `setup.py` / `setup.cfg` / `requirements.txt` / `Pipfile` / `pyrefly.toml` 项目标记及 `.venv` / `venv` / `.conda` 项目依赖目录。 + - Lithe 0.8.9 可以安装此插件。支持 TextMate 首行匹配的桌面版本还会按 shebang 识别无后缀脚本,提供 Python 高亮和 Pyrefly 诊断。 2. **后端解析的语言服务器启动与解释器自动注入(`backend` + `languageServers: python` / Pyrefly `1.4.1`)** - 插件包内的 Rust 后端直接启动 Pyrefly,无需先找到 Python。宿主会传入可用于自动启动的解释器路径,缺失时由 Pyrefly 按自身规则发现项目环境。构建、测试与调试仍用宿主选择的 Python。 - 构建期按平台固定版本与 SHA-256 打包 `pyrefly 1.4.1`(Unix:`bin/pyrefly`,Windows:`bin/pyrefly.exe`),每个包也包含同一目标架构的 `bin/lithe-python-backend`(Windows 为 `.exe`)。 @@ -90,6 +91,7 @@ Rust SDK 和构建提供者的 `scripts/lithe_rpc.py` 通过 stdio JSON-RPC 2.0 | `backend/target/` | Rust 后端编译输出,包含按平台目标区分的产物 | 随工作树保留,可重新由 Cargo 生成 | 不共享,构建时由固定的 Cargo.lock 和 Rust 目标重建。Cargo 使用全局 registry 与 Git 依赖下载缓存。 | | `.artifacts/stage/` | 打包过程中的单平台解包暂存目录 | 每次 `scripts/package.mjs` 按平台重建(`.gitignore` 忽略) | **不可复用**(构建中间产物,毫秒级重建) | | `.artifacts/lithe-host/` | `scripts/e2e-host.mjs` 检出的宿主稀疏工作树及其编译产物 | 本地按需保留(`.gitignore` 忽略) | 其内部 `.artifacts/desktop` 在同一操作系统、CPU 架构与相同 `PINNED_CORE_REVISION` 前提下可按宿主规则复制加速,不得跨工作树软链共用;任何运行时会话日志目录(`sessions//plugins/.../files/`)与状态目录严禁跨工作树复制 | +| `grammars/python.tmLanguage.json`(插件包内) | 插件版本拥有的 TextMate 首行规则,复用宿主内置的 `source.python` 高亮规则 | 构建时随 ZIP 打包,运行时只读,随插件版本更新或卸载 | 由插件源码随包生成,无运行时缓存 | | `dist/` | 最终产出的 `python-support--.zip` 发布包 | 打包输出(`.gitignore` 忽略) | 按需重新运行 `node scripts/package.mjs` 生成 | ### 常用命令 @@ -115,6 +117,9 @@ node scripts/test.mjs # 使用 e2e/host/lithe-host.json 固定的兼容桌面提交 node scripts/e2e-host.mjs +# 用同一个 ZIP 检查 0.8.9 能安装插件并正常高亮 .py +node scripts/e2e-host.mjs --source https://github.com/1lck/Lithe-IDEA.git --ref desktop-v0.8.9 --run '^TestPythonSupportPluginGrammarHighlighting$' + # 也可使用另一个兼容的本地检出和提交 node scripts/e2e-host.mjs --source /path/to/Lithe-IDEA --ref COMPATIBLE_HOST_COMMIT ``` diff --git a/docs/feature-matrix.md b/docs/feature-matrix.md index fb4c227..6cb4ea4 100644 --- a/docs/feature-matrix.md +++ b/docs/feature-matrix.md @@ -12,8 +12,8 @@ | 能力域 | 功能项 | `darwin-arm64` | `darwin-x64` | `windows-x64` / `windows-arm64` | `linux-x64` / `linux-arm64` | 最近实机验证 | 实现与测试证据路径(本仓库) | | --- | --- | --- | --- | --- | --- | --- | --- | -| 语言基础 (`languages`) | `.py` / `.pyi` / `.pyw` 识别、`#` 行注释、括号/引号配对、项目标记与 `.venv` / `venv` / `.conda` 依赖目录 | ✅ 已验证 | ⏳ pending(归档与清单已校验) | ⏳ pending(归档与 Windows 清单已校验) | ⏳ pending(归档与清单已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | -| 无后缀 Python 脚本 (`languages: 1`) | 按解释器路径或 `env` shebang 打开,用 Python 高亮、注释与 Pyrefly 编辑 | ✅ 已验证(真实 ZIP 与宿主) | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | 2026-11-20(macOS ARM64) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | +| 语言基础 (`languages`) | `.py` / `.pyi` / `.pyw` 识别、`#` 行注释、括号/引号配对、项目标记与 `.venv` / `venv` / `.conda` 依赖目录 | ✅ 已验证 | ⏳ pending(归档与清单已校验) | ⏳ pending(归档与 Windows 清单已校验) | ⏳ pending(归档与清单已校验) | `2026-11-20`(`darwin-arm64`,0.8.9 复验 `.py` 高亮) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | +| 无后缀 Python 脚本 | 支持 TextMate 首行匹配的桌面按解释器路径或 `env` shebang 打开,提供 Python 高亮、注释与 Pyrefly 诊断 | ✅ 已验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | `2026-11-20`(`darwin-arm64`,桌面 `79b97fa64`) | `io.github.lithe-idea.python-support/grammars/python.tmLanguage.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | | 插件后端与语言服务器启动解析 (`backend` + `languageServers`) | 包内 Rust SDK 后端协商 `litheLogging` 0 与 `litheFunctions` 0。解析 `pyrefly lsp` 启动,传入宿主提供的解释器,缺失时使用 Pyrefly 原生检测。 | ✅ 已验证(桌面主线) | ⏳ 归档已校验 | ⏳ 待 CI 与宿主验收 | ⏳ 待 CI 与宿主验收 | 2026-11-20(macOS ARM64,桌面主线) | `backend/src/pyrefly.rs`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go`
`e2e/host/desktop/internal/workbench/python_editor_debug_e2e_test.go` | | 工具链与环境自动发现 (`toolDefinitions`) | `python` 4 层解析:项目绑定 → `.venv` / `venv` / `.conda`(受工作区信任门控,保留字面软链路径)→ 全局设置 → `VIRTUAL_ENV` + `PATH` → 16 条跨平台自动发现规则(覆盖 `UV_PYTHON_INSTALL_DIR`、`XDG_DATA_HOME`、`PYENV_ROOT`、`CONDA_ENVS_PATH`、`CONDA_PREFIX`、`WORKON_HOME`、`LOCALAPPDATA`、`APPDATA`、Homebrew、Framework、`~/.pyenv`、`~/.local/share/uv`、`*conda*/envs/*`、`miniforge*/envs/*`) | ✅ 已验证 | ⏳ pending(清单与 Core 规则已校验) | ⏳ pending(`Scripts/python.exe` / `python.exe` 布局与环境变量发现规则已通过 Core 校验) | ⏳ pending(清单与 Core 规则已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | | 构建模型与运行 (`buildSystems: python` + `provider`) | `scripts/build_provider.py`(`python -I -B`,`lithe/build/model`)复用 `scripts/build_model.py` 纯 AST + `tomllib` / `vendor/tomli` 静态提取 `[project.scripts]`、包 `__main__.py`、顶层 `__main__` 脚本、Django `manage.py`、FastAPI ASGI、Flask WSGI 并派生 7 类声明式 `run` 配置;支持损坏 `pyproject.toml` 降级与修复后恢复诊断,并在协商 `litheBuild` 1 时支持 `lithe/build/runEntrypoints` | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/scripts/build_model.py`
`io.github.lithe-idea.python-support/scripts/build_provider.py`
`io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | @@ -27,8 +27,8 @@ ## 宿主版本与验证 -- 插件要求宿主声明 `toolchainProviders: 0`、`buildSystems: 1` 和 `languages: 1`。桌面稳定版 `desktop-v0.8.8` 缺少这组能力。 -- 现有 M3 在兼容桌面主线 `761e6f882`(#2192、#2193)独立验过。加入无后缀识别后,`e2e/host/lithe-host.json` 指向包含 Core 首行契约的桌面候选 `3630758b9`。 +- 插件要求宿主声明 `toolchainProviders: 0`、`buildSystems: 1` 和 `languages: 0`。桌面 0.8.9 支持安装与原有 Python 功能。支持 TextMate 首行匹配的桌面会额外识别无后缀脚本。 +- 现有 M3 在兼容桌面主线 `761e6f882`(#2192、#2193)独立验过。`e2e/host/lithe-host.json` 固定支持 TextMate 首行匹配的桌面候选版本。 - macOS ARM64 的工作台测试从 ZIP 安装插件,改变项目版本要求以切换外部解释器,检查全局候选和项目 `.venv` 信任,精确重跑一个参数化 pytest 用例并核对 JUnit。 - 无头工作台打开 `.py` 后,Pyrefly 返回所选环境独有模块的类型诊断。debugpy 使用同一环境执行当前文件,并将日志写入宿主分配目录。关闭后,已安装插件的文件清单和 SHA-256 与启动前一致。 - 宿主按 Core 的文件事实校验安装。外部虚拟环境里指向环境外的 Python 链接不可作为提供者候选,项目内环境由宿主信任流程单独处理。 diff --git a/docs/releases/v1.0.0.md b/docs/releases/v1.0.0.md index 470b044..70672be 100644 --- a/docs/releases/v1.0.0.md +++ b/docs/releases/v1.0.0.md @@ -1,23 +1,23 @@ ## 中文 -- 无后缀 Python 脚本按 shebang 打开后,可以使用 Python 高亮、注释和 Pyrefly 诊断。 +- 支持 TextMate 首行匹配的 Lithe 可按 shebang 识别无后缀 Python 脚本,提供高亮、注释和 Pyrefly 诊断。 - Toolchains 可从 Conda 环境登记表、uv 自定义安装目录和其他受支持的环境位置发现 Python。项目的 `.python-version` 和 `requires-python` 参与解释器选择。 - Pyrefly 与宿主选定的解释器保持一致。插件包内的后端可以在尚未安装 Python 时启动 Pyrefly。 - Build 面板可用 pytest 收集测试,按已发现的套件和用例精确运行。运行 pytest 和 debugpy 仍需要可用的项目解释器。 ### 升级与兼容性 -升级需要支持 `toolchainProviders` 0、`buildSystems` 1 和 `languages` 1 的 Lithe 桌面版。确认桌面已支持这些能力后,再安装对应操作系统和架构的插件 ZIP。使用较早桌面版本时,可继续使用 Python Support v0.1.1。 +Lithe 0.8.9 支持安装此插件并使用普通 Python 文件功能。无后缀脚本的自动识别需要支持 TextMate 首行匹配的桌面版本。请选择对应操作系统和架构的 ZIP。使用较早桌面版本时,可继续使用 Python Support v0.1.1。 --- ## English -- Open extensionless Python scripts with a shebang to get Python highlighting, comments, and Pyrefly diagnostics. +- On Lithe versions that support TextMate first-line matching, open extensionless Python scripts with a shebang to get highlighting, comment commands, and Pyrefly diagnostics. - Toolchains can find Python from the Conda environment registry, a custom uv installation directory, and other supported environment locations. The project's `.python-version` and `requires-python` help select an interpreter. - Pyrefly uses the interpreter selected in Lithe. The bundled backend can start Pyrefly before Python is installed. - The Build panel can collect tests with pytest and run an exact discovered suite or case. Running pytest and debugpy still requires an available project interpreter. ### Upgrade and compatibility -This upgrade requires a Lithe desktop version that supports `toolchainProviders` 0, `buildSystems` 1, and `languages` 1. Once your desktop version supports these capabilities, install the plugin ZIP for your operating system and architecture. Python Support v0.1.1 remains available for earlier versions of Lithe. +Lithe 0.8.9 can install this plugin and use its standard Python support. Automatic recognition of extensionless scripts requires a desktop version with TextMate first-line matching. Choose the ZIP for your operating system and architecture. Python Support v0.1.1 remains available for earlier versions of Lithe. diff --git a/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go b/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go index 1ca7690..19ab1d2 100644 --- a/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go +++ b/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go @@ -9,12 +9,15 @@ import ( "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/editor/rope" + "github.com/1lck/Lithe-IDEA/desktop/internal/editor/syntax" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" "github.com/1lck/Lithe-IDEA/desktop/internal/store" "github.com/vivaui/viva/app" ) -func TestPythonSupportPluginShebang(t *testing.T) { +func openPythonGrammarWorkbench(t *testing.T) *harness { + t.Helper() archive := pythonArchiveForE2E(t) ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second) defer cancel() @@ -34,8 +37,66 @@ func TestPythonSupportPluginShebang(t *testing.T) { }) h.app.reloadPluginLanguages() h.settle() - root := t.TempDir() - h.open(root) + h.open(t.TempDir()) + return h +} + +func TestPythonSupportPluginGrammarHighlighting(t *testing.T) { + h := openPythonGrammarWorkbench(t) + p := h.app.project + path := filepath.Join(p.root, "sample.py") + const body = `class Counter: + def greet(self, name: str): + count = 42 + 1 + if count >= 1 and name: + return f"Hi {name.upper()}, {count + 1}" # hello + return None +` + if err := os.WriteFile(path, []byte(body), 0o600); err != nil { + t.Fatal(err) + } + grammar := h.app.syntaxRegistry().SyntaxForPath(path) + if grammar == nil || grammar.Language().Scope != "source.python.lithe-support" { + t.Fatal("installed Python grammar was not loaded") + } + h.app.openFile(p, path) + h.settle() + doc := p.docs.byPath(path) + if doc == nil || doc.languageID != "python" { + t.Fatal("sample.py did not open as Python") + } + + bundled := syntax.NewRegistry().SyntaxForPath(path) + highlighter := syntax.NewHighlighter(bundled, rope.New([]byte(body)), syntax.HighlighterOptions{}) + t.Cleanup(highlighter.Close) + for lineIndex, line := range strings.Split(body, "\n") { + want := highlighter.Line(nil, lineIndex) + got := doc.view.SyntaxLine(nil, lineIndex) + if len(got) != len(want) { + t.Fatalf("line %d %q highlights = %v, bundled Python = %v", lineIndex+1, line, got, want) + } + for i, token := range got { + if token == want[i] { + continue + } + end := len(line) + if i+1 < len(want) { + end = int(want[i+1].Start) + } + // Both registries tokenize operators through the bundled grammar. The + // plugin root uses the generic classifier, styling those symbols as keywords. + if token.Start == want[i].Start && token.Name.String() == "keyword" && + want[i].Name.String() == "delimiter" && + strings.Trim(line[token.Start:end], "=+<>") == "" { + continue + } + t.Errorf("line %d %q token = %v, bundled Python = %v", lineIndex+1, line, token, want[i]) + } + } +} + +func TestPythonSupportPluginShebang(t *testing.T) { + h := openPythonGrammarWorkbench(t) p := h.app.project path := filepath.Join(p.root, "script") const body = "#!/usr/bin/env -S python3 -I\ncount: int = 42\n" diff --git a/e2e/host/lithe-host.json b/e2e/host/lithe-host.json index 678f216..3a928d6 100644 --- a/e2e/host/lithe-host.json +++ b/e2e/host/lithe-host.json @@ -1,6 +1,6 @@ { "repository": "https://github.com/1lck/Lithe-IDEA.git", - "revision": "3630758b9a446ee36bd36fc5dd2acd3eb78928c3", + "revision": "79b97fa6428df3c28d2c338c56cfdf4153c14008", "packages": { "./internal/projectgen": "^TestPythonPlugin", "./internal/workbench": "^TestPythonSupportPlugin" diff --git a/io.github.lithe-idea.python-support/grammars/python.tmLanguage.json b/io.github.lithe-idea.python-support/grammars/python.tmLanguage.json new file mode 100644 index 0000000..6d14b71 --- /dev/null +++ b/io.github.lithe-idea.python-support/grammars/python.tmLanguage.json @@ -0,0 +1,9 @@ +{ + "scopeName": "source.python.lithe-support", + "firstLineMatch": "^#![ \\t]*(?:/(?:[^ \\t]*/)?env[ \\t]+(?:-S[ \\t]+)?|/(?:[^ \\t]*/)?)(?:python(?:[0-9]+(?:\\.[0-9]+)*t?)?|pypy[0-9]*)(?:[ \\t]|$)", + "patterns": [ + { + "include": "source.python" + } + ] +} diff --git a/io.github.lithe-idea.python-support/plugin.json b/io.github.lithe-idea.python-support/plugin.json index 097f21d..72c632a 100644 --- a/io.github.lithe-idea.python-support/plugin.json +++ b/io.github.lithe-idea.python-support/plugin.json @@ -16,7 +16,7 @@ "buildSystems": 1, "debugAdapters": 0, "languageServers": 0, - "languages": 1, + "languages": 0, "outputLinkMatchers": 0, "projectGenerators": 0, "settings": 0, @@ -52,7 +52,10 @@ "id": "python", "displayName": "Python", "fileExtensions": ["py", "pyi", "pyw"], - "firstLineMatch": "^#![ \\t]*(?:/(?:[^ \\t]*/)?env[ \\t]+(?:-S[ \\t]+)?|/(?:[^ \\t]*/)?)(?:python(?:[0-9]+(?:\\.[0-9]+)*t?)?|pypy[0-9]*)(?:[ \\t]|$)", + "grammar": { + "kind": "textmate", + "path": "grammars/python.tmLanguage.json" + }, "projectFileNames": [ "pyproject.toml", "setup.py", diff --git a/scripts/package/archives.test.mjs b/scripts/package/archives.test.mjs index 27a3380..473af31 100644 --- a/scripts/package/archives.test.mjs +++ b/scripts/package/archives.test.mjs @@ -121,6 +121,15 @@ test("every built archive has safe paths, no bytecode or symlinks, and valid pla assert.deepEqual(manifest.requires, baseManifest.requires); assert.deepEqual(manifest.vendor, baseManifest.vendor); + assert.equal(manifest.requires.languages, 0); + const pythonLanguage = manifest.languages.find(({ id }) => id === "python"); + assert.deepEqual(pythonLanguage.grammar, { kind: "textmate", path: "grammars/python.tmLanguage.json" }); + assert.equal("firstLineMatch" in pythonLanguage, false); + const grammarPath = `${PACKAGE_ID}/${pythonLanguage.grammar.path}`; + const grammarEntry = entries.find(({ name }) => name === grammarPath); + assert.ok(grammarEntry, `${archive.name}: missing declared grammar ${grammarPath}`); + assert.deepEqual(grammarEntry.data, readFileSync(grammarPath)); + assert.deepEqual(manifest.backend, { launch: { kind: "packaged", path: backendPath(archive.platform) } }); assert.deepEqual(manifest.toolchainProviders, baseManifest.toolchainProviders); assert.equal(manifest.requires.toolchainProviders, 0); diff --git a/scripts/test.mjs b/scripts/test.mjs index 4d9b7ba..f63e9cb 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -310,6 +310,27 @@ try { const pluginManifest = JSON.parse(readFileSync(join(unpackedPluginDir, "plugin.json"), "utf8")); await check("Unix and Windows plugin.json + zh-Hans.json satisfy M3 contract invariants", () => { + const grammar = JSON.parse(readFileSync(join(unpackedPluginDir, "grammars", "python.tmLanguage.json"), "utf8")); + assert.deepEqual(grammar.patterns, [{ include: "source.python" }]); + const firstLine = new RegExp(grammar.firstLineMatch); + for (const line of [ + "#!/usr/bin/python", + "#!/usr/bin/env python3", + "#!/usr/bin/env -S python3.13 -I", + "#!/opt/venv/bin/python3.13t", + "#!/usr/bin/env pypy3", + ]) { + assert.match(line, firstLine); + } + for (const line of [ + "#!/usr/bin/env bash", + "#!/usr/bin/env python-wrapper", + "#!/usr/bin/python3.13.exe", + "#!/usr/bin/env node python3", + "# Mention #!/usr/bin/env python3", + ]) { + assert.doesNotMatch(line, firstLine); + } for (const platform of Object.keys(lock.pyrefly.platforms)) { const variant = manifestForPlatform(sourceManifest, platform, lock); assert.equal(variant.schemaVersion, 0); @@ -345,7 +366,7 @@ try { "toolchainProviders", ]); for (const [capability, version] of Object.entries(variant.requires)) { - assert.equal(version, ["buildSystems", "languages"].includes(capability) ? 1 : 0); + assert.equal(version, capability === "buildSystems" ? 1 : 0); } assert.deepEqual([...variant.permissions].sort(), [ "backend.launch", @@ -362,25 +383,8 @@ try { }); const pyLang = variant.languages[0]; - const firstLine = new RegExp(pyLang.firstLineMatch); - for (const line of [ - "#!/usr/bin/python", - "#!/usr/bin/env python3", - "#!/usr/bin/env -S python3.13 -I", - "#!/opt/venv/bin/python3.13t", - "#!/usr/bin/env pypy3", - ]) { - assert.match(line, firstLine); - } - for (const line of [ - "#!/usr/bin/env bash", - "#!/usr/bin/env python-wrapper", - "#!/usr/bin/python3.13.exe", - "#!/usr/bin/env node python3", - "# Mention #!/usr/bin/env python3", - ]) { - assert.doesNotMatch(line, firstLine); - } + assert.deepEqual(pyLang.grammar, { kind: "textmate", path: "grammars/python.tmLanguage.json" }); + assert.equal("firstLineMatch" in pyLang, false); assert.deepEqual(pyLang.fileExtensions, ["py", "pyi", "pyw"]); assert.deepEqual(pyLang.dependencies.projectDependencyPaths, [".venv", "venv", ".conda"]); From 7521dfa7e1e34991fc764f20c7c2f04e9d1faf40 Mon Sep 17 00:00:00 2001 From: Mucheen <1528136628@qq.com> Date: Fri, 20 Nov 2026 09:14:01 +0800 Subject: [PATCH 3/4] fix(test): compare packaged grammar across checkout line endings --- scripts/package/archives.test.mjs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/package/archives.test.mjs b/scripts/package/archives.test.mjs index 473af31..920bd6d 100644 --- a/scripts/package/archives.test.mjs +++ b/scripts/package/archives.test.mjs @@ -128,7 +128,12 @@ test("every built archive has safe paths, no bytecode or symlinks, and valid pla const grammarPath = `${PACKAGE_ID}/${pythonLanguage.grammar.path}`; const grammarEntry = entries.find(({ name }) => name === grammarPath); assert.ok(grammarEntry, `${archive.name}: missing declared grammar ${grammarPath}`); - assert.deepEqual(grammarEntry.data, readFileSync(grammarPath)); + // Packaged JSON can have CRLF when a Windows runner assembles the ZIP. + assert.deepEqual( + JSON.parse(grammarEntry.data.toString("utf8")), + JSON.parse(readFileSync(grammarPath, "utf8")), + `${archive.name}: packaged grammar differs from ${grammarPath}`, + ); assert.deepEqual(manifest.backend, { launch: { kind: "packaged", path: backendPath(archive.platform) } }); assert.deepEqual(manifest.toolchainProviders, baseManifest.toolchainProviders); From fbc4e270b914b182e9da2e9daf33fffb6e5b73a1 Mon Sep 17 00:00:00 2001 From: Mucheen <1528136628@qq.com> Date: Fri, 20 Nov 2026 10:30:03 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix(python):=20=E4=BF=9D=E7=95=99=E5=86=85?= =?UTF-8?q?=E7=BD=AE=E9=AB=98=E4=BA=AE=E5=B9=B6=E8=A6=86=E7=9B=96=20sheban?= =?UTF-8?q?g=20=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 26 +++++++++++++++++++ README.md | 2 +- docs/feature-matrix.md | 3 ++- .../workbench/python_shebang_e2e_test.go | 22 ++++------------ e2e/host/lithe-host.json | 2 +- .../grammars/python.first-line.json | 3 +++ .../grammars/python.tmLanguage.json | 9 ------- .../plugin.json | 4 --- scripts/package/archives.test.mjs | 14 +++++----- scripts/test.mjs | 9 ++++--- 10 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 io.github.lithe-idea.python-support/grammars/python.first-line.json delete mode 100644 io.github.lithe-idea.python-support/grammars/python.tmLanguage.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae36c7c..37f49c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,3 +89,29 @@ jobs: run: | python --version || python3 --version node scripts/test.mjs + + host-e2e: + needs: package + runs-on: macos-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - uses: actions/setup-go@v7 + with: + go-version: "1.27.3" + cache: false + - uses: dtolnay/rust-toolchain@1.100.0 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - uses: actions/download-artifact@v4 + with: + name: python-support-archive-darwin-arm64 + path: dist + - name: Verify Python highlighting on Lithe 0.8.9 + run: node scripts/e2e-host.mjs --ref 4d1b88f03f243356c855299464baa2647cc57226 --run '^TestPythonSupportPluginGrammarHighlighting$' + - name: Verify highlighting and shebang diagnostics on the pinned desktop + run: node scripts/e2e-host.mjs --run '^TestPythonSupportPlugin(GrammarHighlighting|Shebang)$' diff --git a/README.md b/README.md index 27f107a..6a3f3ce 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Rust SDK 和构建提供者的 `scripts/lithe_rpc.py` 通过 stdio JSON-RPC 2.0 | `backend/target/` | Rust 后端编译输出,包含按平台目标区分的产物 | 随工作树保留,可重新由 Cargo 生成 | 不共享,构建时由固定的 Cargo.lock 和 Rust 目标重建。Cargo 使用全局 registry 与 Git 依赖下载缓存。 | | `.artifacts/stage/` | 打包过程中的单平台解包暂存目录 | 每次 `scripts/package.mjs` 按平台重建(`.gitignore` 忽略) | **不可复用**(构建中间产物,毫秒级重建) | | `.artifacts/lithe-host/` | `scripts/e2e-host.mjs` 检出的宿主稀疏工作树及其编译产物 | 本地按需保留(`.gitignore` 忽略) | 其内部 `.artifacts/desktop` 在同一操作系统、CPU 架构与相同 `PINNED_CORE_REVISION` 前提下可按宿主规则复制加速,不得跨工作树软链共用;任何运行时会话日志目录(`sessions//plugins/.../files/`)与状态目录严禁跨工作树复制 | -| `grammars/python.tmLanguage.json`(插件包内) | 插件版本拥有的 TextMate 首行规则,复用宿主内置的 `source.python` 高亮规则 | 构建时随 ZIP 打包,运行时只读,随插件版本更新或卸载 | 由插件源码随包生成,无运行时缓存 | +| `grammars/python.first-line.json`(插件包内) | 插件的 TextMate 首行元数据。普通文件和按首行识别的脚本都沿用宿主的 `source.python` 高亮 | 构建时随 ZIP 打包,运行时只读,随插件版本更新或卸载 | 由插件源码随包生成,无运行时缓存 | | `dist/` | 最终产出的 `python-support--.zip` 发布包 | 打包输出(`.gitignore` 忽略) | 按需重新运行 `node scripts/package.mjs` 生成 | ### 常用命令 diff --git a/docs/feature-matrix.md b/docs/feature-matrix.md index 6cb4ea4..65d69db 100644 --- a/docs/feature-matrix.md +++ b/docs/feature-matrix.md @@ -13,7 +13,7 @@ | 能力域 | 功能项 | `darwin-arm64` | `darwin-x64` | `windows-x64` / `windows-arm64` | `linux-x64` / `linux-arm64` | 最近实机验证 | 实现与测试证据路径(本仓库) | | --- | --- | --- | --- | --- | --- | --- | --- | | 语言基础 (`languages`) | `.py` / `.pyi` / `.pyw` 识别、`#` 行注释、括号/引号配对、项目标记与 `.venv` / `venv` / `.conda` 依赖目录 | ✅ 已验证 | ⏳ pending(归档与清单已校验) | ⏳ pending(归档与 Windows 清单已校验) | ⏳ pending(归档与清单已校验) | `2026-11-20`(`darwin-arm64`,0.8.9 复验 `.py` 高亮) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | -| 无后缀 Python 脚本 | 支持 TextMate 首行匹配的桌面按解释器路径或 `env` shebang 打开,提供 Python 高亮、注释与 Pyrefly 诊断 | ✅ 已验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | `2026-11-20`(`darwin-arm64`,桌面 `79b97fa64`) | `io.github.lithe-idea.python-support/grammars/python.tmLanguage.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | +| 无后缀 Python 脚本 | 支持 TextMate 首行匹配的桌面按解释器路径或 `env` shebang 打开,提供 Python 高亮、注释与 Pyrefly 诊断 | ✅ 已验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | ⏳ 待实机验证 | `2026-11-20`(`darwin-arm64`,桌面 `3dd5a79e9`) | `io.github.lithe-idea.python-support/grammars/python.first-line.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go` | | 插件后端与语言服务器启动解析 (`backend` + `languageServers`) | 包内 Rust SDK 后端协商 `litheLogging` 0 与 `litheFunctions` 0。解析 `pyrefly lsp` 启动,传入宿主提供的解释器,缺失时使用 Pyrefly 原生检测。 | ✅ 已验证(桌面主线) | ⏳ 归档已校验 | ⏳ 待 CI 与宿主验收 | ⏳ 待 CI 与宿主验收 | 2026-11-20(macOS ARM64,桌面主线) | `backend/src/pyrefly.rs`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go`
`e2e/host/desktop/internal/workbench/python_editor_debug_e2e_test.go` | | 工具链与环境自动发现 (`toolDefinitions`) | `python` 4 层解析:项目绑定 → `.venv` / `venv` / `.conda`(受工作区信任门控,保留字面软链路径)→ 全局设置 → `VIRTUAL_ENV` + `PATH` → 16 条跨平台自动发现规则(覆盖 `UV_PYTHON_INSTALL_DIR`、`XDG_DATA_HOME`、`PYENV_ROOT`、`CONDA_ENVS_PATH`、`CONDA_PREFIX`、`WORKON_HOME`、`LOCALAPPDATA`、`APPDATA`、Homebrew、Framework、`~/.pyenv`、`~/.local/share/uv`、`*conda*/envs/*`、`miniforge*/envs/*`) | ✅ 已验证 | ⏳ pending(清单与 Core 规则已校验) | ⏳ pending(`Scripts/python.exe` / `python.exe` 布局与环境变量发现规则已通过 Core 校验) | ⏳ pending(清单与 Core 规则已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | | 构建模型与运行 (`buildSystems: python` + `provider`) | `scripts/build_provider.py`(`python -I -B`,`lithe/build/model`)复用 `scripts/build_model.py` 纯 AST + `tomllib` / `vendor/tomli` 静态提取 `[project.scripts]`、包 `__main__.py`、顶层 `__main__` 脚本、Django `manage.py`、FastAPI ASGI、Flask WSGI 并派生 7 类声明式 `run` 配置;支持损坏 `pyproject.toml` 降级与修复后恢复诊断,并在协商 `litheBuild` 1 时支持 `lithe/build/runEntrypoints` | ✅ 已验证 | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | ⏳ pending(归档已校验) | `2026-11-18`(`darwin-arm64`) | `io.github.lithe-idea.python-support/scripts/build_model.py`
`io.github.lithe-idea.python-support/scripts/build_provider.py`
`io.github.lithe-idea.python-support/plugin.json`
`scripts/test.mjs`
`e2e/host/desktop/internal/workbench/python_support_plugin_e2e_test.go` | @@ -29,6 +29,7 @@ - 插件要求宿主声明 `toolchainProviders: 0`、`buildSystems: 1` 和 `languages: 0`。桌面 0.8.9 支持安装与原有 Python 功能。支持 TextMate 首行匹配的桌面会额外识别无后缀脚本。 - 现有 M3 在兼容桌面主线 `761e6f882`(#2192、#2193)独立验过。`e2e/host/lithe-host.json` 固定支持 TextMate 首行匹配的桌面候选版本。 +- 插件 CI 用同一个 macOS ARM64 ZIP 验证 0.8.9 与候选桌面的普通 Python 高亮,并在候选版验证无后缀脚本编辑后收到 Pyrefly 诊断。 - macOS ARM64 的工作台测试从 ZIP 安装插件,改变项目版本要求以切换外部解释器,检查全局候选和项目 `.venv` 信任,精确重跑一个参数化 pytest 用例并核对 JUnit。 - 无头工作台打开 `.py` 后,Pyrefly 返回所选环境独有模块的类型诊断。debugpy 使用同一环境执行当前文件,并将日志写入宿主分配目录。关闭后,已安装插件的文件清单和 SHA-256 与启动前一致。 - 宿主按 Core 的文件事实校验安装。外部虚拟环境里指向环境外的 Python 链接不可作为提供者候选,项目内环境由宿主信任流程单独处理。 diff --git a/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go b/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go index 19ab1d2..a6f8200 100644 --- a/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go +++ b/e2e/host/desktop/internal/workbench/python_shebang_e2e_test.go @@ -56,8 +56,8 @@ func TestPythonSupportPluginGrammarHighlighting(t *testing.T) { t.Fatal(err) } grammar := h.app.syntaxRegistry().SyntaxForPath(path) - if grammar == nil || grammar.Language().Scope != "source.python.lithe-support" { - t.Fatal("installed Python grammar was not loaded") + if grammar == nil || grammar.Language().Scope != "source.python" { + t.Fatal("installed plugin did not preserve the built-in Python grammar") } h.app.openFile(p, path) h.settle() @@ -76,21 +76,9 @@ func TestPythonSupportPluginGrammarHighlighting(t *testing.T) { t.Fatalf("line %d %q highlights = %v, bundled Python = %v", lineIndex+1, line, got, want) } for i, token := range got { - if token == want[i] { - continue + if token != want[i] { + t.Errorf("line %d %q token = %v, bundled Python = %v", lineIndex+1, line, token, want[i]) } - end := len(line) - if i+1 < len(want) { - end = int(want[i+1].Start) - } - // Both registries tokenize operators through the bundled grammar. The - // plugin root uses the generic classifier, styling those symbols as keywords. - if token.Start == want[i].Start && token.Name.String() == "keyword" && - want[i].Name.String() == "delimiter" && - strings.Trim(line[token.Start:end], "=+<>") == "" { - continue - } - t.Errorf("line %d %q token = %v, bundled Python = %v", lineIndex+1, line, token, want[i]) } } } @@ -99,7 +87,7 @@ func TestPythonSupportPluginShebang(t *testing.T) { h := openPythonGrammarWorkbench(t) p := h.app.project path := filepath.Join(p.root, "script") - const body = "#!/usr/bin/env -S python3 -I\ncount: int = 42\n" + const body = "#!/usr/bin/env -S /usr/bin/python3 -I\ncount: int = 42\n" if err := os.WriteFile(path, []byte(body), 0o600); err != nil { t.Fatal(err) } diff --git a/e2e/host/lithe-host.json b/e2e/host/lithe-host.json index 3a928d6..56a3939 100644 --- a/e2e/host/lithe-host.json +++ b/e2e/host/lithe-host.json @@ -1,6 +1,6 @@ { "repository": "https://github.com/1lck/Lithe-IDEA.git", - "revision": "79b97fa6428df3c28d2c338c56cfdf4153c14008", + "revision": "3dd5a79e97d0c4ac2eedddd06baaf327a20487d0", "packages": { "./internal/projectgen": "^TestPythonPlugin", "./internal/workbench": "^TestPythonSupportPlugin" diff --git a/io.github.lithe-idea.python-support/grammars/python.first-line.json b/io.github.lithe-idea.python-support/grammars/python.first-line.json new file mode 100644 index 0000000..02f2a36 --- /dev/null +++ b/io.github.lithe-idea.python-support/grammars/python.first-line.json @@ -0,0 +1,3 @@ +{ + "firstLineMatch": "^#![ \\t]*/(?:[^ \\t]*/)?(?:env[ \\t]+(?:-S[ \\t]+)?(?:/(?:[^ \\t]*/)?)?)?(?:python(?:[0-9]+(?:\\.[0-9]+)*t?)?|pypy[0-9]*)(?:[ \\t]|$)" +} diff --git a/io.github.lithe-idea.python-support/grammars/python.tmLanguage.json b/io.github.lithe-idea.python-support/grammars/python.tmLanguage.json deleted file mode 100644 index 6d14b71..0000000 --- a/io.github.lithe-idea.python-support/grammars/python.tmLanguage.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "scopeName": "source.python.lithe-support", - "firstLineMatch": "^#![ \\t]*(?:/(?:[^ \\t]*/)?env[ \\t]+(?:-S[ \\t]+)?|/(?:[^ \\t]*/)?)(?:python(?:[0-9]+(?:\\.[0-9]+)*t?)?|pypy[0-9]*)(?:[ \\t]|$)", - "patterns": [ - { - "include": "source.python" - } - ] -} diff --git a/io.github.lithe-idea.python-support/plugin.json b/io.github.lithe-idea.python-support/plugin.json index 72c632a..535f78e 100644 --- a/io.github.lithe-idea.python-support/plugin.json +++ b/io.github.lithe-idea.python-support/plugin.json @@ -52,10 +52,6 @@ "id": "python", "displayName": "Python", "fileExtensions": ["py", "pyi", "pyw"], - "grammar": { - "kind": "textmate", - "path": "grammars/python.tmLanguage.json" - }, "projectFileNames": [ "pyproject.toml", "setup.py", diff --git a/scripts/package/archives.test.mjs b/scripts/package/archives.test.mjs index 920bd6d..7c8c70d 100644 --- a/scripts/package/archives.test.mjs +++ b/scripts/package/archives.test.mjs @@ -123,16 +123,16 @@ test("every built archive has safe paths, no bytecode or symlinks, and valid pla assert.equal(manifest.requires.languages, 0); const pythonLanguage = manifest.languages.find(({ id }) => id === "python"); - assert.deepEqual(pythonLanguage.grammar, { kind: "textmate", path: "grammars/python.tmLanguage.json" }); + assert.equal(pythonLanguage.grammar, undefined); assert.equal("firstLineMatch" in pythonLanguage, false); - const grammarPath = `${PACKAGE_ID}/${pythonLanguage.grammar.path}`; - const grammarEntry = entries.find(({ name }) => name === grammarPath); - assert.ok(grammarEntry, `${archive.name}: missing declared grammar ${grammarPath}`); + const metadataPath = `${PACKAGE_ID}/grammars/python.first-line.json`; + const metadataEntry = entries.find(({ name }) => name === metadataPath); + assert.ok(metadataEntry, `${archive.name}: missing ${metadataPath}`); // Packaged JSON can have CRLF when a Windows runner assembles the ZIP. assert.deepEqual( - JSON.parse(grammarEntry.data.toString("utf8")), - JSON.parse(readFileSync(grammarPath, "utf8")), - `${archive.name}: packaged grammar differs from ${grammarPath}`, + JSON.parse(metadataEntry.data.toString("utf8")), + JSON.parse(readFileSync(metadataPath, "utf8")), + `${archive.name}: packaged metadata differs from ${metadataPath}`, ); assert.deepEqual(manifest.backend, { launch: { kind: "packaged", path: backendPath(archive.platform) } }); diff --git a/scripts/test.mjs b/scripts/test.mjs index f63e9cb..ab5ee9e 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -310,13 +310,14 @@ try { const pluginManifest = JSON.parse(readFileSync(join(unpackedPluginDir, "plugin.json"), "utf8")); await check("Unix and Windows plugin.json + zh-Hans.json satisfy M3 contract invariants", () => { - const grammar = JSON.parse(readFileSync(join(unpackedPluginDir, "grammars", "python.tmLanguage.json"), "utf8")); - assert.deepEqual(grammar.patterns, [{ include: "source.python" }]); - const firstLine = new RegExp(grammar.firstLineMatch); + const metadata = JSON.parse(readFileSync(join(unpackedPluginDir, "grammars", "python.first-line.json"), "utf8")); + assert.deepEqual(Object.keys(metadata), ["firstLineMatch"]); + const firstLine = new RegExp(metadata.firstLineMatch); for (const line of [ "#!/usr/bin/python", "#!/usr/bin/env python3", "#!/usr/bin/env -S python3.13 -I", + "#!/usr/bin/env -S /usr/bin/python3 -I", "#!/opt/venv/bin/python3.13t", "#!/usr/bin/env pypy3", ]) { @@ -383,7 +384,7 @@ try { }); const pyLang = variant.languages[0]; - assert.deepEqual(pyLang.grammar, { kind: "textmate", path: "grammars/python.tmLanguage.json" }); + assert.equal(pyLang.grammar, undefined); assert.equal("firstLineMatch" in pyLang, false); assert.deepEqual(pyLang.fileExtensions, ["py", "pyi", "pyw"]); assert.deepEqual(pyLang.dependencies.projectDependencyPaths, [".venv", "venv", ".conda"]);