about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRyo Yoshida <low.ryoshida@gmail.com>2023-02-14 17:34:14 +0900
committerRyo Yoshida <low.ryoshida@gmail.com>2023-02-14 17:34:14 +0900
commit098d9d77b45749aeb7514c1cea2b750791ead85e (patch)
tree8a98d8cf9aa3d7a85d0b595cad4b22e5aeb6e881
parent2a57b019808370d6b4d95a7e7dae354fe12de9db (diff)
downloadrust-098d9d77b45749aeb7514c1cea2b750791ead85e.tar.gz
rust-098d9d77b45749aeb7514c1cea2b750791ead85e.zip
Search raw identifiers without prefix
-rw-r--r--crates/ide-db/src/search.rs23
-rw-r--r--crates/ide/src/references.rs15
-rw-r--r--crates/ide/src/rename.rs5
3 files changed, 33 insertions, 10 deletions
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index ada2821d6b1..d09c91942f2 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -455,15 +455,20 @@ impl<'a> FindUsages<'a> {
         }
 
         let find_nodes = move |name: &str, node: &syntax::SyntaxNode, offset: TextSize| {
-            node.token_at_offset(offset).find(|it| it.text() == name).map(|token| {
-                // FIXME: There should be optimization potential here
-                // Currently we try to descend everything we find which
-                // means we call `Semantics::descend_into_macros` on
-                // every textual hit. That function is notoriously
-                // expensive even for things that do not get down mapped
-                // into macros.
-                sema.descend_into_macros(token).into_iter().filter_map(|it| it.parent())
-            })
+            node.token_at_offset(offset)
+                .find(|it| {
+                    // `name` is stripped of raw ident prefix. See the comment on name retrieval above.
+                    it.text().trim_start_matches("r#") == name
+                })
+                .map(|token| {
+                    // FIXME: There should be optimization potential here
+                    // Currently we try to descend everything we find which
+                    // means we call `Semantics::descend_into_macros` on
+                    // every textual hit. That function is notoriously
+                    // expensive even for things that do not get down mapped
+                    // into macros.
+                    sema.descend_into_macros(token).into_iter().filter_map(|it| it.parent())
+                })
         };
 
         for (text, file_id, search_range) in scope_files(sema, &search_scope) {
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 60fb1544a8f..cabbc287279 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -2016,4 +2016,19 @@ fn method$0() {}
             "#]],
         );
     }
+
+    #[test]
+    fn raw_identifier() {
+        check(
+            r#"
+fn r#fn$0() {}
+fn main() { r#fn(); }
+"#,
+            expect![[r#"
+                r#fn Function FileId(0) 0..12 3..7
+
+                FileId(0) 25..29
+            "#]],
+        );
+    }
 }
diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs
index 8e89160ef5e..c0237e1edd0 100644
--- a/crates/ide/src/rename.rs
+++ b/crates/ide/src/rename.rs
@@ -1371,7 +1371,6 @@ pub fn baz() {}
 
     #[test]
     fn test_rename_mod_from_raw_ident() {
-        // FIXME: `r#fn` in path expression is not renamed.
         check_expect(
             "foo",
             r#"
@@ -1397,6 +1396,10 @@ pub fn baz() {}
                                     insert: "foo",
                                     delete: 4..8,
                                 },
+                                Indel {
+                                    insert: "foo",
+                                    delete: 23..27,
+                                },
                             ],
                         },
                     },