mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +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 file = sema.parse(file_id).syntax().clone();
|
||||
|
||||
let offset = if !range.is_empty() {
|
||||
if !range.is_empty() {
|
||||
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 {
|
||||
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());
|
||||
|
||||
// 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)?;
|
||||
render::try_for_lint(&attr, token)
|
||||
}) {
|
||||
});
|
||||
if let Some(res) = hovered_lint {
|
||||
return Some(RangeInfo::new(original_token.text_range(), res));
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,9 @@ pub(crate) fn hover(
|
|||
|
||||
if result.is_none() {
|
||||
// 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));
|
||||
}
|
||||
let res = descended
|
||||
|
@ -199,6 +201,7 @@ fn hover_ranged(
|
|||
sema: &Semantics<RootDatabase>,
|
||||
config: &HoverConfig,
|
||||
) -> Option<RangeInfo<HoverResult>> {
|
||||
// FIXME: make this work in attributes
|
||||
let expr_or_pat = file.covering_element(range).ancestors().find_map(|it| {
|
||||
match_ast! {
|
||||
match it {
|
||||
|
|
Loading…
Reference in a new issue