Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 098d9d7

Browse files
committed
Search raw identifiers without prefix
1 parent 2a57b01 commit 098d9d7

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

crates/ide-db/src/search.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,20 @@ impl<'a> FindUsages<'a> {
455455
}
456456

457457
let find_nodes = move |name: &str, node: &syntax::SyntaxNode, offset: TextSize| {
458-
node.token_at_offset(offset).find(|it| it.text() == name).map(|token| {
459-
// FIXME: There should be optimization potential here
460-
// Currently we try to descend everything we find which
461-
// means we call `Semantics::descend_into_macros` on
462-
// every textual hit. That function is notoriously
463-
// expensive even for things that do not get down mapped
464-
// into macros.
465-
sema.descend_into_macros(token).into_iter().filter_map(|it| it.parent())
466-
})
458+
node.token_at_offset(offset)
459+
.find(|it| {
460+
// `name` is stripped of raw ident prefix. See the comment on name retrieval above.
461+
it.text().trim_start_matches("r#") == name
462+
})
463+
.map(|token| {
464+
// FIXME: There should be optimization potential here
465+
// Currently we try to descend everything we find which
466+
// means we call `Semantics::descend_into_macros` on
467+
// every textual hit. That function is notoriously
468+
// expensive even for things that do not get down mapped
469+
// into macros.
470+
sema.descend_into_macros(token).into_iter().filter_map(|it| it.parent())
471+
})
467472
};
468473

469474
for (text, file_id, search_range) in scope_files(sema, &search_scope) {

crates/ide/src/references.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,4 +2016,19 @@ fn method$0() {}
20162016
"#]],
20172017
);
20182018
}
2019+
2020+
#[test]
2021+
fn raw_identifier() {
2022+
check(
2023+
r#"
2024+
fn r#fn$0() {}
2025+
fn main() { r#fn(); }
2026+
"#,
2027+
expect![[r#"
2028+
r#fn Function FileId(0) 0..12 3..7
2029+
2030+
FileId(0) 25..29
2031+
"#]],
2032+
);
2033+
}
20192034
}

crates/ide/src/rename.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,6 @@ pub fn baz() {}
13711371

13721372
#[test]
13731373
fn test_rename_mod_from_raw_ident() {
1374-
// FIXME: `r#fn` in path expression is not renamed.
13751374
check_expect(
13761375
"foo",
13771376
r#"
@@ -1397,6 +1396,10 @@ pub fn baz() {}
13971396
insert: "foo",
13981397
delete: 4..8,
13991398
},
1399+
Indel {
1400+
insert: "foo",
1401+
delete: 23..27,
1402+
},
14001403
],
14011404
},
14021405
},

0 commit comments

Comments
 (0)