Skip to content

Rust: add extended_canonical_path and crate_origin to Item #17825

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

Merged
merged 7 commits into from
Oct 30, 2024

Conversation

redsun82
Copy link
Contributor

@redsun82 redsun82 commented Oct 23, 2024

This adds an internal extended_canonical_path and crate_origin property to all Items.

The former is the same as canonical paths, with the extension being that items defined in blocks get a {<block_id>} prefix. As these items can be referenced to within the scope in which they are visible, we will need such extension.

Building upon this, we can extract path resolution from rust-analyzer using this same format (in an upcoming PR).

One thing to notice is that those paths identify an entity only within a given crate. To allow for cross-crate references I've added
crate_origin, but that is just an experiment. It is something that rust-analyzer itself has, but we need to play around with to see if it's really useful. It might be we will need to insert crate root file paths and maybe CFG values in it for it to be meaningful for cross-crate dependencies, but this can be done in upcoming PRs.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Oct 23, 2024
@redsun82 redsun82 force-pushed the redsun82/rust-canonical-path branch 2 times, most recently from 8144f90 to e7c9003 Compare October 25, 2024 14:06
@redsun82 redsun82 force-pushed the redsun82/rust-canonical-path branch from 785aa4e to 719b5e1 Compare October 25, 2024 15:07
@redsun82 redsun82 changed the title Rust: add canonical_path and crate_origin to Item Rust: add extended_canonical_path and crate_origin to Item Oct 28, 2024
@redsun82 redsun82 marked this pull request as ready for review October 28, 2024 13:28
@@ -20,62 +23,30 @@ use ra_ap_syntax::{
#[macro_export]
macro_rules! emit_detached {
(MacroCall, $self:ident, $node:ident, $label:ident) => {
$self.extract_macro_call_expanded(&$node, $label.into());
$self.extract_macro_call_expanded(&$node, $label);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, if the into() here wasn't needed, why is it needed for all the other lines below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That function is only called on macros and macro labels. The other calls below accept an Item label, which is a super-type of the specific label being produced in the extractor and therefore requires the conversion.

Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@redsun82 redsun82 merged commit 7e8a09a into main Oct 30, 2024
14 checks passed
@redsun82 redsun82 deleted the redsun82/rust-canonical-path branch October 30, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants