-
Notifications
You must be signed in to change notification settings - Fork 441
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
rust_analyzer: unpredictable/broken behavior with generated sources #3126
Comments
- deterministically prefer rust_library's crate spec over rust_test's. This means root_module gets remapped to a workspace path more often, and fixes flakiness of generated_srcs_test. - document the reasons and tradeoffs for this remapping. - stop adding `include_dirs` when remapping, it doesn't do anything to help with this problem, and is confusing. - fix test to strictly assert the path, which I broke in 74f164b Partially fixes bazelbuild#3126
#3127 attempts to stabilize/document the current situation. |
We're having the same issue(s) as we use a lot of generated code in our repo. I pushed #3040 a while ago to "fix" what was most irritating to me at least: that nothing works if you randomly get the buildroot path as |
At a3778c5, the rust-analyzer generated_srcs_test fails on my machine, complaining about missing
source.include_dirs
:log
Running the aspect by hand shows there are two crate specs produced, one for the library and one for the test:
lib.rs
from a generated file to a source file insrcs
, and so has a__WORKSPACE__
path with asource.include_dir
under__EXEC_ROOT__
.srcs
here), and root_module has a__EXEC_ROOT__
path with nosource.include_dir
.generated_srcs.json
generated_srcs_test.json
Digging deeper into this, it seems both are broken, and it's not clear that making the test pass is a real fix.
rust_library
will generate extra symlinks so all files are in the generated tree.rust-project.json
describes a crate rooted atblaze-out/gen/foo.rs
, but you openworkspace/foo.rs
in your editor, rust-analyzer doesn't know it's the same file.workspace/foo.rs
and seepub mod generated
, rust-analyzer looks forworkspace/generated.rs
, and can't find it, because it's actuallyblaze-out/gen/generated.rs
.So if we don't remap the path, we get a
rust-project.json
that "works" if you open all the files through their generated locations, but rust-analyzer doesn't know which crates your regular source files belong to.If we do remap the path, we get a
rust-project.json
where rust-analyzer knows which crates your files are part of, but can't actually understand them because generated files are missing.(The existing logic tries to point
include_dirs
to the generated directory when there might be sources there, but I don't think this actually achieves anything: this isn't a C-style#include
path, rather each module is resolved relative to the current one.)I'm not really sure what to do about this. If we have to choose, there are arguments for either behavior:
Maybe there's a clean solution that someone smarter than me can find...
The text was updated successfully, but these errors were encountered: