Skip to content

Commit 29506b5

Browse files
bors[bot]Veykril
andauthored
Merge #9762
9762: fix: Fix ranged hover result range r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents cae54d8 + 8e0a7d8 commit 29506b5

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 {
@@ -207,24 +215,24 @@ pub(crate) fn hover(
207215
}
208216
};
209217

210-
let res = hover_type_info(&sema, config, expr_or_pat)?;
218+
let res = hover_type_info(&sema, config, &expr_or_pat)?;
211219
let range = sema.original_range(&node).range;
212220
Some(RangeInfo::new(range, res))
213221
}
214222

215223
fn hover_type_info(
216224
sema: &Semantics<RootDatabase>,
217225
config: &HoverConfig,
218-
expr_or_pat: Either<ast::Expr, ast::Pat>,
226+
expr_or_pat: &Either<ast::Expr, ast::Pat>,
219227
) -> Option<HoverResult> {
220-
let (ty, coerced) = match &expr_or_pat {
228+
let (ty, coerced) = match expr_or_pat {
221229
Either::Left(expr) => sema.type_of_expr_with_coercion(expr)?,
222230
Either::Right(pat) => sema.type_of_pat_with_coercion(pat)?,
223231
};
224232

225233
let mut res = HoverResult::default();
226234
res.markup = if coerced {
227-
let uncoerced_ty = match &expr_or_pat {
235+
let uncoerced_ty = match expr_or_pat {
228236
Either::Left(expr) => sema.type_of_expr(expr)?,
229237
Either::Right(pat) => sema.type_of_pat(pat)?,
230238
};

0 commit comments

Comments
 (0)