Skip to content

Commit 8437e4b

Browse files
committed
Auto merge of rust-lang#13362 - WaffleLapkin:go_to_def_fix_doc_include_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`.
2 parents a415fb4 + 1c0ec9f commit 8437e4b

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

crates/ide/src/doc_links.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,13 @@ pub(crate) fn token_as_doc_comment(doc_token: &SyntaxToken) -> Option<DocComment
232232
(match_ast! {
233233
match doc_token {
234234
ast::Comment(comment) => TextSize::try_from(comment.prefix().len()).ok(),
235-
ast::String(string) => doc_token.parent_ancestors().find_map(ast::Attr::cast)
236-
.filter(|attr| attr.simple_name().as_deref() == Some("doc")).and_then(|_| string.open_quote_text_range().map(|it| it.len())),
235+
ast::String(string) => {
236+
doc_token.parent_ancestors().find_map(ast::Attr::cast).filter(|attr| attr.simple_name().as_deref() == Some("doc"))?;
237+
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() {
238+
return None;
239+
}
240+
string.open_quote_text_range().map(|it| it.len())
241+
},
237242
_ => None,
238243
}
239244
}).map(|prefix_len| DocCommentToken { prefix_len, doc_token: doc_token.clone() })

crates/ide/src/goto_definition.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,24 @@ fn main() {
13671367
);
13681368
}
13691369

1370+
#[test]
1371+
fn goto_doc_include_str() {
1372+
check(
1373+
r#"
1374+
//- /main.rs
1375+
#[rustc_builtin_macro]
1376+
macro_rules! include_str {}
1377+
1378+
#[doc = include_str!("docs.md$0")]
1379+
struct Item;
1380+
1381+
//- /docs.md
1382+
// docs
1383+
//^file
1384+
"#,
1385+
);
1386+
}
1387+
13701388
#[test]
13711389
fn goto_shadow_include() {
13721390
check(

0 commit comments

Comments
 (0)