Skip to content

Commit

Permalink
Auto merge of rust-lang#13362 - WaffleLapkin:go_to_def_fix_doc_includ…
Browse files Browse the repository at this point in the history
…e_str, r=Veykril

fix: Make go-to-def work for `#[doc = include_str!("path")]`

See the added test, go-to-def on `#[doc = include_str!("path$0")]` should navigate to `path`.
  • Loading branch information
bors committed Oct 7, 2022
2 parents a415fb4 + 1c0ec9f commit 8437e4b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/ide/src/doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@ pub(crate) fn token_as_doc_comment(doc_token: &SyntaxToken) -> Option<DocComment
(match_ast! {
match doc_token {
ast::Comment(comment) => TextSize::try_from(comment.prefix().len()).ok(),
ast::String(string) => doc_token.parent_ancestors().find_map(ast::Attr::cast)
.filter(|attr| attr.simple_name().as_deref() == Some("doc")).and_then(|_| string.open_quote_text_range().map(|it| it.len())),
ast::String(string) => {
doc_token.parent_ancestors().find_map(ast::Attr::cast).filter(|attr| attr.simple_name().as_deref() == Some("doc"))?;
if doc_token.parent_ancestors().find_map(ast::MacroCall::cast).filter(|mac| mac.path().and_then(|p| p.segment()?.name_ref()).as_ref().map(|n| n.text()).as_deref() == Some("include_str")).is_some() {
return None;
}
string.open_quote_text_range().map(|it| it.len())
},
_ => None,
}
}).map(|prefix_len| DocCommentToken { prefix_len, doc_token: doc_token.clone() })
Expand Down
18 changes: 18 additions & 0 deletions crates/ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,24 @@ fn main() {
);
}

#[test]
fn goto_doc_include_str() {
check(
r#"
//- /main.rs
#[rustc_builtin_macro]
macro_rules! include_str {}
#[doc = include_str!("docs.md$0")]
struct Item;
//- /docs.md
// docs
//^file
"#,
);
}

#[test]
fn goto_shadow_include() {
check(
Expand Down

0 comments on commit 8437e4b

Please sign in to comment.