mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
implement #10070 in runnables
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
parent
cbc13ae6bd
commit
5d08ac20d9
1 changed files with 12 additions and 7 deletions
|
@ -229,15 +229,20 @@ fn find_related_tests(
|
||||||
for (file_id, refs) in refs.into_iter().flat_map(|refs| refs.references) {
|
for (file_id, refs) in refs.into_iter().flat_map(|refs| refs.references) {
|
||||||
let file = sema.parse(file_id);
|
let file = sema.parse(file_id);
|
||||||
let file = file.syntax();
|
let file = file.syntax();
|
||||||
let functions = refs.iter().filter_map(|(range, _)| {
|
|
||||||
let token = file.token_at_offset(range.start()).next()?;
|
// create flattened vec of tokens
|
||||||
let token = sema.descend_into_macros(token);
|
let tokens = refs.iter().flat_map(|(range, _)| {
|
||||||
token
|
match file.token_at_offset(range.start()).next() {
|
||||||
.ancestors()
|
Some(token) => sema.descend_into_macros_many(token),
|
||||||
.find_map(ast::Fn::cast)
|
None => Default::default(),
|
||||||
.map(|f| hir::InFile::new(sema.hir_file_for(f.syntax()), f))
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// find first suitable ancestor
|
||||||
|
let functions = tokens
|
||||||
|
.filter_map(|token| token.ancestors().find_map(ast::Fn::cast))
|
||||||
|
.map(|f| hir::InFile::new(sema.hir_file_for(f.syntax()), f));
|
||||||
|
|
||||||
for fn_def in functions {
|
for fn_def in functions {
|
||||||
// #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
|
// #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
|
||||||
let InFile { value: fn_def, .. } = &fn_def.node_with_attributes(sema.db);
|
let InFile { value: fn_def, .. } = &fn_def.node_with_attributes(sema.db);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue