Skip to content

fix: filter the DOS device path prefix #16677

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

Closed
wants to merge 1 commit into from

Conversation

Tsuk1ha
Copy link

@Tsuk1ha Tsuk1ha commented Feb 26, 2024

fix #16666

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 26, 2024
@Proxtx
Copy link

Proxtx commented Feb 26, 2024

Looking at the code it feels a bit jank to join these two paths together. The rust compiler itself probably just opens the file since it is executed inside the src directory I presume. We however must resolve the path ourselves which leads to many edge cases. I would suggest calling fs::canonicalize in a subprocess where the working directory is set to the source directory. This would resolve basically all the issues. For example I have found this error which wouldn't be resolved as well: Screenshot 2024-02-26 134131.png
Basically loading a file from a network drive which the compiler accepts.

@Veykril
Copy link
Member

Veykril commented Feb 26, 2024

We intentionally do not use path canonicalization as that gives us a bunch of problems, see #14430 (comment)

@Proxtx
Copy link

Proxtx commented Feb 26, 2024

Is there a reason why we replace "\" with "/"? From my experience on windows a mix of "/" and "\" works fine.
Alternatively canonicalize could be used as a fallback.

@Tsuk1ha
Copy link
Author

Tsuk1ha commented Feb 26, 2024

gotcha!

@Tsuk1ha Tsuk1ha closed this Feb 26, 2024
@lnicola
Copy link
Member

lnicola commented Feb 26, 2024

Is there a reason why we replace "" with "/"?

I do wonder myself, CC @matklad.

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

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

Is there a reason why we replace "" with "/"? From my experience on windows a mix of "/" and "" works fine.
Alternatively canonicalize could be used as a fallback.

Perhaps a better question to ask is why this code doesn’t just use Path? The reason for that is that Path is platform specific: std::os::Path behaves differently on windows and Linux.

But we explicitly don’t want that in rust-analyzer: analysis is a pure function of the safe of the code, running rust-analyzer on a codebase should give exactly the same, determinist result irrespective of the host operating system.

So, we need to model our own Path in cross-platform way, and we do that by using String and normalizing path delimiters.

I think the code here predates introduction of

https://github.com/rust-lang/rust-analyzer/blob/master/crates/vfs/src/anchored_path.rs

anchored paths is probably the right abstraction we should be using here.

@@ -154,6 +154,14 @@ impl DirPath {
fn join_attr(&self, mut attr: &str, relative_to_parent: bool) -> String {
let base = if relative_to_parent { self.parent().unwrap() } else { &self.0 };

if cfg!(windows) {
Copy link
Member

Choose a reason for hiding this comment

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

There shouldn’t be any cfgs in the analysis parts of rust-analyzer.

A rust-analyzer server running on a Unix host should successfully analyzer code of a windows-only project.

Host operating system shouldn’t be an input to analysis.

If there’s some need to vary semantics of paths, it should be triggered by an explicit property of a Crate data structure stored in salsa database.

@matklad
Copy link
Member

matklad commented Feb 26, 2024

@Tsuk1ha
Copy link
Author

Tsuk1ha commented Feb 27, 2024

I will review the relevant code again, or maybe we should do nothing at all...

@Tsuk1ha Tsuk1ha deleted the fix-dos-device-path-prefix branch March 14, 2024 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

modding with absolute path disables autocomplete
6 participants