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 seems broken by a LazyLock + conditional crate paths #18798

Closed
alice-i-cecile opened this issue Dec 30, 2024 · 7 comments
Closed
Labels
C-bug Category: bug

Comments

@alice-i-cecile
Copy link

rust-analyzer version: rust-analyzer 1.83.0 (90b35a6 2024-11-26)

rustc version: 1.83

editor or extension: VsCode

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): bevyengine/bevy@760d0a3, which is the commit that broke this.

code snippet to reproduce:

use bevy::prelude::*;

fn my_system(query: Query<&Transform>){
    for transform in query.iter(){
      // Autocomplete should show up here, showing the various fields etc.
       transform
   } 
}

First detected in bevyengine/bevy#17004. We can probably work around this, but this seems to be an RA bug.

@alice-i-cecile alice-i-cecile added the C-bug Category: bug label Dec 30, 2024
@alice-i-cecile alice-i-cecile changed the title Autocomplete seems broken by a LazyLock Autocomplete seems broken by a LazyLock + conditional crate paths Dec 30, 2024
@ChayimFriedman2
Copy link
Contributor

I'm trying to understand what's the role of the LazyLock here. Is it created in a bad state in which proc macros expand to something not completeable, then after edits becomes good?

@alice-i-cecile
Copy link
Author

@mockersf @raldone01 may have better hypotheses than I do here about what's going on: bevyengine/bevy#16766 was the offending PR.

@ChayimFriedman2
Copy link
Contributor

I tried and I'm getting completions normally (Windows), both in 0.15.0 and in this commit.

@raldone01
Copy link

raldone01 commented Dec 30, 2024

I can look into it in the new year.

I will try to reproduce it on my machines.

Seems very weird.
I just read: bevyengine/bevy#17004

Seems like RA keeps the proc macros instantiated across crates which rustc does not.

@ChayimFriedman2
Copy link
Contributor

Indeed it does, because r-a analyzes all crates at once while rustc compiles one crate at a time. In general proc macros should not rely on external state, and their behavior if they do is non-guaranteed, even in rustc. So if this is the problem I believe it's working as intended.

@Veykril
Copy link
Member

Veykril commented Dec 31, 2024

rust-analyzer caches proc-macro expansions unlike rustc, it also doesn't unload the library unlike rustc. You generally cannot assume when and how often a proc-macro gets re-executed. The only thing you may assume is the environment (env vars, working directory) which is also not ideal but cargo is not going to change the working directory anymore now (the breakage would be too severe if they tried).

@alice-i-cecile
Copy link
Author

Awesome, thanks for the help and feedback :) I'm happy to call this an "us problem"; I hope this thread helps some poor soul years down the line.

@alice-i-cecile alice-i-cecile closed this as not planned Won't fix, can't repro, duplicate, stale Dec 31, 2024
raldone01 added a commit to ink-feather-org/cargo-manifest-proc-macros-rs that referenced this issue Jan 1, 2025
* Fixed a bug where rust analyser would resolve the crate paths incorrectly due to caching of `'static` lifetimes.
  See [rust-analyzer#18798](rust-lang/rust-analyzer#18798) and [bevy#17004](bevyengine/bevy#17004).
raldone01 added a commit to ink-feather-org/cargo-manifest-proc-macros-rs that referenced this issue Jan 1, 2025
* Fixed a bug where rust analyser would resolve the crate paths incorrectly due to caching of `'static` lifetimes.
  See [rust-analyzer#18798](rust-lang/rust-analyzer#18798) and [bevy#17004](bevyengine/bevy#17004).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants