diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-19 13:57:03 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-19 13:57:03 +0000 |
commit | 27587f3501168c0522e62bf14923aedbdc08a960 (patch) | |
tree | f323973f087ef0f47ef7015a930b09fefdf723a6 /crates/ra_ide_db | |
parent | ff415582960dbd91a18a092271c0848d6c90b0ec (diff) | |
parent | 372439dec88f8ce3350f29aa56801c8f30e59abe (diff) |
Merge #3236
3236: Merge NameDefinition and NameKind r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 55 | ||||
-rw-r--r-- | crates/ra_ide_db/src/imports_locator.rs | 8 |
2 files changed, 23 insertions, 40 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index aec748abf..04c214624 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -18,7 +18,7 @@ use ra_syntax::{ | |||
18 | use crate::RootDatabase; | 18 | use crate::RootDatabase; |
19 | 19 | ||
20 | #[derive(Debug, PartialEq, Eq)] | 20 | #[derive(Debug, PartialEq, Eq)] |
21 | pub enum NameKind { | 21 | pub enum NameDefinition { |
22 | Macro(MacroDef), | 22 | Macro(MacroDef), |
23 | StructField(StructField), | 23 | StructField(StructField), |
24 | ModuleDef(ModuleDef), | 24 | ModuleDef(ModuleDef), |
@@ -27,33 +27,26 @@ pub enum NameKind { | |||
27 | TypeParam(TypeParam), | 27 | TypeParam(TypeParam), |
28 | } | 28 | } |
29 | 29 | ||
30 | #[derive(PartialEq, Eq)] | ||
31 | pub struct NameDefinition { | ||
32 | /// FIXME: this doesn't really make sense. For example, builtin types don't | ||
33 | /// really have a module. | ||
34 | pub kind: NameKind, | ||
35 | } | ||
36 | |||
37 | impl NameDefinition { | 30 | impl NameDefinition { |
38 | pub fn module(&self, db: &RootDatabase) -> Option<Module> { | 31 | pub fn module(&self, db: &RootDatabase) -> Option<Module> { |
39 | match self.kind { | 32 | match self { |
40 | NameKind::Macro(it) => it.module(db), | 33 | NameDefinition::Macro(it) => it.module(db), |
41 | NameKind::StructField(it) => Some(it.parent_def(db).module(db)), | 34 | NameDefinition::StructField(it) => Some(it.parent_def(db).module(db)), |
42 | NameKind::ModuleDef(it) => it.module(db), | 35 | NameDefinition::ModuleDef(it) => it.module(db), |
43 | NameKind::SelfType(it) => Some(it.module(db)), | 36 | NameDefinition::SelfType(it) => Some(it.module(db)), |
44 | NameKind::Local(it) => Some(it.module(db)), | 37 | NameDefinition::Local(it) => Some(it.module(db)), |
45 | NameKind::TypeParam(it) => Some(it.module(db)), | 38 | NameDefinition::TypeParam(it) => Some(it.module(db)), |
46 | } | 39 | } |
47 | } | 40 | } |
48 | 41 | ||
49 | pub fn visibility(&self, db: &RootDatabase) -> Option<ast::Visibility> { | 42 | pub fn visibility(&self, db: &RootDatabase) -> Option<ast::Visibility> { |
50 | match self.kind { | 43 | match self { |
51 | NameKind::Macro(_) => None, | 44 | NameDefinition::Macro(_) => None, |
52 | NameKind::StructField(sf) => match sf.source(db).value { | 45 | NameDefinition::StructField(sf) => match sf.source(db).value { |
53 | FieldSource::Named(it) => it.visibility(), | 46 | FieldSource::Named(it) => it.visibility(), |
54 | FieldSource::Pos(it) => it.visibility(), | 47 | FieldSource::Pos(it) => it.visibility(), |
55 | }, | 48 | }, |
56 | NameKind::ModuleDef(def) => match def { | 49 | NameDefinition::ModuleDef(def) => match def { |
57 | ModuleDef::Module(it) => it.declaration_source(db)?.value.visibility(), | 50 | ModuleDef::Module(it) => it.declaration_source(db)?.value.visibility(), |
58 | ModuleDef::Function(it) => it.source(db).value.visibility(), | 51 | ModuleDef::Function(it) => it.source(db).value.visibility(), |
59 | ModuleDef::Adt(adt) => match adt { | 52 | ModuleDef::Adt(adt) => match adt { |
@@ -68,9 +61,9 @@ impl NameDefinition { | |||
68 | ModuleDef::EnumVariant(_) => None, | 61 | ModuleDef::EnumVariant(_) => None, |
69 | ModuleDef::BuiltinType(_) => None, | 62 | ModuleDef::BuiltinType(_) => None, |
70 | }, | 63 | }, |
71 | NameKind::SelfType(_) => None, | 64 | NameDefinition::SelfType(_) => None, |
72 | NameKind::Local(_) => None, | 65 | NameDefinition::Local(_) => None, |
73 | NameKind::TypeParam(_) => None, | 66 | NameDefinition::TypeParam(_) => None, |
74 | } | 67 | } |
75 | } | 68 | } |
76 | } | 69 | } |
@@ -87,9 +80,7 @@ pub fn classify_name( | |||
87 | ast::BindPat(it) => { | 80 | ast::BindPat(it) => { |
88 | let src = name.with_value(it); | 81 | let src = name.with_value(it); |
89 | let local = sb.to_def(src)?; | 82 | let local = sb.to_def(src)?; |
90 | Some(NameDefinition { | 83 | Some(NameDefinition::Local(local)) |
91 | kind: NameKind::Local(local), | ||
92 | }) | ||
93 | }, | 84 | }, |
94 | ast::RecordFieldDef(it) => { | 85 | ast::RecordFieldDef(it) => { |
95 | let src = name.with_value(it); | 86 | let src = name.with_value(it); |
@@ -144,16 +135,12 @@ pub fn classify_name( | |||
144 | let src = name.with_value(it); | 135 | let src = name.with_value(it); |
145 | let def = sb.to_def(src.clone())?; | 136 | let def = sb.to_def(src.clone())?; |
146 | 137 | ||
147 | Some(NameDefinition { | 138 | Some(NameDefinition::Macro(def)) |
148 | kind: NameKind::Macro(def), | ||
149 | }) | ||
150 | }, | 139 | }, |
151 | ast::TypeParam(it) => { | 140 | ast::TypeParam(it) => { |
152 | let src = name.with_value(it); | 141 | let src = name.with_value(it); |
153 | let def = sb.to_def(src)?; | 142 | let def = sb.to_def(src)?; |
154 | Some(NameDefinition { | 143 | Some(NameDefinition::TypeParam(def)) |
155 | kind: NameKind::TypeParam(def), | ||
156 | }) | ||
157 | }, | 144 | }, |
158 | _ => None, | 145 | _ => None, |
159 | } | 146 | } |
@@ -161,11 +148,9 @@ pub fn classify_name( | |||
161 | } | 148 | } |
162 | 149 | ||
163 | pub fn from_struct_field(field: StructField) -> NameDefinition { | 150 | pub fn from_struct_field(field: StructField) -> NameDefinition { |
164 | let kind = NameKind::StructField(field); | 151 | NameDefinition::StructField(field) |
165 | NameDefinition { kind } | ||
166 | } | 152 | } |
167 | 153 | ||
168 | pub fn from_module_def(def: ModuleDef) -> NameDefinition { | 154 | pub fn from_module_def(def: ModuleDef) -> NameDefinition { |
169 | let kind = NameKind::ModuleDef(def); | 155 | NameDefinition::ModuleDef(def) |
170 | NameDefinition { kind } | ||
171 | } | 156 | } |
diff --git a/crates/ra_ide_db/src/imports_locator.rs b/crates/ra_ide_db/src/imports_locator.rs index 86383bcd0..b8dd358a9 100644 --- a/crates/ra_ide_db/src/imports_locator.rs +++ b/crates/ra_ide_db/src/imports_locator.rs | |||
@@ -6,8 +6,7 @@ use ra_prof::profile; | |||
6 | use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; | 6 | use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | defs::classify_name, | 9 | defs::{classify_name, NameDefinition}, |
10 | defs::NameKind, | ||
11 | symbol_index::{self, FileSymbol, Query}, | 10 | symbol_index::{self, FileSymbol, Query}, |
12 | RootDatabase, | 11 | RootDatabase, |
13 | }; | 12 | }; |
@@ -44,7 +43,7 @@ impl<'a> ImportsLocator<'a> { | |||
44 | .chain(lib_results.into_iter()) | 43 | .chain(lib_results.into_iter()) |
45 | .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) | 44 | .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) |
46 | .filter_map(|name_definition_to_import| match name_definition_to_import { | 45 | .filter_map(|name_definition_to_import| match name_definition_to_import { |
47 | NameKind::ModuleDef(module_def) => Some(module_def), | 46 | NameDefinition::ModuleDef(module_def) => Some(module_def), |
48 | _ => None, | 47 | _ => None, |
49 | }) | 48 | }) |
50 | .collect() | 49 | .collect() |
@@ -54,7 +53,7 @@ impl<'a> ImportsLocator<'a> { | |||
54 | &mut self, | 53 | &mut self, |
55 | db: &impl HirDatabase, | 54 | db: &impl HirDatabase, |
56 | import_candidate: &FileSymbol, | 55 | import_candidate: &FileSymbol, |
57 | ) -> Option<NameKind> { | 56 | ) -> Option<NameDefinition> { |
58 | let _p = profile("get_name_definition"); | 57 | let _p = profile("get_name_definition"); |
59 | let file_id = import_candidate.file_id.into(); | 58 | let file_id = import_candidate.file_id.into(); |
60 | let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?); | 59 | let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?); |
@@ -67,6 +66,5 @@ impl<'a> ImportsLocator<'a> { | |||
67 | &mut self.source_binder, | 66 | &mut self.source_binder, |
68 | hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? }, | 67 | hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? }, |
69 | ) | 68 | ) |
70 | .map(|it| it.kind) | ||
71 | } | 69 | } |
72 | } | 70 | } |