-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
8144f90
to
e7c9003
Compare
785aa4e
to
719b5e1
Compare
canonical_path
and crate_origin
to Item
extended_canonical_path
and crate_origin
to Item
@@ -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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
This adds an internal
extended_canonical_path
andcrate_origin
property to allItem
s.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.