Search raw identifiers without prefix

This commit is contained in:
Ryo Yoshida 2023-02-14 17:34:14 +09:00
parent 2a57b01980
commit 098d9d77b4
No known key found for this signature in database
GPG key ID: E25698A930586171
3 changed files with 33 additions and 10 deletions

View file

@ -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) {

View file

@ -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
"#]],
);
}
}

View file

@ -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,
},
],
},
},