Skip to content

fix(lsp): encode reserved chars in workspace root URIs - #222

Open
dergachoff wants to merge 1 commit into
bug-ops:mainfrom
dergachoff:fix/workspace-root-uri-encoding
Open

fix(lsp): encode reserved chars in workspace root URIs#222
dergachoff wants to merge 1 commit into
bug-ops:mainfrom
dergachoff:fix/workspace-root-uri-encoding

Conversation

@dergachoff

Copy link
Copy Markdown
Contributor

Closes #221.

Problem

initialize built 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/#work became path /home/me/dev/ with fragment work, so the server silently received the parent directory as its root.
  • [ and ] were rejected by Uri::from_str, failing initialization with Invalid workspace root.

Root cause

lsp/lifecycle.rs predates bridge::path_to_uri (#151) and never used it, so it carried its own format!("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_uri panics and this call site returns Result, so try_path_to_uri becomes the fallible core and path_to_uri a thin wrapper over it; the new helper is crate-internal. The per-root mapping moves into workspace_folder so it is testable without a live LSP client.

Incidental: the Invalid UTF-8 in path branch is gone, since Url::from_file_path takes 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 warnings
  • cargo +1.95 nextest run — 412 passed, 33 skipped
  • cargo +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 use C:\... roots on Windows and /... elsewhere, matching state.rs.
  • The three new workspace_folder tests fail against the pre-fix logic with the predicted symptom: left: "file:///home/me/dev/#work", right: "file:///home/me/dev/%23work".

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.
@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes mcpls-core mcpls-core crate changes labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation mcpls-core mcpls-core crate changes rust Rust code changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: workspace root URIs are spliced instead of encoded

1 participant