mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +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| {
|
let find_nodes = move |name: &str, node: &syntax::SyntaxNode, offset: TextSize| {
|
||||||
node.token_at_offset(offset).find(|it| it.text() == name).map(|token| {
|
node.token_at_offset(offset)
|
||||||
// FIXME: There should be optimization potential here
|
.find(|it| {
|
||||||
// Currently we try to descend everything we find which
|
// `name` is stripped of raw ident prefix. See the comment on name retrieval above.
|
||||||
// means we call `Semantics::descend_into_macros` on
|
it.text().trim_start_matches("r#") == name
|
||||||
// every textual hit. That function is notoriously
|
})
|
||||||
// expensive even for things that do not get down mapped
|
.map(|token| {
|
||||||
// into macros.
|
// FIXME: There should be optimization potential here
|
||||||
sema.descend_into_macros(token).into_iter().filter_map(|it| it.parent())
|
// 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) {
|
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]
|
#[test]
|
||||||
fn test_rename_mod_from_raw_ident() {
|
fn test_rename_mod_from_raw_ident() {
|
||||||
// FIXME: `r#fn` in path expression is not renamed.
|
|
||||||
check_expect(
|
check_expect(
|
||||||
"foo",
|
"foo",
|
||||||
r#"
|
r#"
|
||||||
|
@ -1397,6 +1396,10 @@ pub fn baz() {}
|
||||||
insert: "foo",
|
insert: "foo",
|
||||||
delete: 4..8,
|
delete: 4..8,
|
||||||
},
|
},
|
||||||
|
Indel {
|
||||||
|
insert: "foo",
|
||||||
|
delete: 23..27,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue