diff options
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r-- | crates/ide_db/src/helpers.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index d96028cbc..bc21977e3 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs | |||
@@ -10,7 +10,10 @@ use std::collections::VecDeque; | |||
10 | use base_db::FileId; | 10 | use base_db::FileId; |
11 | use either::Either; | 11 | use either::Either; |
12 | use hir::{Crate, Enum, ItemInNs, MacroDef, Module, ModuleDef, Name, ScopeDef, Semantics, Trait}; | 12 | use hir::{Crate, Enum, ItemInNs, MacroDef, Module, ModuleDef, Name, ScopeDef, Semantics, Trait}; |
13 | use syntax::ast::{self, make}; | 13 | use syntax::{ |
14 | ast::{self, make}, | ||
15 | SyntaxKind, SyntaxToken, TokenAtOffset, | ||
16 | }; | ||
14 | 17 | ||
15 | use crate::RootDatabase; | 18 | use crate::RootDatabase; |
16 | 19 | ||
@@ -22,6 +25,14 @@ pub fn item_name(db: &RootDatabase, item: ItemInNs) -> Option<Name> { | |||
22 | } | 25 | } |
23 | } | 26 | } |
24 | 27 | ||
28 | /// Picks the token with the highest rank returned by the passed in function. | ||
29 | pub fn pick_best_token( | ||
30 | tokens: TokenAtOffset<SyntaxToken>, | ||
31 | f: impl Fn(SyntaxKind) -> usize, | ||
32 | ) -> Option<SyntaxToken> { | ||
33 | tokens.max_by_key(move |t| f(t.kind())) | ||
34 | } | ||
35 | |||
25 | /// Converts the mod path struct into its ast representation. | 36 | /// Converts the mod path struct into its ast representation. |
26 | pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path { | 37 | pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path { |
27 | let _p = profile::span("mod_path_to_ast"); | 38 | let _p = profile::span("mod_path_to_ast"); |