mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Search raw identifiers without prefix
This commit is contained in:
parent
2a57b01980
commit
098d9d77b4
3 changed files with 33 additions and 10 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue