fix(lsp): encode reserved chars in workspace root URIs - #222
Open
dergachoff wants to merge 1 commit into
Open
Conversation
initialize built workspace folder URIs by splicing raw paths into
`format!("file://{path_str}")`, bypassing the encoder added in bug-ops#151.
A root containing `#` parsed cleanly but truncated: `/home/me/dev/#work`
became path `/home/me/dev/` with fragment `work`, so the server silently
received the parent directory as its root. A root containing `[` or `]`
was rejected by `Uri::from_str` and failed initialization outright.
Route the mapping through `bridge::path_to_uri`, which already performs
this encoding and already strips the Windows `\\?\` prefix that this
call site duplicated. Since `path_to_uri` panics on failure and this
path returns `Result`, add a crate-internal `try_path_to_uri` as the
fallible core and keep `path_to_uri` as a thin wrapper over it.
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.
Closes #221.
Problem
initializebuilt workspace folder URIs by splicing raw paths, so a workspace root containing reserved characters was sent wrong or rejected:#parsed cleanly but truncated./home/me/dev/#workbecame path/home/me/dev/with fragmentwork, so the server silently received the parent directory as its root.[and]were rejected byUri::from_str, failing initialization withInvalid workspace root.Root cause
lsp/lifecycle.rspredatesbridge::path_to_uri(#151) and never used it, so it carried its ownformat!("file://{path_str}")plus a duplicate copy of the Windows\\?\stripping the shared helper already does.Fix
Route the mapping through the shared encoder.
path_to_uripanics and this call site returnsResult, sotry_path_to_uribecomes the fallible core andpath_to_uria thin wrapper over it; the new helper is crate-internal. The per-root mapping moves intoworkspace_folderso it is testable without a live LSP client.Incidental: the
Invalid UTF-8 in pathbranch is gone, sinceUrl::from_file_pathtakes a&Path. Non-UTF-8 roots now work instead of erroring.Validation
cargo +nightly fmt --check,cargo +1.95 clippy --all-targets --all-features -- -D warningscargo +1.95 nextest run— 412 passed, 33 skippedcargo +1.95 check -p mcpls-core --target x86_64-pc-windows-msvc --all-targets --all-features, since fix(core): encode reserved path chars in file URIs #151 hit Windows-only breakage. New tests useC:\...roots on Windows and/...elsewhere, matchingstate.rs.workspace_foldertests fail against the pre-fix logic with the predicted symptom:left: "file:///home/me/dev/#work",right: "file:///home/me/dev/%23work".