Canonicalize LSP diagnostics path to resolve symlinks and match the document path #7885
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
When opening a file through a symlink, diagnostic info from the language server is discarded due to a mismatch between the LSP URL and the canonicalized path in
helix_view::Document
.Example
Consider the following project tree (example based on cxx):
where
lib.rs
containsmod syntax
.If we open
gen/src/syntax/mod.rs
in helix, the path is canonicalized byget_canonicalized_path
and it becomes an absolute path like<...>/syntax/mod.rs
, since symlinks are resolved byget_canonicalized_path
(in contrast to what is said in the comments in helix-core/src/path.rs, is this intended?). This canonicalized path is then stored inhelix_view::Document
.However, when diagnostics are published by the language server, we get a URL that is turned into the path
<...>/gen/src/syntax/mod.rs
. Symlinks are not resolved and this path is not canonicalized. As a result, there is a mismatch between this path and the canonicalized path inhelix_view::Document
, and the diagnostics are not sent to the open document.Proposed Solution (this PR)
Canonicalize the path received from the language server to ensure that it matches the path stored in
helix_view::Document
.Please let me know if there are any problems with this PR!
P.S.: I believe this may have been a regression of d04288e, which might have changed the behavior of
get_canonicalized_path
to resolve symlinks, sincedunce::canonicalize
relies onstd::canonicalize
internally (on Linux/UNIX). Either way, canonicalizing the path sent by the language server using the same canonicalization method as done by this PR should resolve the current issue.