diff options
author | Aleksey Kladov <[email protected]> | 2020-02-18 17:35:10 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-26 11:55:50 +0000 |
commit | c3a4c4429de83450654795534e64e878a774a088 (patch) | |
tree | 12d89798f61b276f8bd640db07276a7d4e92b1c2 /crates/ra_assists/src/utils.rs | |
parent | 04deae3dba7c9b7054f7a1d64e4b93a05aecc132 (diff) |
Refactor primary IDE API
This introduces the new type -- Semantics.
Semantics maps SyntaxNodes to various semantic info, such as type,
name resolution or macro expansions.
To do so, Semantics maintains a HashMap which maps every node it saw
to the file from which the node originated. This is enough to get all
the necessary hir bits just from syntax.
Diffstat (limited to 'crates/ra_assists/src/utils.rs')
-rw-r--r-- | crates/ra_assists/src/utils.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 6ff44c95c..92d3ed471 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs | |||
@@ -1,16 +1,15 @@ | |||
1 | //! Assorted functions shared by several assists. | 1 | //! Assorted functions shared by several assists. |
2 | 2 | ||
3 | use hir::Semantics; | ||
4 | use ra_ide_db::RootDatabase; | ||
3 | use ra_syntax::{ | 5 | use ra_syntax::{ |
4 | ast::{self, make, NameOwner}, | 6 | ast::{self, make, NameOwner}, |
5 | AstNode, T, | 7 | AstNode, T, |
6 | }; | 8 | }; |
7 | |||
8 | use hir::db::HirDatabase; | ||
9 | use rustc_hash::FxHashSet; | 9 | use rustc_hash::FxHashSet; |
10 | 10 | ||
11 | pub fn get_missing_impl_items( | 11 | pub fn get_missing_impl_items( |
12 | db: &impl HirDatabase, | 12 | sema: &Semantics<RootDatabase>, |
13 | analyzer: &hir::SourceAnalyzer, | ||
14 | impl_block: &ast::ImplBlock, | 13 | impl_block: &ast::ImplBlock, |
15 | ) -> Vec<hir::AssocItem> { | 14 | ) -> Vec<hir::AssocItem> { |
16 | // Names must be unique between constants and functions. However, type aliases | 15 | // Names must be unique between constants and functions. However, type aliases |
@@ -42,15 +41,17 @@ pub fn get_missing_impl_items( | |||
42 | } | 41 | } |
43 | } | 42 | } |
44 | 43 | ||
45 | resolve_target_trait(db, analyzer, impl_block).map_or(vec![], |target_trait| { | 44 | resolve_target_trait(sema, impl_block).map_or(vec![], |target_trait| { |
46 | target_trait | 45 | target_trait |
47 | .items(db) | 46 | .items(sema.db) |
48 | .iter() | 47 | .iter() |
49 | .filter(|i| match i { | 48 | .filter(|i| match i { |
50 | hir::AssocItem::Function(f) => !impl_fns_consts.contains(&f.name(db).to_string()), | 49 | hir::AssocItem::Function(f) => { |
51 | hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(db).to_string()), | 50 | !impl_fns_consts.contains(&f.name(sema.db).to_string()) |
51 | } | ||
52 | hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(sema.db).to_string()), | ||
52 | hir::AssocItem::Const(c) => c | 53 | hir::AssocItem::Const(c) => c |
53 | .name(db) | 54 | .name(sema.db) |
54 | .map(|n| !impl_fns_consts.contains(&n.to_string())) | 55 | .map(|n| !impl_fns_consts.contains(&n.to_string())) |
55 | .unwrap_or_default(), | 56 | .unwrap_or_default(), |
56 | }) | 57 | }) |
@@ -60,8 +61,7 @@ pub fn get_missing_impl_items( | |||
60 | } | 61 | } |
61 | 62 | ||
62 | pub(crate) fn resolve_target_trait( | 63 | pub(crate) fn resolve_target_trait( |
63 | db: &impl HirDatabase, | 64 | sema: &Semantics<RootDatabase>, |
64 | analyzer: &hir::SourceAnalyzer, | ||
65 | impl_block: &ast::ImplBlock, | 65 | impl_block: &ast::ImplBlock, |
66 | ) -> Option<hir::Trait> { | 66 | ) -> Option<hir::Trait> { |
67 | let ast_path = impl_block | 67 | let ast_path = impl_block |
@@ -70,7 +70,7 @@ pub(crate) fn resolve_target_trait( | |||
70 | .and_then(ast::PathType::cast)? | 70 | .and_then(ast::PathType::cast)? |
71 | .path()?; | 71 | .path()?; |
72 | 72 | ||
73 | match analyzer.resolve_path(db, &ast_path) { | 73 | match sema.resolve_path(&ast_path) { |
74 | Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def), | 74 | Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def), |
75 | _ => None, | 75 | _ => None, |
76 | } | 76 | } |