mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Factor out pick_best_token
ide pattern into ide_db
This commit is contained in:
parent
4e2ec914f4
commit
f615efdfc3
9 changed files with 62 additions and 101 deletions
|
@ -10,7 +10,10 @@ use std::collections::VecDeque;
|
|||
use base_db::FileId;
|
||||
use either::Either;
|
||||
use hir::{Crate, Enum, ItemInNs, MacroDef, Module, ModuleDef, Name, ScopeDef, Semantics, Trait};
|
||||
use syntax::ast::{self, make};
|
||||
use syntax::{
|
||||
ast::{self, make},
|
||||
SyntaxKind, SyntaxToken, TokenAtOffset,
|
||||
};
|
||||
|
||||
use crate::RootDatabase;
|
||||
|
||||
|
@ -22,6 +25,14 @@ pub fn item_name(db: &RootDatabase, item: ItemInNs) -> Option<Name> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Picks the token with the highest rank returned by the passed in function.
|
||||
pub fn pick_best_token(
|
||||
tokens: TokenAtOffset<SyntaxToken>,
|
||||
f: impl Fn(SyntaxKind) -> usize,
|
||||
) -> Option<SyntaxToken> {
|
||||
tokens.max_by_key(move |t| f(t.kind()))
|
||||
}
|
||||
|
||||
/// Converts the mod path struct into its ast representation.
|
||||
pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path {
|
||||
let _p = profile::span("mod_path_to_ast");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue