Title: fix(platform): Unix 上 \ 和 : 是文件名字符,路径规则统一到 lithe-platform by xiaoyumuxi · Pull Request #62 · Lithe-IDEA/Lithe-core-rust · GitHub
Open Graph Title: fix(platform): Unix 上 \ 和 : 是文件名字符,路径规则统一到 lithe-platform by xiaoyumuxi · Pull Request #62 · Lithe-IDEA/Lithe-core-rust
X Title: fix(platform): Unix 上 \ 和 : 是文件名字符,路径规则统一到 lithe-platform by xiaoyumuxi · Pull Request #62 · Lithe-IDEA/Lithe-core-rust
Description: 关联 Issue / Linked issue Refs 1lck/Lithe-IDEA#2009 本 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 fix:缺陷修复 改动说明 / 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(['\\', ':']): Windows 上的行为不变。 Unix 上 \ 和 : 是文件名的一部分。 写进跨平台共享文档的路径用"可移植"规则,在任何平台上都不能含 \ 或 :。 改动 / Changes 统一规则:rust/crates/platform/src/paths.rs 函数 作用 is_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。 以上 crate 的 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 的校验、引号转义。 Git patch_exchange 对 .git 路径段的检查、changelist 的 safe_path。 execution/launch.rs 对程序名的检查:它需要的就是可移植规则。 不在本 PR 范围内 / Out of scope Unix 上 Git 仍然拒绝含 : 的路径:is_safe_pathspec 还保留对 : 的拒绝,因为它也用来校验分支名和远程名(mutations.rs、branches.rs)。对它们放开 : 会带来 refspec 注入风险,需要把 ref 校验和路径校验拆开,还要处理 line_history 的 rev:path 和 patch exchange。已建单:1lck/Lithe-IDEA#2016 Lithe-IDEA 那边的工作在 https://github.com/1lck/Lithe-IDEA/pull/2023:升级 PINNED_CORE_REVISION,在 desktop/internal/workbench 加 Go 回归测试,并关闭 #2009。 #2009 里提到的"无法直接运行启动类"看起来是另一个问题,已在 Issue 里请报告人补充信息。 类型专属:fix 复现与根因 复现:macOS 上,在项目根目录创建文件夹 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)。 两者都在 Core 拆成独立仓库之前写成,7ae0c16(#28)拆 crate 时原样搬了过来。 62b8a08(#31)把项目树行的计算移进 Core,并开始校验"每个节点都在上一级文件夹里"。从这以后,名字带 \ 的条目会让整棵树报 invalid_request,而不只是显示错位。 影响平台:只影响 macOS 和 Linux。Windows 上 \ 本来就是分隔符,行为不变。 检查项 已先写回归测试,确认它修复前失败、修复后通过。 测试路径:rust/crates/core/src/tests/project_tree.rs 中的 names_with_backslashes_stay_one_level_below_their_folder_on_unix。 修复前:把三个新测试复制到 main(6a14126)的检出上运行,全部失败。项目树用例的断言输出是: left: ["D:/logs", "D:/logs/app.log"] right: ["D:\\logs", "D:\\logs\\app.log"] 也就是 listDirectories 把 D:\logs 报成了 D:/logs。git.rs 的忽略用例和 project.rs 的 ..\outside.txt 文件名用例在 main 上也都失败。 修复后:三个用例都通过。 [N/A] 手动复现:已经自动化。 已检查全部调用方: 旧的 lithe_protocol::invalid_relative_path 已删除,编译器会指出所有调用方,已逐个改为本机规则、原生输入规则或可移植规则(分类见上方"改动")。 全仓库搜索过 replace('\\', "/")、replace('\\\\', "/") 和 ['/', '\\'],剩下的调用点见上方"有意保留、没有改的写死规则"。 file_operations::plan 只在本 crate 内调用,两个命令都已传入 Platform::HOST。 另一平台:Windows 的规则写成数据,在 macOS 上以 Platform::Windows 测试,原有 Windows 行为的测试照常通过。Windows 目标的 clippy 已通过,但没有在 Windows 实机上运行。 只改了修复所需的代码。把所有写死的替换换成统一函数,是这次修复的范围:用户要求统一成一个支持跨平台识别的函数。删除 valid_relative 和移动 lithe-diagnostics 依赖,都是这次改动直接带出来的。 [N/A] Agent Note:Core 仓库没有 .agents/notes/implemented/bug-fix/。这条约束由 lithe-platform 的文档注释和两个平台各自的测试来保证。 范围检查 / Scope checks 功能矩阵:N/A,没有新增宿主能力。只修复了 Unix 上一类文件名的显示和操作。 插件归属:Core 改动不涉及任何具体插件;测试只用测试内临时创建的目录和仓库。 UI / i18n:N/A,没有界面文字。 统一日志系统:N/A,没有新增或改动日志事件。 逻辑归属:全部在 Rust Core。平台差异作为数据放在 lithe-platform。 性能与内存:没有新增进程、线程、缓存或轮询。slash_separated 在 Unix 上不分配内存,直接借用原字符串。 设置:N/A。 插件契约:N/A,没有改插件契约、能力版本、插件函数协议或宿主方法。 发行包与资源:N/A,没有新增运行时资源。 无用代码:本次让 lithe_protocol::invalid_relative_path 和 execution 的 valid_relative 变成无用代码,都已删除。 验证 / Verification 本机为 Apple M4,Rust 1.100.0。 命令或操作 平台 结果 cargo fmt --manifest-path rust/Cargo.toml --all -- --check macOS arm64 通过 scripts/rust-core/verify-rust-core-comments.sh macOS arm64 通过 node scripts/rust-core/verify-platform-tests.mjs macOS arm64 通过 cargo test --manifest-path rust/Cargo.toml --workspace --features lithe-remote/server --no-fail-fast macOS arm64 通过:2115 passed,0 failed cargo test --manifest-path rust/Cargo.toml -p lithe-platform -p lithe-platform-tests macOS arm64 lithe-platform 23 个测试全部通过。lithe-platform-tests 有一个测试不稳定,见下方说明 cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings macOS arm64 通过 cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings macOS 交叉检查 Windows 目标 通过 回归测试先在 main(6a14126)上运行 macOS arm64 按预期失败,输出见上方 已有的不稳定测试: 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)。 在 main 上连续运行 15 次失败 8 次,在本分支上失败 4/15。本 PR 没有改 lsp-transport 和 git-host,所以这不是本 PR 引入的。 已建单:1lck/Lithe-IDEA#2017 ,修复在 #63(原因是 macOS 对只剩未回收僵尸进程的进程组返回 EPERM)。 未能执行的检查和原因: 没有在 Windows 上运行测试,只做了 Windows 目标的 clippy。Windows 规则以 Platform::Windows 数据形式在 macOS 上测过;affected-crates.mjs 为本改动选的 Windows 作业是 -p lithe-platform -p lithe-platform-tests,PR 标记 ready 后会在 CI 上运行。 没有在打包后的 Lithe 应用里复测。桌面端的回归测试在 https://github.com/1lck/Lithe-IDEA/pull/2023:它用真实 Core 打开含 D:\logs 的目录,固定到 main 6a14126 时报出与 Issue 相同的通知,固定到本 PR 的 c0dd2a4 时通过。 提交前确认 / Final checks 分支从最新 main(6a14126)创建,目标分支 main。 以 Draft 提交,本地验证已通过。 没有无关改动、构建产物、凭据或个人路径。 本次验证没有启动 Lithe 应用,没有进程残留。
Open Graph Description: 关联 Issue / Linked issue Refs 1lck/Lithe-IDEA#2009 本 PR 是 #2009 的 Core 修复。桌面端在 https://github.com/1lck/Lithe-IDEA/pull/2023(Draft):暂时把 PINNED_CORE_REVISION 固定到本 PR 的 c0dd2a4,补桌面端回归测试,由它关闭 #2009。本 ...
X Description: 关联 Issue / Linked issue Refs 1lck/Lithe-IDEA#2009 本 PR 是 #2009 的 Core 修复。桌面端在 https://github.com/1lck/Lithe-IDEA/pull/2023(Draft):暂时把 PINNED_CORE_REVISION 固定到本 PR 的 c0dd2a4,补桌面端回归测试,由它关闭 #2009。本 ...
Opengraph URL: https://github.com/Lithe-IDEA/Lithe-core-rust/pull/62
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:630d941c-70f4-d943-c88c-bb10c32f9290 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D720:2925CB:1964A10:23F47C2:6B07271D |
| html-safe-nonce | 627a5820a02085e896561c19f30951eb31e788484f3793a4a972782d6312a515 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzIwOjI5MjVDQjoxOTY0QTEwOjIzRjQ3QzI6NkIwNzI3MUQiLCJ2aXNpdG9yX2lkIjoiMjEyMTkxNjU0NzAwMTE2NTU5NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4b7a43eeba6d27a0679a72caa4df9ee9864e2dc3894a165862df6cd33c65686 |
| hovercard-subject-tag | pull_request:5333167650 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/Lithe-IDEA/Lithe-core-rust/pull/62/files |
| twitter:image | https://avatars.githubusercontent.com/u/145102356?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/145102356?s=400&v=4 |
| og:image:alt | 关联 Issue / Linked issue Refs 1lck/Lithe-IDEA#2009 本 PR 是 #2009 的 Core 修复。桌面端在 https://github.com/1lck/Lithe-IDEA/pull/2023(Draft):暂时把 PINNED_CORE_REVISION 固定到本 PR 的 c0dd2a4,补桌面端回归测试,由它关闭 #2009。本 ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5a20fe9aa5e45c6df9328a5ec3f167a7805856126d8bf72d810541ca01962ef9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/Lithe-IDEA/Lithe-core-rust git https://github.com/Lithe-IDEA/Lithe-core-rust.git |
| octolytics-dimension-user_id | 340144206 |
| octolytics-dimension-user_login | Lithe-IDEA |
| octolytics-dimension-repository_id | 1449354685 |
| octolytics-dimension-repository_nwo | Lithe-IDEA/Lithe-core-rust |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1449354685 |
| octolytics-dimension-repository_network_root_nwo | Lithe-IDEA/Lithe-core-rust |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6ce961d9a663a99bc4bcab9fd6ac5cca54bd6fcc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width