Skip to content

Conversation

@xffxff
Copy link
Contributor

@xffxff xffxff commented Sep 16, 2021

Implement #10070 in goto_definition

@xffxff xffxff changed the title fix: multi-token mapping aware goto definition fix: make goto_definition multi-token mapping aware Sep 16, 2021
@xffxff
Copy link
Contributor Author

xffxff commented Sep 17, 2021

@Veykril Please take a look.

Comment on lines 43 to 65
let navs = tokens
.clone()
.into_iter()
.filter_map(|token| {
let parent = token.parent()?;
if let Some(_) = ast::Comment::cast(token.clone()) {
let (attributes, def) = doc_attributes(&sema, &parent)?;
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
let (_, link, ns) =
extract_definitions_from_docs(&docs).into_iter().find(|&(range, ..)| {
doc_mapping.map(range).map_or(false, |InFile { file_id, value: range }| {
file_id == position.file_id.into() && range.contains(position.offset)
})
})?;
let nav = resolve_doc_path_for_def(db, def, &link, ns)?.try_to_nav(db)?;
return Some(nav);
}
None
})
.collect::<Vec<NavigationTarget>>();
if navs.len() > 0 {
return Some(RangeInfo::new(original_token.text_range(), navs));
}
Copy link
Member

@Veykril Veykril Sep 17, 2021

Choose a reason for hiding this comment

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

I just realized, this extra comment logic actually doesn't work for comments inside macros currently so instead of doing this you can just do this special comment handling once on the original token and if that fails just do the token descending as planned.
That should simplify things.

Copy link
Contributor Author

@xffxff xffxff Sep 18, 2021

Choose a reason for hiding this comment

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

I just realized, this extra comment logic actually doesn't work for comments inside macros currently

Do you mean this?

macro_rules! foo_macro {
    ($(#[$attr:meta])* $name:ident) => {
        $(#[$attr])*
        pub struct $name;
    }
}

foo_macro!(
    /// Doc comment for [`Foo$0`]
    Foo
 // ^^^
);

@xffxff xffxff force-pushed the goto_definition_multi_token branch from 5bb9949 to 227450f Compare September 18, 2021 00:22
@Veykril
Copy link
Member

Veykril commented Sep 18, 2021

Yep, that was the case I meant 👍
Thanks
bors r+

@bors
Copy link
Contributor

bors bot commented Sep 18, 2021

@bors bors bot merged commit a435e49 into rust-lang:master Sep 18, 2021
@xffxff xffxff deleted the goto_definition_multi_token branch September 18, 2021 01:43
@lnicola
Copy link
Member

lnicola commented Sep 18, 2021

changelog fix (first contribution) make goto_definition multi-token mapping aware

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