about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-10-07 09:04:41 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-10-07 09:04:41 +0000
commit1c0ec9f0c84e59cb6eda77fcb082f26c77566685 (patch)
treed78297b71be52552dee332769e353cc745911900
parenta415fb4c4e00da1b4138f5a7787ae9838e8ab576 (diff)
downloadrust-1c0ec9f0c84e59cb6eda77fcb082f26c77566685.tar.gz
rust-1c0ec9f0c84e59cb6eda77fcb082f26c77566685.zip
Fix go-to-def for `#[doc = include_str!("path")]`
-rw-r--r--crates/ide/src/doc_links.rs9
-rw-r--r--crates/ide/src/goto_definition.rs18
2 files changed, 25 insertions, 2 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index 92ce26b422e..d96827326cf 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -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() })
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index 7d8ef7ab9dc..f86ea61d158 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -1368,6 +1368,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(
             r#"