yewstack / yewstack/yew

rust-analyzer cannot jump to the definition of components or attributes used inside of html!() macros

Open
#3,904 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
32.8k
Forks
1.5k
Avg merge
5h 34m
Merged PRs (30d)
2

Description

Problem
When hovering and ctrl-clicking a component inside of an html!() macro it doesn't pull up the definition of the component, instead it gives a laundry list of uses which seemingly includes many of the items used inside of the macro (see among other things references to core and std):

Image

Steps To Reproduce
Steps to reproduce the behavior:

  1. Take any yew project.
  2. ctrl-click on any component inside of an html!() macro.

Expected behavior
You should jump to the component.

Environment:

  • Yew version: master
  • Rust version: 1.89.0

Cause

The root cause of this is the spans being produced by the macro. Yew makes heavy used of respanning methods such as quote_spanned! and parse_quote_spanned!. Judging by the test cases (and running some of them) this is to improve ergonomics in error reporting.

Unfortunately this has the effect of the relevant identifier being hovered over having the span of presumably a much wider expression than the scope of the identifier, which confuses rust-analyzer.

I have a branch where I removed all respanning methods, and there I can jump to the definition of components, feel free to try it out: https://github.com/udoprog/yew/tree/remove-spans.

This is what I get with my branch (it cleanly jumps to the definition when clicked):

Image

In my branch, jumping to attributes almost works as well. It currently uses two definitions which seems to confuse rust-analyzer:

Image

In my mind, this is an important use case than improving error diagnostics, jumping to definition is something I attempt all the time, which is what caused me to investigate the issue and write this bug report.

Thank you!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the current macro span behavior with the remove-spans branch linked in the issue, focusing on quote_spanned! and parse_quote_spanned! usage in html!(). Reproduce component and attribute navigation in a Yew project with rust-analyzer. Done means components jump to their definitions and attributes resolve correctly without losing the error-reporting behavior the respanning was intended to provide.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.