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

autocomplete options does not appear #7897

Closed
patrickelectric opened this issue Mar 6, 2021 · 20 comments
Closed

autocomplete options does not appear #7897

patrickelectric opened this issue Mar 6, 2021 · 20 comments
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now

Comments

@patrickelectric
Copy link

I did a simple repository if someone wants to replicate the problem:
https://github.com/patrickelectric/vscode-autocomplete-problem/blob/master/src/main.rs#L7

In 3 different computers I was unable to make rust-analyzer to work with it.
I'm using rust-analyzer (v0.2.497) directly from vscodium (1.53.2).

image
image

@jonas-schievink
Copy link
Contributor

Does it work if you enable "load out dirs from check"?

@patrickelectric
Copy link
Author

I did try both rust-analyzer.cargo.loadOutDirsFromCheck and rust-analyzer.procMacro.enable without success

@lnicola lnicola added A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now labels Mar 7, 2021
@lnicola
Copy link
Member

lnicola commented Mar 7, 2021

Confirmed. Looks like some include! shenanigans might be going on, but I don't see anything out of the ordinary.

@lnicola
Copy link
Member

lnicola commented Mar 7, 2021

That's actually rust-analyzer.cargo.runBuildScripts (I thought it was enabled by default). But no, it doesn't help.

@patrickelectric
Copy link
Author

patrickelectric commented Mar 7, 2021

Reading the sourcing code and doing some debug from rust-analyzer, it appears that cargo environment variables are not supported at all.
https://github.com/rust-analyzer/rust-analyzer/blob/30402beeb200fe85bd7595a6a8e6efdb81ede2b5/crates/hir_expand/src/builtin_macro.rs#L434-L448

Taking a closer look on:
https://github.com/rust-analyzer/rust-analyzer/blob/30402beeb200fe85bd7595a6a8e6efdb81ede2b5/crates/hir_expand/src/builtin_macro.rs#L418-L421

My debug showed that it was always empty and there was nothing in db.crate_graph()[krate].env.

Doing research over cargo, it appears that cargo OUT_DIR variable may not be possible at all to get:
rust-lang/cargo#7546

For you that is reading this in the future, if you are generated stuff under OUT_DIR, it may be a good alternative to generated under a path such as src/generated, and with that you can do include! without using OUT_DIR, it will fix the autocomplete feature.

@jonas-schievink
Copy link
Contributor

mavlink does not seem to be using OUT_DIR

@jonas-schievink
Copy link
Contributor

Ah, this might be due to #7846

@patrickelectric
Copy link
Author

mavlink does not seem to be using OUT_DIR

I just changed it.

Though, projects that depends of rust-mavlink are still not working with that change, but inside the project the autocomplete now works.

rust-mavlink master branch:
image

It is still inconsistent, some time works and sometimes doesn't

example vscode-autocomplete-problem:
image

@flodiebold
Copy link
Member

@patrickelectric OUT_DIR should work fine as long as you've enabled rust-analyzer.cargo.loadOutDirsFromCheck (hence the name) or the new rust-analyzer.cargo.runBuildScripts.

@patrickelectric
Copy link
Author

It's enabled and not working:
image

rust-analyzer.cargo.runBuildScripts does not show here for me, I'm using the latest 0.2.487. Is that available somewhere to test ?

@bjorn3
Copy link
Member

bjorn3 commented Mar 7, 2021

rust-analyzer.cargo.loadOutDirsFromCheck is what it is called on the stable weekly builds. It has been renamed to rust-analyzer.cargo.runBuildScripts on nightly with the old name being accepted as alias.

@flodiebold
Copy link
Member

@patrickelectric what does cargo check --message-format=json | grep build-script-executed say?

@patrickelectric
Copy link
Author

@patrickelectric what does cargo check --message-format=json | grep build-script-executed say?

{"reason":"build-script-executed","package_id":"libc 0.2.88 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":["freebsd11","libc_priv_mod_use","libc_union","libc_const_size_of","libc_align","libc_core_cvoid","libc_packedN","libc_cfg_target_vendor"],"env":[],"out_dir":"/home/patrick/git/patrick/vscode-autocomplete-problem/target/debug/build/libc-cf127cddf224d515/out"} {"reason":"build-script-executed","package_id":"proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":["lexerror_display","hygiene","use_proc_macro","wrap_proc_macro"],"env":[],"out_dir":"/home/patrick/git/patrick/vscode-autocomplete-problem/target/debug/build/proc-macro2-3498c16925406714/out"} {"reason":"build-script-executed","package_id":"syn 1.0.62 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":["syn_disable_nightly_tests"],"env":[],"out_dir":"/home/patrick/git/patrick/vscode-autocomplete-problem/target/debug/build/syn-e4255a1c653518e2/out"} {"reason":"build-script-executed","package_id":"serde_derive 1.0.124 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":["underscore_consts"],"env":[],"out_dir":"/home/patrick/git/patrick/vscode-autocomplete-problem/target/debug/build/serde_derive-50d3257b96e1e96e/out"} {"reason":"build-script-executed","package_id":"serde 1.0.124 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":["ops_bound","core_reverse","de_boxed_c_str","de_boxed_path","de_rc_dst","core_duration","integer128","range_inclusive","num_nonzero","serde_derive","core_try_from","num_nonzero_signed","systemtime_checked_add","std_atomic64","std_atomic"],"env":[],"out_dir":"/home/patrick/git/patrick/vscode-autocomplete-problem/target/debug/build/serde-73ca5304cca9ae09/out"} {"reason":"build-script-executed","package_id":"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":["bitflags_const_fn"],"env":[],"out_dir":"/home/patrick/git/patrick/vscode-autocomplete-problem/target/debug/build/bitflags-f9113967e336fcbe/out"} {"reason":"build-script-executed","package_id":"num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":["has_i128","has_to_int_unchecked"],"env":[],"out_dir":"/home/patrick/git/patrick/vscode-autocomplete-problem/target/debug/build/num-traits-9247bc1ce3fdb48a/out"} {"reason":"build-script-executed","package_id":"mavlink 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":[],"env":[],"out_dir":"/home/patrick/git/patrick/vscode-autocomplete-problem/target/debug/build/mavlink-2f7d07fb4a9be9fc/out"}

@jonas-schievink
Copy link
Contributor

OUT_DIR is not the problem here, I suspect what's happening is that all include!s in src/generated/mod.rs fail to resolve due to #7846. This also explains why all submodules show up but are empty, since they're declared inline and use include! to pull in their content (mod should work just as well here though?).

@patrickelectric
Copy link
Author

mod should work just as well here though?

Yep, thanks for the feedback.
But it did not work, autocomplete is still not working:
patrickelectric/rust-mavlink@2a2a908

@jonas-schievink
Copy link
Contributor

Yes, the only way to work around this bug is to only generate a single file. Once #7846 is fixed, what you have now should start working as-is.

@edwin0cheng
Copy link
Member

edwin0cheng commented Mar 21, 2021

#7846 is fixed, and I tested in rust-mavlink project from master and it seem to work now. @patrickelectric could you test it again ?

mavlink-screenshot

@patrickelectric
Copy link
Author

Yep, I can confirm that it works, just downloaded https://github.com/rust-analyzer/rust-analyzer/releases/tag/2021-03-22 with:

  "rust-analyzer.cargo.runBuildScripts": true,
  "rust-analyzer.lruCapacity": 1024,
  "rust-analyzer.procMacro.enable": true,
  "rust-analyzer.cargo.allFeatures": true,

image

@patrickelectric
Copy link
Author

Thank you everybody for your patience and time!

@lnicola
Copy link
Member

lnicola commented Mar 22, 2021

Heads-up: build scripts and proc macros are now enabled by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

6 participants