-
-
Couldn't load subscription status.
- Fork 1.4k
Bugfix: rust-analyzer can't resolve symbols in #[function_component] #3916
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
base: master
Are you sure you want to change the base?
Conversation
using remote yew-macro crate from crates.io or github. Cause: spans get mangled during cross-crate resolution. Solution: anchor parse_quote_spanned! calls to their call sites. Impact: fixes control-click editor navigation for all symbols in
|
Visit the preview URL for this PR (updated for commit 74fee05): https://yew-rs-api--pr3916-fix-analyzer-master-zfyo9fyc.web.app (expires Sun, 07 Sep 2025 01:55:42 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew Master
Pull Request
|
Size Comparison
✅ None of the examples has changed their size significantly. |
|
It doesn't seem to fix anything for me on linux. Although I use neovim, I also have a "go to definition" action provided by rust-analyzer. And I can trigger it by control-clicking too. (It seems like the action is allowed to provide more than one option because my ui shows a list of dozen options, in which some weird ones like "yew root" and "std root" exist. And control clicking leads me to a random one). I tried this minimum code: use yew::prelude::*;
#[function_component]
pub fn Foo() -> Html {
html! {
<Bar />
}
}
#[function_component]
pub fn Bar() -> Html {
html! {
}
}in one repo, with [dependencies]
yew = { git = "https://github.com/yewstack/yew", branch = "master", features = ["csr"] }in the other with [dependencies]
yew = { git = "https://github.com/dra11y/yew.git", branch = "master", features = ["csr"] }In both cases, the control click destination and the list on I was using |
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.