mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge #11480
11480: fix: keyword hover works on non-keyword tokens if expanded to keyword r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
e5b6020e55
1 changed files with 10 additions and 7 deletions
|
@ -94,11 +94,10 @@ pub(crate) fn hover(
|
||||||
let sema = &hir::Semantics::new(db);
|
let sema = &hir::Semantics::new(db);
|
||||||
let file = sema.parse(file_id).syntax().clone();
|
let file = sema.parse(file_id).syntax().clone();
|
||||||
|
|
||||||
let offset = if !range.is_empty() {
|
if !range.is_empty() {
|
||||||
return hover_ranged(&file, range, sema, config);
|
return hover_ranged(&file, range, sema, config);
|
||||||
} else {
|
}
|
||||||
range.start()
|
let offset = range.start();
|
||||||
};
|
|
||||||
|
|
||||||
let original_token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
|
let original_token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
|
||||||
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
|
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
|
||||||
|
@ -118,10 +117,11 @@ pub(crate) fn hover(
|
||||||
let descended = sema.descend_into_macros(original_token.clone());
|
let descended = sema.descend_into_macros(original_token.clone());
|
||||||
|
|
||||||
// FIXME: Definition should include known lints and the like instead of having this special case here
|
// FIXME: Definition should include known lints and the like instead of having this special case here
|
||||||
if let Some(res) = descended.iter().find_map(|token| {
|
let hovered_lint = descended.iter().find_map(|token| {
|
||||||
let attr = token.ancestors().find_map(ast::Attr::cast)?;
|
let attr = token.ancestors().find_map(ast::Attr::cast)?;
|
||||||
render::try_for_lint(&attr, token)
|
render::try_for_lint(&attr, token)
|
||||||
}) {
|
});
|
||||||
|
if let Some(res) = hovered_lint {
|
||||||
return Some(RangeInfo::new(original_token.text_range(), res));
|
return Some(RangeInfo::new(original_token.text_range(), res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,9 @@ pub(crate) fn hover(
|
||||||
|
|
||||||
if result.is_none() {
|
if result.is_none() {
|
||||||
// fallbacks, show keywords or types
|
// fallbacks, show keywords or types
|
||||||
if let Some(res) = render::keyword(sema, config, &original_token) {
|
|
||||||
|
let res = descended.iter().find_map(|token| render::keyword(sema, config, &token));
|
||||||
|
if let Some(res) = res {
|
||||||
return Some(RangeInfo::new(original_token.text_range(), res));
|
return Some(RangeInfo::new(original_token.text_range(), res));
|
||||||
}
|
}
|
||||||
let res = descended
|
let res = descended
|
||||||
|
@ -199,6 +201,7 @@ fn hover_ranged(
|
||||||
sema: &Semantics<RootDatabase>,
|
sema: &Semantics<RootDatabase>,
|
||||||
config: &HoverConfig,
|
config: &HoverConfig,
|
||||||
) -> Option<RangeInfo<HoverResult>> {
|
) -> Option<RangeInfo<HoverResult>> {
|
||||||
|
// FIXME: make this work in attributes
|
||||||
let expr_or_pat = file.covering_element(range).ancestors().find_map(|it| {
|
let expr_or_pat = file.covering_element(range).ancestors().find_map(|it| {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match it {
|
match it {
|
||||||
|
|
Loading…
Reference in a new issue