Bugfix: rust-analyzer can't resolve symbols in #[function_component] #3916
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem: When
yew-macrois sourced from a remote (crates.io or github),rust-analyzer"control-click" resolution of code inside#[function_component]definitions fails to resolve; instead, it resolves to the top of the mainyewcrate.Cause: Apparently, spans get mangled during cross-crate resolution when the crate is from a remote such as crates.io or github, etc. When
yew-macrois overridden with a local path patch in Cargo.toml, e.g.:even if the source is copied verbatim from the crates.io cache, this problem does not occur (at least on nightly), making reproduction for the yew authors difficult (because they are likely working on the workspace in the local filesystem in which case
rust-analyzerdoesn't seem to mangle the spans and resolution works?).Solution: anchor parse_quote_spanned! calls to their call sites.
Impact: fixes control-click editor navigation for all symbols in
#[function_component]bodies.Fixes #3904
Tested on
Checklist
rust-analyzerbehavior inside of an IDE. Instead of tests, I have added comments to the changes to indicate why they were changed.