Skip to content
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

Can Rust Analyzer Not Handle Build.rs Generated Source Files? #7400

Closed
zicklag opened this issue Jan 22, 2021 · 4 comments
Closed

Can Rust Analyzer Not Handle Build.rs Generated Source Files? #7400

zicklag opened this issue Jan 22, 2021 · 4 comments
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@zicklag
Copy link

zicklag commented Jan 22, 2021

I have a crate that generates a Rust src file in the build.rs and then include!'s it in the lib.rs file. This works great for cargo build, but the rust analyzer seems to not be able to get the auto-complete for it correctly:

It gets the Project, top level type which is hard-coded into the struct:

image

But it can't get any of it's fields figured out:

image

I'm guessing that using a proc macro to generate the code instead of include!-ing the source file would probably fix it, and I'm going to try that out, but I wanted to make sure you guys didn't have any pointers first. Thanks!

@lnicola
Copy link
Member

lnicola commented Jan 22, 2021

Did you enable rust-analyzer.cargo.loadOutDirsFromCheck?

@lnicola lnicola added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Jan 22, 2021
@zicklag
Copy link
Author

zicklag commented Jan 22, 2021

Ah, that fixed it! Thanks for the quick response. I always wondered what that setting was actually for. Would you be open to me adding some more description such as "Needed for autocomplete for some crates that generate source files in the cargo OUT_DIR"?

Am I right in my understanding that it would work fine if I used a proc macro? I might just do that if it helps users not having to be aware of this edge case. Especially being that that option is off by default. Would it make sense to make that option enabled by default?

@lnicola
Copy link
Member

lnicola commented Jan 22, 2021

Proc macros are also off by default, so no. And a build script seems like the better solution here.

The plan is to enable both by default in #7328 and that will probably include cleaning up the config name and description. A PR for that would be appreciated, of course.

Let's close this in the meantime, though.

@lnicola lnicola closed this as completed Jan 22, 2021
@zicklag
Copy link
Author

zicklag commented Jan 22, 2021

Sounds great! I'll update the option description, and I'm happy that I can just use a build script for my crate. 🙂 Thanks again for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

2 participants