diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-22 18:17:54 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-22 18:17:54 +0100 |
commit | 76c88e9ca9ea9000d7d9eda1b2dae3173296f738 (patch) | |
tree | 8e7d42ad63269c668b189c0a59d55ebd53328f90 /crates/ide_db | |
parent | 4e2ec914f4b9609d162c3fd1776e8d293428fe5a (diff) | |
parent | f615efdfc3b4655e4f74068769905404cd911b5e (diff) |
Merge #9373
9373: internal: Factor out `pick_best_token` ide pattern into `ide_db` r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_db')
-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"); |