Skip to content

Commit 686f8fb

Browse files
author
Anatol Ulrich
committed
simplify
1 parent 2490807 commit 686f8fb

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

crates/ide/src/goto_type_definition.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ pub(crate) fn goto_type_definition(
3636
}
3737
}
3838
};
39-
40-
// TODO this became pretty baroque after refactoring for `descend_into_macros(_many)`
41-
let range = sema
42-
.descend_into_macros(token)
39+
let range = token.text_range();
40+
sema.descend_into_macros(token)
4341
.iter()
4442
.filter_map(|token| {
45-
let ty_range = sema.token_ancestors_with_macros(token.clone()).find_map(|node| {
43+
let ty = sema.token_ancestors_with_macros(token.clone()).find_map(|node| {
4644
let ty = match_ast! {
4745
match node {
4846
ast::Expr(it) => sema.type_of_expr(&it)?.original,
@@ -64,12 +62,11 @@ pub(crate) fn goto_type_definition(
6462
}
6563
};
6664

67-
let range = node.text_range();
68-
Some((ty, range.start(), range.end()))
65+
Some(ty)
6966
});
70-
ty_range
67+
ty
7168
})
72-
.inspect(|(ty, _range_start, _range_end)| {
69+
.for_each(|ty| {
7370
// collect from each `ty` into the `res` result vec
7471
let ty = ty.strip_references();
7572
ty.walk(db, |t| {
@@ -83,14 +80,12 @@ pub(crate) fn goto_type_definition(
8380
push(trait_.into());
8481
}
8582
});
86-
}) // reduce all ranges into a single umbrella span (TODO fishy?)
87-
.map(|(_, range_start, range_end)| (range_start, range_end))
88-
.reduce(|(start_acc, end_acc), (start_cur, end_cur)| {
89-
(start_acc.min(start_cur), end_acc.max(end_cur))
90-
})
91-
.map(|(range_start, range_end)| TextRange::new(range_start, range_end))?; // TODO easy to miss `?` bail
92-
93-
Some(RangeInfo::new(range, res))
83+
});
84+
if res.is_empty() {
85+
None
86+
} else {
87+
Some(RangeInfo::new(range, res))
88+
}
9489
}
9590

9691
#[cfg(test)]

0 commit comments

Comments
 (0)