rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.2k stars 1.59k forks source link

modding with absolute path disables autocomplete #16666

Open Proxtx opened 8 months ago

Proxtx commented 8 months ago

rust-analyzer version: 0.3.1850-standalone (68c506fd6 2024-02-19) rustc version: rustc 1.77.0-nightly (30dfb9e04 2024-01-14)

I'm writing a build script that automatically mods some other files. The build script generates it's output to some directory which then is included with the include! macro. The main file behaves correcty, the autocomplete treats the injected code as if the include macro didn't exist (which is expected). In the included files compile-errors are displayed correctly as well. Just autocomplete is not working. When modding the file manually in main.rs autocomplete starts working. Note that the modded file is in a different directory than src (still within the same vscode session tho)

flodiebold commented 7 months ago

Can you provide a reproduction?

Proxtx commented 7 months ago

It seems like I have misunderstood what the cause of the bug is: It's not because of the include macro. The actual cause seems to be the absolute path which is generated by the build script. Hardcoding a absolute path into the main.rs yields the same result with the error message: "unresolved module, can't find module file" even tho cargo run does not complain about that. Demo Repo: https://github.com/Proxtx/rust_analyzer_bug_report.git

Hanamiyuzu commented 7 months ago

@rustbot claim

Hanamiyuzu commented 7 months ago

Once the mod path cannot be found in the collection, it will immediately return None, perhaps a more lenient check can be performed as a fallback (such as comparing the file metadata pointed to by the path)

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

@Veykril What do you think?

Veykril commented 7 months ago

No I don't think that would be right. I'm inclined to label this as a wont-fix for now until we rewrite our VFS, as the macro / build script should probably generate a relative path instead. In similar to our shortcoming with mod path overrides that leave the directory of the crate they are in. Our VFS is not written in mind to handle these kinds of cases and trying to bolt that onto it in some way won't really make it work.

Hanamiyuzu commented 7 months ago

@rustbot release-assignment