Skip to content

fix: resolve path duplication when workspace root differs from cwd#14

Merged
observerw merged 1 commit intolsp-client:mainfrom
cyborg42:main
Jan 15, 2026
Merged

fix: resolve path duplication when workspace root differs from cwd#14
observerw merged 1 commit intolsp-client:mainfrom
cyborg42:main

Conversation

@cyborg42
Copy link
Contributor

Fix: Resolve path duplication when workspace root differs from cwd

Problem

When running lsp commands from a directory different from the LSP workspace root, relative file paths were incorrectly duplicated.

For example, in a Cargo workspace with nested crates:

pwd
/path/to/project

❯ lsp hover -L "crates/foo/src/bar.rs@some_function<|>"
Error: No such file or directory: '/path/to/project/crates/foo/crates/foo/src/bar.rs'

The path crates/foo was duplicated because:

  1. User input is relative to cwd (crates/foo/src/bar.rs)
  2. find_client() discovers workspace root as /path/to/project/crates/foo (where Cargo.toml lives)
  3. lsp_client.as_uri() concatenates workspace root + relative path, causing duplication

Solution

Convert relative file_path to absolute path in create_locate() before passing to lsp_client. The as_uri() method correctly handles absolute paths by checking if they fall within workspace folders.

Changes

  • src/lsp_cli/cli/shared.py: Add path normalization in create_locate()

Testing

Verified fix works in a Cargo workspace:

pwd
/path/to/project

❯ lsp hover -L "crates/foo/src/bar.rs@some_function<|>"
# Hover Information
... (correct output)

When running commands from a directory different from the LSP workspace
root (e.g., in a Cargo workspace with nested crates), relative file
paths were incorrectly duplicated.

Example: `crates/foo/src/bar.rs` was resolved to
`/path/crates/foo/crates/foo/src/bar.rs`

Fix by converting relative paths to absolute paths in `create_locate()`
before passing to lsp_client, which correctly handles absolute paths in
its `as_uri()` method.
@observerw
Copy link
Contributor

Thank you! I'll take a look 😄

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@observerw observerw added the bug Something isn't working label Jan 15, 2026
@observerw observerw merged commit 0395a73 into lsp-client:main Jan 15, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants