Autocomplete breaks inside macro
rust-analyzer version: v0.3.1091 rustc version: 1.61 relevant settings: None, clean install
In my project I have several files that define logic via closures stored within vectors. The structure of the code roughly looks like this:
pub fn gold_mine() -> CardDefinition {
CardDefinition {
name: CardName::GoldMine,
abilities: vec![
simple_ability(
at_dusk(|g, s, _| {
mutations::take_stored_mana(g, s.card_id(), 3, OnZeroStored::Sacrifice)?;
Ok(())
}),
),
],
config: CardConfig::default(),
}
}
Autocomplete via rust analyzer breaks within these closures in all of the files in my project. It works as expected outside of them.
This reproduces for me in a brand new installation of ubuntu 22.04 running Visual Studio Code and rust-analyzer. You should be able to reproduce it via:
git clone https://github.com/thurn/Spelldawn.git
git checkout 2ed24d0 (the exact point of the screenshot above)
rm .cargo/config.toml (if you don't have the lld linker installed, but the issue reproduces either way)
cargo build
open crates/cards/src/projects.rs (or any file in this directory really)
attempt to use auto-complete inside one of the closures, e.g. on line 43
This also reproduced for me on Mac OSX.
Hm. Can you try writing such a closure outside the vec! macro and seeing whether completion works there? I suspect this might be a problem with macro error resilience.
Edit: Yeah, I checked myself. This isn't related to the closure, but rather to being in a macro call with some other tokens following. E.g. if you have at_dusk(|q, s, _| { mutations::ta }) it actually works, but if you have at_dusk(|q, s, _| { mutations::ta mutations::take_stored_mana(); }) the macro fails to expand, so no completions. We should try to do better there.
I'm not sure if this is the same problem but I also lose auto-complete of some variable names when trying to access the variable from multiple threads and loops. The code still compiles so it's not a logic error or borrowing problem. I get normal auto-complete functionality after typing the entire variable name. It seems it just can't find the variable name in the first place. The original rust-lang support is able to find the variable name but then fails when looking for the functions associated with the variable. I have found the best solution for me is to use both rust-lang and RA at the same time to maximize code completion. However I noticed that I get duplicate code hints when doing this.
Thank you for your time! Rust is really amazing :)
@frozenranger From your description, I can't really tell what the problem is. Can you open a new issue and provide a code example? I would not recommend using RLS and RA at the same time.
- src/macro_rules/overload.rs
#[macro_export]
macro_rules! test {
($left:expr; and $right:expr) => {
println!("{:?} and {:?} is {:?}", stringify!($left), stringify!($right), $left && $right)
};
($left:expr; or $right:expr) => {
println!("{:?} or {:?} is {:?}", stringify!($left), stringify!($right), $left || $right)
};
}
- src/main.rs mod macro_rules
When I create custom macro, auto complete does not work about even "println!'.
I can reproduce this issue on NeoVim and VSCode r-a.
https://github.com/rust-lang/rust-analyzer/assets/138601092/5b36b1c6-07ca-406d-8c97-8ef6cd927e83
it seems to only break for the first "level" of a module
For example Utc:: would produce autocomplete list outside of the query! macro
But inside the macros it produces nothing
@DanCookeWillow I managed to work around this by disabling macro call expansion (one line change)
https://github.com/darsto/rust-analyzer/commit/b84a959560b8657c28cf37cc8119f44fef6b7a8a
@darsto I can't see any way this change would affect autocompletion. This method isn't even anywhere in the call chain for completion, and is unrelated to actual macro expansion. Also, actually disabling macro call expansion would not make completion in function-like macro calls work, because rust-analyzer wouldn't be able to interpret them at all then.
@flodiebold Hm I might have assed something in my tests then. Please ignore
Heya, any updates on this? Also ran into this issue with rust-analyzer