-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix(path): change normalization strategy #7658
Conversation
I think this is actually an accidental/unintentional side effect introduced by #6290. I think the real crux is that we don't actually want to resolve symbolic link in normalize_paths. I think we can still keep the cannonicalization (which is the only way to correctly compare two paths) while making that work. We probably want to iterate the ancestors in reverse instead and check:
|
I'm not sure I understand you. Should we change canonicalization strategy? |
Hmm let me show some exanoles in your case we would cannicolize What I mean twith my description is that we basically want to cannonicalize the parent directory and then just join the link name on top... Howver the parent directory (and any of its parents) could also be a symlink. So you would need to start at the bottom. For example Then join Next we cannonicalize We repeat the sane thing for Thks way we basically don't resolve symlinks while still normalizing filenames/paths correctly in every case |
If I understand correctly, if we implement this, we should call |
I don't think that makes too much of a difference what functions are called when should not change, only |
If we implement this and try to open the original file (after symlink), we will have two buffers. VsCode and Vim behave this way, it seems. Is this the desired result or am I wrong? |
that's at least how helix used to behave before the (unintentional) change to cannoncialize symlinks. Even in the past the cannoncialize function has never resolved symlinks. A buffer should have a single unique path. We should only ever use that path to determine the language of the file and interact with it in other way. Otherwise, you can symlink ( The problem of potentially having multiple links open at once exists anyway (hardlinks) so I don't think that's that big of an issue (especially because we hide symlinks that point into the current workspace from the file picker so you have to put in some effort to open the same file twice) |
Yeah, that's exactly what I was thinking. Very clear explanation. I just didn't know what the previous behavior was when opening a symlink and original file, so I assumed that maybe current behavior was desired. Now I got it, ty. |
e1e0857
to
abdf417
Compare
While changing the implementation, I found one interesting case. I believe Pr is now ready for reviewing, but in a few days I will add tests with creating files and links to catch more pitfalls. |
I think in that case we actually want to keep the colons. |
340ede9
to
27c054c
Compare
Okay, I think I'm done with this. If you have corner cases that would be easy to test, I can add them for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this lookgs good to me. Ideally we would reduce the number of cannonivalize calls a bit and try to sk.how do case folding on windows for symlinks too but that would involve pulling in the windows API and make the code more complex.
I think the edgecase of case folding symlinks on windows is rare enough to ignore (symlinks are rare on windows anyway) and the couple extra realpath syscalls shouldnt matter much
6960187
to
c20d041
Compare
c20d041
to
e748a47
Compare
Rebased on master. |
e748a47
to
858b7e7
Compare
One more edgecase for windows: You must use std cannonicalize instead of dunce and then only simplify the final path with https://docs.rs/dunce/latest/dunce/fn.simplified.html otherwise stripping the prefix may fail. I think for unix I would actually prefer if we just reverted to the old handling (no cannonicalization at all) to avoid the (on slow FS potentially significant) overhead. Other unix programs (like vim, nvim or emacs) don't handle this either. I think on unix the cases where this would be useful are extremely nieche. This is mainly important for windows (casefolding) |
Damn, Windows... I suggest adding |
I considered that but I do think the points I made to motivate this PR still apply for windows. We want helix to correctly handle symlinks on windows too (or more accurately similarly as unix). I do think what you implemented here is good enough for windows (except the detail I mentioned). You just need to feature gate the new parent and normal match arms and add the old implementation back (plus the use of different function I mentioned above) |
Wait what. How did I do it? I just pulled from master and rebased as usual 😅 |
6b628c8
to
17dd102
Compare
Closes #7458
If the file does not have a language detected but has a symbolic link, try using symlink file extension to set the language. This applies to opening new files as well as previewing them in the file picker.
Demo: https://asciinema.org/a/KISAzgMSh7ToTcZ3yKme5f0hA
I run the patched helix for the first time, where you can see at the bottom of the screen that the canonicalized path is a file with no extension (+ syntax hightlighting).
I am using the master helix for the second time (- syntax hightlighting)
TODO: