mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 13:33:31 +00:00
Sort hover results by relevance
This commit is contained in:
parent
c2a07e21f5
commit
01fc1e57d2
2 changed files with 18 additions and 6 deletions
|
@ -180,11 +180,25 @@ fn hover_simple(
|
|||
|
||||
// prefer descending the same token kind in attribute expansions, in normal macros text
|
||||
// equivalency is more important
|
||||
let mut descended = vec![];
|
||||
sema.descend_into_macros_cb(original_token.clone(), |token| {
|
||||
descended.push(token.value);
|
||||
let mut descended = sema.descend_into_macros(original_token.clone());
|
||||
|
||||
let kind = original_token.kind();
|
||||
let text = original_token.text();
|
||||
let ident_kind = kind.is_any_identifier();
|
||||
|
||||
descended.sort_by_key(|tok| {
|
||||
let tok_kind = tok.kind();
|
||||
|
||||
let exact_same_kind = tok_kind == kind;
|
||||
let both_idents = exact_same_kind || (tok_kind.is_any_identifier() && ident_kind);
|
||||
let same_text = tok.text() == text;
|
||||
// anything that mapped into a token tree has likely no semantic information
|
||||
let no_tt_parent = tok.parent().map_or(false, |it| it.kind() != TOKEN_TREE);
|
||||
(both_idents as usize)
|
||||
| ((exact_same_kind as usize) << 1)
|
||||
| ((same_text as usize) << 2)
|
||||
| ((no_tt_parent as usize) << 3)
|
||||
});
|
||||
let descended = || descended.iter();
|
||||
|
||||
// TODO: WE should not try these step by step, instead to accommodate for macros we should run
|
||||
// all of these in "parallel" and rank their results
|
||||
|
|
|
@ -407,8 +407,6 @@ fn traverse(
|
|||
|
||||
let mut t = None;
|
||||
let mut r = 0;
|
||||
// FIXME: Add an extra API that takes the file id of this. That is a simple way
|
||||
// to prevent us constantly walking up the tree to fetch the file
|
||||
sema.descend_into_macros_breakable(
|
||||
InRealFile::new(file_id, token.clone()),
|
||||
|tok| {
|
||||
|
|
Loading…
Reference in a new issue