Skip to content

Commit 8e0a7d8

Browse files
committed
Fix ranged hover result range
1 parent f2d2ce0 commit 8e0a7d8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

crates/ide/src/hover.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ pub(crate) fn hover(
9393
}
9494
}
9595
})?;
96-
return hover_type_info(&sema, config, expr).map(|it| RangeInfo::new(range, it));
96+
return hover_type_info(&sema, config, &expr).map(|it| {
97+
RangeInfo::new(
98+
match expr {
99+
Either::Left(it) => it.syntax().text_range(),
100+
Either::Right(it) => it.syntax().text_range(),
101+
},
102+
it,
103+
)
104+
});
97105
};
98106

99107
let token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
@@ -204,24 +212,24 @@ pub(crate) fn hover(
204212
}
205213
};
206214

207-
let res = hover_type_info(&sema, config, expr_or_pat)?;
215+
let res = hover_type_info(&sema, config, &expr_or_pat)?;
208216
let range = sema.original_range(&node).range;
209217
Some(RangeInfo::new(range, res))
210218
}
211219

212220
fn hover_type_info(
213221
sema: &Semantics<RootDatabase>,
214222
config: &HoverConfig,
215-
expr_or_pat: Either<ast::Expr, ast::Pat>,
223+
expr_or_pat: &Either<ast::Expr, ast::Pat>,
216224
) -> Option<HoverResult> {
217-
let (ty, coerced) = match &expr_or_pat {
225+
let (ty, coerced) = match expr_or_pat {
218226
Either::Left(expr) => sema.type_of_expr_with_coercion(expr)?,
219227
Either::Right(pat) => sema.type_of_pat_with_coercion(pat)?,
220228
};
221229

222230
let mut res = HoverResult::default();
223231
res.markup = if coerced {
224-
let uncoerced_ty = match &expr_or_pat {
232+
let uncoerced_ty = match expr_or_pat {
225233
Either::Left(expr) => sema.type_of_expr(expr)?,
226234
Either::Right(pat) => sema.type_of_pat(pat)?,
227235
};

0 commit comments

Comments
 (0)