Skip to content

Commit c93aa5a

Browse files
committed
Remove hover fallback in favor of ranged hover
1 parent a542bd4 commit c93aa5a

File tree

1 file changed

+10
-44
lines changed

1 file changed

+10
-44
lines changed

crates/ide/src/hover.rs

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ide_db::{
1515
FxIndexSet, RootDatabase,
1616
};
1717
use itertools::Itertools;
18-
use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, T};
18+
use syntax::{ast, AstNode, SyntaxKind::*, SyntaxNode, T};
1919

2020
use crate::{
2121
doc_links::token_as_doc_comment,
@@ -203,14 +203,10 @@ fn hover_simple(
203203
})
204204
});
205205

206-
result
207-
.map(|mut res: HoverResult| {
208-
res.actions = dedupe_or_merge_hover_actions(res.actions);
209-
RangeInfo::new(original_token.text_range(), res)
210-
})
211-
// fallback to type hover if there aren't any other suggestions
212-
// this finds its own range instead of using the closest token's range
213-
.or_else(|| descended().find_map(|token| hover_type_fallback(sema, config, token, token)))
206+
result.map(|mut res: HoverResult| {
207+
res.actions = dedupe_or_merge_hover_actions(res.actions);
208+
RangeInfo::new(original_token.text_range(), res)
209+
})
214210
}
215211

216212
fn hover_ranged(
@@ -220,8 +216,11 @@ fn hover_ranged(
220216
config: &HoverConfig,
221217
) -> Option<RangeInfo<HoverResult>> {
222218
// FIXME: make this work in attributes
223-
let expr_or_pat =
224-
file.covering_element(range).ancestors().find_map(Either::<ast::Expr, ast::Pat>::cast)?;
219+
let expr_or_pat = file
220+
.covering_element(range)
221+
.ancestors()
222+
.take_while(|it| ast::Item::can_cast(it.kind()))
223+
.find_map(Either::<ast::Expr, ast::Pat>::cast)?;
225224
let res = match &expr_or_pat {
226225
Either::Left(ast::Expr::TryExpr(try_expr)) => render::try_expr(sema, config, try_expr),
227226
Either::Left(ast::Expr::PrefixExpr(prefix_expr))
@@ -268,39 +267,6 @@ pub(crate) fn hover_for_definition(
268267
})
269268
}
270269

271-
fn hover_type_fallback(
272-
sema: &Semantics<'_, RootDatabase>,
273-
config: &HoverConfig,
274-
token: &SyntaxToken,
275-
original_token: &SyntaxToken,
276-
) -> Option<RangeInfo<HoverResult>> {
277-
let node =
278-
token.parent_ancestors().take_while(|it| !ast::Item::can_cast(it.kind())).find(|n| {
279-
ast::Expr::can_cast(n.kind())
280-
|| ast::Pat::can_cast(n.kind())
281-
|| ast::Type::can_cast(n.kind())
282-
})?;
283-
284-
let expr_or_pat = match_ast! {
285-
match node {
286-
ast::Expr(it) => Either::Left(it),
287-
ast::Pat(it) => Either::Right(it),
288-
// If this node is a MACRO_CALL, it means that `descend_into_macros_many` failed to resolve.
289-
// (e.g expanding a builtin macro). So we give up here.
290-
ast::MacroCall(_it) => return None,
291-
_ => return None,
292-
}
293-
};
294-
295-
let res = render::type_info_of(sema, config, &expr_or_pat)?;
296-
297-
let range = sema
298-
.original_range_opt(&node)
299-
.map(|frange| frange.range)
300-
.unwrap_or_else(|| original_token.text_range());
301-
Some(RangeInfo::new(range, res))
302-
}
303-
304270
fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
305271
fn to_action(nav_target: NavigationTarget) -> HoverAction {
306272
HoverAction::Implementation(FilePosition {

0 commit comments

Comments
 (0)