-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LSP (clangd) actions open duplicate buffers #6182
Comments
Is it possible that this is windows only issue? Have no problem like that on linux. |
I tried this with Linux and yes, it does seem to be on Windows only, and specific to clangd |
We do automatically canonicalize paths so I suspect that this is a windows issue. This looks a bit like #6182 but in this case it shouldn't apply because we are converting the URLs to paths (which ignore prefix casing). I suspect this is some special case where canonicalization either fails or returns inconsistent results. Is this some kind of specical path (network path or something else)? Perhaphs cannonicalization fails in some way. Could you share the exact path that you started helix in and the exact path clangd opens? We hand-roll our own canonicalization because the one from standard library is somehwat of a footgun. I think we are missing case cannonicalization here tough so that might be the cause of the problem. I think we might need to switch to https://docs.rs/normpath/latest/normpath/index.html |
I did some testing and can confirm it seems to be associated with path casing.
However, if I instead in helix cd into So essentially you are correct, if the casing of pwd in helix differs from the filesystem, path canonicalization fails. |
Thanks for confirming. The right way to fix this is to implement a better canonicalization strategy here: Line 42 in 4f066b1
Howeber the way to correctly normalize a path is to obtain a file descriptor and to turn that file descriptor back into a path. Path equality is fundamentally file system dependent so even on windows different drives might have different canonicalization strategies. Luckily this is exactly what the std
The first problem.can be resolved by using https://docs.rs/dunce/latest/dunce/fn.canonicalize.html instead of std cannonicalize (it would be great if the standard library adopted but not holding my breath for that). Under the hood it cannonicalizess the path with std and (on windows) it then simplifies the result back to a traditional path if possible. For the second problem I think the right way to fix this is to: Walk up the pathsancestors with This implementation also has the added bonus of properly handeling softlinks which our currently strategy also doesn't do. Should.not be hard to send a PR to implement what I described |
I had a look through the relevant code and I don't think canonicalization is actually the issue here. The issue is just that |
When I perform navigational code actions through the LSP (clangd), e.g., gd (goto definition), it opens a duplicate buffer with the absolute path rather than the path relative to pwd. This buffer is separate from the original buffer even though they refer to same file, so I can unknowingly write changes to this duplicate buffer, then overwrite those changes in the original buffer, which is frustrating since I end up losing my work.
For example, within buffer "src/code.cpp" -> gd -> opens buffer "C:/full/path/to/src/code.cpp" (cursor at the definition).
I expect the correct behavior to be for it to resolve the LSP's requested file path relative to pwd such that
a) It doesn't open the buffer with an absolute path if it's under pwd and
b) subsequently, doesn't open a duplicate buffer
The text was updated successfully, but these errors were encountered: