Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e5b6020

Browse files
bors[bot]Veykril
andauthored
11480: fix: keyword hover works on non-keyword tokens if expanded to keyword r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 9bc2ee3 + 95db3c1 commit e5b6020

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

crates/ide/src/hover.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,10 @@ pub(crate) fn hover(
9494
let sema = &hir::Semantics::new(db);
9595
let file = sema.parse(file_id).syntax().clone();
9696

97-
let offset = if !range.is_empty() {
97+
if !range.is_empty() {
9898
return hover_ranged(&file, range, sema, config);
99-
} else {
100-
range.start()
101-
};
99+
}
100+
let offset = range.start();
102101

103102
let original_token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
104103
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
@@ -118,10 +117,11 @@ pub(crate) fn hover(
118117
let descended = sema.descend_into_macros(original_token.clone());
119118

120119
// FIXME: Definition should include known lints and the like instead of having this special case here
121-
if let Some(res) = descended.iter().find_map(|token| {
120+
let hovered_lint = descended.iter().find_map(|token| {
122121
let attr = token.ancestors().find_map(ast::Attr::cast)?;
123122
render::try_for_lint(&attr, token)
124-
}) {
123+
});
124+
if let Some(res) = hovered_lint {
125125
return Some(RangeInfo::new(original_token.text_range(), res));
126126
}
127127

@@ -143,7 +143,9 @@ pub(crate) fn hover(
143143

144144
if result.is_none() {
145145
// fallbacks, show keywords or types
146-
if let Some(res) = render::keyword(sema, config, &original_token) {
146+
147+
let res = descended.iter().find_map(|token| render::keyword(sema, config, &token));
148+
if let Some(res) = res {
147149
return Some(RangeInfo::new(original_token.text_range(), res));
148150
}
149151
let res = descended
@@ -199,6 +201,7 @@ fn hover_ranged(
199201
sema: &Semantics<RootDatabase>,
200202
config: &HoverConfig,
201203
) -> Option<RangeInfo<HoverResult>> {
204+
// FIXME: make this work in attributes
202205
let expr_or_pat = file.covering_element(range).ancestors().find_map(|it| {
203206
match_ast! {
204207
match it {

0 commit comments

Comments
 (0)