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

fix: Rust-Analyzer hover information / redundant spans #2836

Merged
merged 1 commit into from
Aug 17, 2024

Conversation

chrisp60
Copy link
Contributor

These changes hope to improve (I wish I could say fix, but I'm not entirely sure yet) the recent issues that the view! and #[component] macros had with providing incorrect / extra information through Rust-Analyzer.

In many instances, the procedural macros are spanning tokens with their own span redundantly, while also including lint attributes and unrelated tokens within their spanned interpolation.

I am far from an expert on procedural macros and token spans, while this seems to fix the issues on my editor, I just don't know enough to say if it actually fixes everything. From what I can tell, no diagnostic information is lost from these changes.

Additionally, I have no idea how to write a test for this. I am open to doing additional work to research and write tests if needed.

@benwis
Copy link
Contributor

benwis commented Aug 14, 2024

Is this at all related to this PR: #2835 ?

@chrisp60
Copy link
Contributor Author

Is this at all related to this PR: #2835 ?

I believe entirely unrelated. My changes are around the builder pattern that is constructed in the view macro, theirs is about the #[component] definition.

@chrisp60
Copy link
Contributor Author

There are pictures available on #2840 that mostly show the improvements. Obviously the code is different but the results are visually similar

Per https://docs.rs/quote/latest/quote/macro.quote.html#hygiene
regarding token hygiene.

> Any interpolated tokens preserve the Span information provided by their
> `ToTokens` implementation.

In many instances, the procedural macros are spanning tokens with their
own span redundantly.
@chrisp60 chrisp60 force-pushed the fix-proc-macro-spans-ra branch from 78d6c86 to e76b759 Compare August 15, 2024 19:41
@gbj
Copy link
Collaborator

gbj commented Aug 17, 2024

Thanks very much! Yes, as I understand it #2289 introduced some of these, but rust-analyzer later made changes that caused overlapping spans to break. Thank you for working to clean up the issue.

@gbj gbj merged commit fcdfd61 into leptos-rs:main Aug 17, 2024
64 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants