rust-lang / rust-lang/rust-analyzer
import suggestion chooses weirdly long private path
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: 0.4.2700-standalone and 0.3.2693-standalone
rustc version: rustc 1.93.0-nightly
editor or extension: vscode
relevant settings:
repository link (if public, optional):
code snippet to reproduce:
[package]
name = "world-stuff"
version = "0.1.0"
edition = "2024"
[dependencies]
godot = "0.4.3"
pub struct Foo {
v: Vector2,
}
Rust-analyzer now suggests to import Vector2 from the path godot::classes::class_macros::private::virtuals::Os::Vector2:
rather than the path godot::builtin::Vector2, which is what docs.rs shows as the top result when searching for Vector2 in the library. This is also strange since private is a module that has #[doc(hidden)] on it (see here). In fact, i don't think the path that RA suggests is even in the search results on docs.rs.
RA does properly auto-complete the path if i write it out manually however, i.e it will suggest builtin after typing use godot:: and Vector2 after typing use godot::builtin::Vec.
I've tried to make a minimum example, but im not entirely sure what exactly breaks it so i haven't been able to reproduce it outside of using the gdext library. However i have found a way to fix it by changing the gdext library:
inside of gdext, the Vector2 struct is ultimately exported like this:
// in builtin/mod.rs
#[doc(hidden)]
pub mod __prelude_reexport {
...
}
pub use __prelude_reexport::*;
If i remove that #[doc(hidden)] then RA does correctly suggest the path godot::builtin::Vector2. However it doesn't work anymore if i change it to:
mod builtin_reexport {
...
}
#[doc(hidden)]
pub mod __prelude_reexport {
pub use super::builtin_reexport::*;
}
pub use builtin_reexport::*;
It's also strange that it doesn't suggest godot::prelude::Vector2 either, since Vector2 is also re-exported there.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Cargo example in the issue and compare the import suggestions for Vector2. Read the re-export definitions in godot-core/src/builtin/mod.rs and the #[doc(hidden)] module in godot-core/src/lib.rs, then trace rust-analyzer's import suggestion handling for hidden re-exports. Done means the public godot::builtin::Vector2 or godot::prelude::Vector2 path is preferred over the private path, with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- godot, rust, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100