-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add macro support in jump to definition feature #91264
Conversation
8d667cc
to
616da70
Compare
I won't have a chance to review this any time soon. r? @camelid |
I don't have knowledge of this code. r? rust-lang/rustdoc |
@jsha this is waiting for your review |
☔ The latest upstream changes (presumably #94139) made this pull request unmergeable. Please resolve the merge conflicts. |
616da70
to
427b31b
Compare
☔ The latest upstream changes (presumably #93803) made this pull request unmergeable. Please resolve the merge conflicts. |
I'll fix the conflict once #96636 is merged. |
#96636 is now merged. Can you put up a demo, including a demo of the "expands to empty" behavior you mentioned? |
427b31b
to
5613627
Compare
Here you go: https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html As for the empty macro issue that cannot create a jump to definition, you can see it here. |
I wonder why |
It's because the code tried to find it location based on its |
@bors retry |
…=jsha Add macro support in jump to definition feature Fixes rust-lang#91174. To do so, I check if the span comes from an expansion, and if so, I infer the original macro `DefId` or `Span` depending if it's a defined in the current crate or not. There is one limitation due to macro expansion though: ```rust macro_rules! yolo { () => {}} fn foo() { yolo!(); } ``` In `foo`, `yolo!` won't be linked because after expansion, it is replaced by nothing (which seems logical). So I can't get an item from the `Visitor` from which I could tell if its `Span` comes from an expansion. I added a test for this specific limitation alongside others. Demo: https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html As for the empty macro issue that cannot create a jump to definition, you can see it [here](https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html#35). r? `@jyn514`
…=jsha Add macro support in jump to definition feature Fixes rust-lang#91174. To do so, I check if the span comes from an expansion, and if so, I infer the original macro `DefId` or `Span` depending if it's a defined in the current crate or not. There is one limitation due to macro expansion though: ```rust macro_rules! yolo { () => {}} fn foo() { yolo!(); } ``` In `foo`, `yolo!` won't be linked because after expansion, it is replaced by nothing (which seems logical). So I can't get an item from the `Visitor` from which I could tell if its `Span` comes from an expansion. I added a test for this specific limitation alongside others. Demo: https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html As for the empty macro issue that cannot create a jump to definition, you can see it [here](https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html#35). r? ``@jyn514``
Rollup of 9 pull requests Successful merges: - rust-lang#91264 (Add macro support in jump to definition feature) - rust-lang#96955 (Remove (transitive) reliance on sorting by DefId in pretty-printer) - rust-lang#97633 (Session object: Set OS/ABI) - rust-lang#98039 (Fix `panic` message for `BTreeSet`'s `range` API and document `panic` cases) - rust-lang#98214 (rustc_target: Remove some redundant target properties) - rust-lang#98280 (Improve suggestion for calling fn-like expr on type mismatch) - rust-lang#98394 (Fixup missing renames from `#[main]` to `#[rustc_main]`) - rust-lang#98411 (Update tendril) - rust-lang#98419 (Remove excess rib while resolving closures) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…eGomez rustdoc: simplify highlight.rs Split render_with_highlighting, which took many optional parameters, into three functions for specific purposes, which each take a smaller number of mostly required parameters. Remove some plumbing to pass through an "edition" parameter, which was used solely to avoid highlighting some 2021 Edition keywords in non-2021 code. I've tested a build of std docs before and after, and this does not change the generated HTML at all. Followup from rust-lang#91264 (comment) r? `@GuillaumeGomez`
…eGomez rustdoc: simplify highlight.rs Split render_with_highlighting, which took many optional parameters, into three functions for specific purposes, which each take a smaller number of mostly required parameters. Remove some plumbing to pass through an "edition" parameter, which was used solely to avoid highlighting some 2021 Edition keywords in non-2021 code. I've tested a build of std docs before and after, and this does not change the generated HTML at all. Followup from rust-lang#91264 (comment) r? ``@GuillaumeGomez``
…eGomez rustdoc: simplify highlight.rs Split render_with_highlighting, which took many optional parameters, into three functions for specific purposes, which each take a smaller number of mostly required parameters. Remove some plumbing to pass through an "edition" parameter, which was used solely to avoid highlighting some 2021 Edition keywords in non-2021 code. I've tested a build of std docs before and after, and this does not change the generated HTML at all. Followup from rust-lang#91264 (comment) r? ```@GuillaumeGomez```
rustdoc: simplify highlight.rs Split render_with_highlighting, which took many optional parameters, into three functions for specific purposes, which each take a smaller number of mostly required parameters. Remove some plumbing to pass through an "edition" parameter, which was used solely to avoid highlighting some 2021 Edition keywords in non-2021 code. I've tested a build of std docs before and after, and this does not change the generated HTML at all. Followup from rust-lang/rust#91264 (comment) r? ``@GuillaumeGomez``
rustdoc: simplify highlight.rs Split render_with_highlighting, which took many optional parameters, into three functions for specific purposes, which each take a smaller number of mostly required parameters. Remove some plumbing to pass through an "edition" parameter, which was used solely to avoid highlighting some 2021 Edition keywords in non-2021 code. I've tested a build of std docs before and after, and this does not change the generated HTML at all. Followup from rust-lang/rust#91264 (comment) r? ``@GuillaumeGomez``
Fixes #91174.
To do so, I check if the span comes from an expansion, and if so, I infer the original macro
DefId
orSpan
depending if it's a defined in the current crate or not.There is one limitation due to macro expansion though:
In
foo
,yolo!
won't be linked because after expansion, it is replaced by nothing (which seems logical). So I can't get an item from theVisitor
from which I could tell if itsSpan
comes from an expansion.I added a test for this specific limitation alongside others.
Demo: https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html
As for the empty macro issue that cannot create a jump to definition, you can see it here.
r? @jyn514