Repository navigation
fix(platform): Unix 上 \ 和 : 是文件名字符,路径规则统一到 lithe-platform - #62
Merged
Merged
Conversation
在 macOS 上,Spring Boot 的 logging.file.path: D:\logs 会创建一个名字就叫 D:\logs 的文件夹。Core 不分平台地把 \ 当分隔符,把它拆成两级, workspace.projectTree.rows 于是报 invalid_request,项目树为空(1lck/Lithe-IDEA#2009)。 - lithe-platform/paths:is_separator、slash_separated(_path)、 invalid_relative_path、invalid_native_relative_path、 invalid_portable_relative_path,都带 Platform 参数;Platform::ALL。 - 项目文件、运行配置、Git、LSP、工具链等调用方改用统一函数, 去掉写死的 replace('\\', "/")。跨平台共享文档里的路径仍用可移植规则。 - lithe-protocol 删除旧的 invalid_relative_path,execution 删除无用的 valid_relative。 - .gitignore 写入 Unix 文件名里的 \ 时转义。 - 回归测试:项目树、文件读取、Git 忽略(Unix),以及两个平台的规则单测。 Unix 上 Git 仍拒绝含 : 的路径,另见 1lck/Lithe-IDEA#2016。
9 tasks done
xiaoyumuxi
marked this pull request as ready for review
November 16, 2026 08:02
This was referenced Nov 16, 2026
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 是 #2009 的 Core 修复。桌面端在 https://github.com/1lck/Lithe-IDEA/pull/2023(Draft):暂时把
PINNED_CORE_REVISION固定到本 PR 的c0dd2a4,补桌面端回归测试,由它关闭 #2009。本 PR 合入后,#2023 改为 main 上的 commit 再标记 ready。PR 类型 / Type
改动说明 / What changes
背景 / Why
#2009:在 macOS 上导入一个 Spring Boot 项目,项目树不显示,并报错
workspace.projectTree.rows: A project tree node is not in the folder above it (invalid_request)。Spring Boot 的
logging.file.path如果按 Windows 写法配置成D:\logs,在 macOS 上运行后会在项目目录里创建一个名字就叫D:\logs的文件夹。Unix 上\和:都是普通的文件名字符。但 Core 的relative_path不分平台,把\一律换成/,于是这个文件夹的路径变成了D:/logs,被当成两级目录。桌面端按真实的嵌套层级把它排在第 1 层,项目树校验发现它不在根目录下面,整棵树就报错了。旧的
lithe_protocol::invalid_relative_path也有同样的问题:它在所有平台上都把\当分隔符,在所有平台上都拒绝:。本 PR 把分隔符和相对路径规则统一放在
lithe-platform,做成带Platform参数的函数。生产代码传Platform::HOST,不再到处写死.replace('\\', "/")或contains(['\\', ':']):\和:是文件名的一部分。\或:。改动 / Changes
统一规则:
rust/crates/platform/src/paths.rsis_separator(character, platform)/分隔,只有 Windows 还按\分隔。slash_separated(path, platform)/。Unix 上原样返回。原来只有 Windows 分支,现在改为基于is_separator实现。slash_separated_path(&Path, platform)to_string_lossy().replace('\\', "/")。invalid_relative_path(value, platform)lithe-protocol移来,加了平台参数。所有平台都拒绝空路径、以/开头、含 NUL、含..段;Windows 上还拒绝路径段里有\,以及含:的路径段(盘符C:x或备用数据流file:stream)。invalid_native_relative_path(value, platform)slash_separated再校验,给用户输入的原生路径用。invalid_portable_relative_path(value)Platform::ALL的每个平台上都要合法,给跨平台共享文档里保存的路径用。lithe-platform/src/lib.rs:新增Platform::ALL = [Unix, Windows]。join_native改为使用is_separator。lithe-protocol删除旧的invalid_relative_path及其导出。项目文件(
lithe-project):本机规则files/paths.rs:新增relative_request_path,请求里的路径先用slash_separated(…, HOST)转换,再用invalid_relative_path(…, HOST)校验。safe_relative_path、writable_relative_path、safe_relative_path_string都改用它。relative_path改用slash_separated_path(…, HOST)。这一处就是 #2009 的直接原因。files/snapshot.rs、files/events.rs、history.rs、directory_actions.rs、indexing.rs:改用统一函数和 HOST 规则。目录规则和索引策略保存在宿主本地偏好里,不跨平台共享,所以用本机规则。file_operations.rs:plan和validate_name加了platform参数,两个命令都传Platform::HOST。复制或粘贴时的新名字在所有平台上都不能是空、.、..或含/;只有 Windows 还拒绝含\或:的名字。运行配置(
lithe-execution)layers.rs的normalize_project_directory和project_directory_exists,以及validation.rs的cwd,都改用invalid_native_relative_path(…, HOST)。Windows 用户仍可以写src\main;Unix 上的src\main是一个名字。document.rs的root、project_toolchain.rs的path、provider_runs.rs的project_path,改用invalid_portable_relative_path。这些文档会被另一个平台读到,因此在任何平台上都不接受\或:,和改动前一样。launch.rs的provider_root:原来先调invalid_relative_path、再调project_directory_exists,后者已经包含同样的校验,所以只保留后者。validation.rs:删除带#[allow(dead_code)]、没有任何调用方的valid_relative。inputs.rs、workspace_scan.rs、detectors/scan.rs:改用slash_separated_path(…, HOST)。context_selection.rs:case_insensitive_paths的文档写的是"Windows path identities",改为slash_separated(path, Platform::Windows),行为不变。Git(
lithe-git)repository.rs:仓库路径、path_sort_key、is_safe_pathspec、relative_or_absolute用 HOST 规则。validate_git_path_on和simplified_canonical_path要识别盘符和 UNC 形状,非 Windows 主机上也一样,所以明确用Platform::Windows,并加了注释。ignore.rs:转换后剩下的\是 Unix 文件名的一部分,而.gitignore会把\当转义符,所以转义集合里加了\。Unix 上忽略logs\app.log会写入/logs\\app.log。process.rs:改用统一函数。file_context.rs的测试也改了。其他 crate:把写死的替换换成统一函数
lsp-engine/engine.rs:slash_separated_path(&canonical, HOST)。lsp-policy/document_identity.rs:Windows 分支用slash_separated(…, Windows),并用is_separator(…, Windows)去掉末尾分隔符。document-uri/encode.rs:Windows 分支用slash_separated(…, Windows)。debug/projection_v2.rs:workspace_relative先按工作区根路径的形状判断平台,再调用slash_separated。toolchain/paths.rs:新增pub fn rules(platform: &str) -> Platform。normalize改为slash_separated(path, rules(platform)),并去掉"Unix 上路径含\就返回None"的特判:Unix 上的绝对路径/opt/a\b/jdk现在合法。join去末尾分隔符时改用is_separator。plugin-output-links:改为slash_separated(raw, lithe_toolchain::paths::rules(platform))。project-generators/plan.rs:HOST 规则。lsp-client/client/validation.rs:workspace_name_from_uri用is_separator(…, HOST)。另外,lithe-diagnostics只在测试里用到,从[dependencies]移到了[dev-dependencies],因为这次要给lithe-client的Cargo.toml加lithe-platform。Cargo.toml都加了lithe-platform = { path = "../platform" },Cargo.lock随之更新。契约与夹具
rust/contracts/rust-core-api.md:在workspace.planPaste一段写明复制名称的平台规则。rust/fixtures/workspace/file-copy-names-v1.json:invalidNames去掉"a\\b"(Unix 上它是合法名字),新增windowsInvalidNames: ["a\\b", "D:\\logs", "a:b"]。测试
lithe-platform:is_separator、slash_separated_path、invalid_relative_path(越界路径在所有平台都非法;\、:只在 Windows 上非法)、invalid_native_relative_path、invalid_portable_relative_path,每个都对两个平台各测一次,不加cfg。lithe-project/file_operations.rs:用夹具测试invalidNames在两个平台上都被拒绝,windowsInvalidNames只在 Windows 上被拒绝。lithe-toolchain/paths.rs:only_windows_reads_a_backslash_as_a_separator。core/src/tests/project_tree.rs(#[cfg(unix)]):#2009 的回归测试。在真实目录里创建D:\logs/spring.log和D:\logs\app.log,workspace.listDirectories把它们放在正确的层级,workspace.projectTree.rows接受由此生成的行。原来的run改为调用新的execute,避免 Windows 上出现无用函数。core/src/tests/project.rs:file_commands_round_trip_and_reject_traversal里的..\outside.txt、nested\..\outside.txt、C:\outside.txt:在 Windows 上它们会越出工作区,被拒绝;在 Unix 上它们是根目录里一个不存在的文件名。两边都读不到工作区以外的文件,所以只断言ok == false,不再断言错误码。#[cfg(unix)]段新增用例:根目录里真有一个名叫..\outside.txt的文件时,file.read读到的是它。core/src/tests/git.rs(#[cfg(unix)]):git_write_ignores_a_unix_file_whose_name_holds_a_backslash。.gitignore写入/logs\\app.log;git check-ignore认为logs\app.log被忽略,logs/app.log没有被忽略。有意保留、没有改的写死规则
这些地方处理的是外部文本或标识符,不是工作区路径,改了反而会出错:
ai的sensitive_path、debug的 step filter、build的decode.rs和select.rs、html_preview、插件和贡献 ID 的校验、引号转义。patch_exchange对.git路径段的检查、changelist 的safe_path。execution/launch.rs对程序名的检查:它需要的就是可移植规则。不在本 PR 范围内 / Out of scope
:的路径:is_safe_pathspec还保留对:的拒绝,因为它也用来校验分支名和远程名(mutations.rs、branches.rs)。对它们放开:会带来 refspec 注入风险,需要把 ref 校验和路径校验拆开,还要处理line_history的rev:path和 patch exchange。已建单:[Bug] macOS 上 Git 操作拒绝文件名含 ":" 的文件:is_safe_pathspec 同时校验 ref 和工作区路径 1lck/Lithe-IDEA#2016PINNED_CORE_REVISION,在desktop/internal/workbench加 Go 回归测试,并关闭 #2009。类型专属:fix
复现与根因
D:\logs(Spring Boot 在 macOS 上读取logging.file.path: D:\logs时就会这样创建),里面放spring.log,然后打开项目。workspace.listDirectories把子项路径报成D:/logs;workspace.projectTree.rows返回A project tree node is not in the folder above it (invalid_request),项目树为空。D:\logs作为根目录下的一个文件夹显示,spring.log在它里面。lithe-project/src/files/paths.rs里的relative_path等函数,以及lithe_protocol::invalid_relative_path,都不分平台地把\当成分隔符。relative_path的.replace('\\', "/")来自 1lck/Lithe-IDEA@2e27b84e7(feat: add shared Rust core boundary,2026-08-03)。invalid_relative_path来自 1lck/Lithe-IDEA@4df498ece(refactor: complete shared core decoupling,2026-08-04)。\的条目会让整棵树报invalid_request,而不只是显示错位。\本来就是分隔符,行为不变。检查项
rust/crates/core/src/tests/project_tree.rs中的names_with_backslashes_stay_one_level_below_their_folder_on_unix。listDirectories把D:\logs报成了D:/logs。git.rs的忽略用例和project.rs的..\outside.txt文件名用例在 main 上也都失败。lithe_protocol::invalid_relative_path已删除,编译器会指出所有调用方,已逐个改为本机规则、原生输入规则或可移植规则(分类见上方"改动")。replace('\\', "/")、replace('\\\\', "/")和['/', '\\'],剩下的调用点见上方"有意保留、没有改的写死规则"。file_operations::plan只在本 crate 内调用,两个命令都已传入Platform::HOST。Platform::Windows测试,原有 Windows 行为的测试照常通过。Windows 目标的 clippy 已通过,但没有在 Windows 实机上运行。valid_relative和移动lithe-diagnostics依赖,都是这次改动直接带出来的。.agents/notes/implemented/bug-fix/。这条约束由lithe-platform的文档注释和两个平台各自的测试来保证。范围检查 / Scope checks
lithe-platform。slash_separated在 Unix 上不分配内存,直接借用原字符串。lithe_protocol::invalid_relative_path和execution的valid_relative变成无用代码,都已删除。验证 / Verification
本机为 Apple M4,Rust 1.100.0。
cargo fmt --manifest-path rust/Cargo.toml --all -- --checkscripts/rust-core/verify-rust-core-comments.shnode scripts/rust-core/verify-platform-tests.mjscargo test --manifest-path rust/Cargo.toml --workspace --features lithe-remote/server --no-fail-fastcargo test --manifest-path rust/Cargo.toml -p lithe-platform -p lithe-platform-testslithe-platform23 个测试全部通过。lithe-platform-tests有一个测试不稳定,见下方说明cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warningscargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings已有的不稳定测试:
lithe-platform-tests的lsp_process::terminating_a_language_server_ends_the_processes_it_started有时失败:dispose报Language-server process tree did not exit.,原因是Operation not permitted (os error 1)。lsp-transport和git-host,所以这不是本 PR 引入的。EPERM)。未能执行的检查和原因:
Platform::Windows数据形式在 macOS 上测过;affected-crates.mjs为本改动选的 Windows 作业是-p lithe-platform -p lithe-platform-tests,PR 标记 ready 后会在 CI 上运行。D:\logs的目录,固定到 main6a14126时报出与 Issue 相同的通知,固定到本 PR 的c0dd2a4时通过。提交前确认 / Final checks
main(6a14126)创建,目标分支main。