diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/hover.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide/src/references/classify.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 23 | ||||
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 40 | ||||
-rw-r--r-- | crates/ra_ide_db/src/imports_locator.rs | 2 |
7 files changed, 45 insertions, 71 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index e9329a72c..de5551a4c 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -76,11 +76,10 @@ pub(crate) fn reference_definition( | |||
76 | let name_kind = classify_name_ref(sb, name_ref).map(|d| d.kind); | 76 | let name_kind = classify_name_ref(sb, name_ref).map(|d| d.kind); |
77 | match name_kind { | 77 | match name_kind { |
78 | Some(Macro(it)) => return Exact(it.to_nav(sb.db)), | 78 | Some(Macro(it)) => return Exact(it.to_nav(sb.db)), |
79 | Some(Field(it)) => return Exact(it.to_nav(sb.db)), | 79 | Some(StructField(it)) => return Exact(it.to_nav(sb.db)), |
80 | Some(TypeParam(it)) => return Exact(it.to_nav(sb.db)), | 80 | Some(TypeParam(it)) => return Exact(it.to_nav(sb.db)), |
81 | Some(AssocItem(it)) => return Exact(it.to_nav(sb.db)), | ||
82 | Some(Local(it)) => return Exact(it.to_nav(sb.db)), | 81 | Some(Local(it)) => return Exact(it.to_nav(sb.db)), |
83 | Some(Def(def)) => match NavigationTarget::from_def(sb.db, def) { | 82 | Some(ModuleDef(def)) => match NavigationTarget::from_def(sb.db, def) { |
84 | Some(nav) => return Exact(nav), | 83 | Some(nav) => return Exact(nav), |
85 | None => return Approximate(vec![]), | 84 | None => return Approximate(vec![]), |
86 | }, | 85 | }, |
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 315b88190..3f88bb260 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -98,19 +98,14 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<S | |||
98 | let src = it.source(db); | 98 | let src = it.source(db); |
99 | hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value))) | 99 | hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value))) |
100 | } | 100 | } |
101 | Field(it) => { | 101 | StructField(it) => { |
102 | let src = it.source(db); | 102 | let src = it.source(db); |
103 | match src.value { | 103 | match src.value { |
104 | hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), | 104 | hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), |
105 | _ => None, | 105 | _ => None, |
106 | } | 106 | } |
107 | } | 107 | } |
108 | AssocItem(it) => match it { | 108 | ModuleDef(it) => match it { |
109 | hir::AssocItem::Function(it) => from_def_source(db, it), | ||
110 | hir::AssocItem::Const(it) => from_def_source(db, it), | ||
111 | hir::AssocItem::TypeAlias(it) => from_def_source(db, it), | ||
112 | }, | ||
113 | Def(it) => match it { | ||
114 | hir::ModuleDef::Module(it) => match it.definition_source(db).value { | 109 | hir::ModuleDef::Module(it) => match it.definition_source(db).value { |
115 | hir::ModuleSource::Module(it) => { | 110 | hir::ModuleSource::Module(it) => { |
116 | hover_text(it.doc_comment_text(), it.short_label()) | 111 | hover_text(it.doc_comment_text(), it.short_label()) |
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index c215040f4..a6320bd2f 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -127,9 +127,8 @@ pub(crate) fn find_all_refs( | |||
127 | 127 | ||
128 | let declaration = match def.kind { | 128 | let declaration = match def.kind { |
129 | NameKind::Macro(mac) => mac.to_nav(db), | 129 | NameKind::Macro(mac) => mac.to_nav(db), |
130 | NameKind::Field(field) => field.to_nav(db), | 130 | NameKind::StructField(field) => field.to_nav(db), |
131 | NameKind::AssocItem(assoc) => assoc.to_nav(db), | 131 | NameKind::ModuleDef(def) => NavigationTarget::from_def(db, def)?, |
132 | NameKind::Def(def) => NavigationTarget::from_def(db, def)?, | ||
133 | NameKind::SelfType(imp) => imp.to_nav(db), | 132 | NameKind::SelfType(imp) => imp.to_nav(db), |
134 | NameKind::Local(local) => local.to_nav(db), | 133 | NameKind::Local(local) => local.to_nav(db), |
135 | NameKind::TypeParam(_) => return None, | 134 | NameKind::TypeParam(_) => return None, |
@@ -240,7 +239,7 @@ fn decl_access( | |||
240 | range: TextRange, | 239 | range: TextRange, |
241 | ) -> Option<ReferenceAccess> { | 240 | ) -> Option<ReferenceAccess> { |
242 | match kind { | 241 | match kind { |
243 | NameKind::Local(_) | NameKind::Field(_) => {} | 242 | NameKind::Local(_) | NameKind::StructField(_) => {} |
244 | _ => return None, | 243 | _ => return None, |
245 | }; | 244 | }; |
246 | 245 | ||
@@ -260,7 +259,7 @@ fn decl_access( | |||
260 | fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option<ReferenceAccess> { | 259 | fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option<ReferenceAccess> { |
261 | // Only Locals and Fields have accesses for now. | 260 | // Only Locals and Fields have accesses for now. |
262 | match kind { | 261 | match kind { |
263 | NameKind::Local(_) | NameKind::Field(_) => {} | 262 | NameKind::Local(_) | NameKind::StructField(_) => {} |
264 | _ => return None, | 263 | _ => return None, |
265 | }; | 264 | }; |
266 | 265 | ||
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 0326fd379..d0f03d8a8 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs | |||
@@ -8,7 +8,7 @@ use test_utils::tested_by; | |||
8 | use super::{NameDefinition, NameKind}; | 8 | use super::{NameDefinition, NameKind}; |
9 | use ra_ide_db::RootDatabase; | 9 | use ra_ide_db::RootDatabase; |
10 | 10 | ||
11 | pub use ra_ide_db::defs::{classify_name, from_assoc_item, from_module_def, from_struct_field}; | 11 | pub use ra_ide_db::defs::{classify_name, from_module_def, from_struct_field}; |
12 | 12 | ||
13 | pub(crate) fn classify_name_ref( | 13 | pub(crate) fn classify_name_ref( |
14 | sb: &mut SourceBinder<RootDatabase>, | 14 | sb: &mut SourceBinder<RootDatabase>, |
@@ -22,7 +22,7 @@ pub(crate) fn classify_name_ref( | |||
22 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { | 22 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { |
23 | tested_by!(goto_def_for_methods); | 23 | tested_by!(goto_def_for_methods); |
24 | if let Some(func) = analyzer.resolve_method_call(&method_call) { | 24 | if let Some(func) = analyzer.resolve_method_call(&method_call) { |
25 | return Some(from_assoc_item(sb.db, func.into())); | 25 | return Some(from_module_def(sb.db, func.into(), None)); |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
@@ -57,27 +57,35 @@ pub(crate) fn classify_name_ref( | |||
57 | 57 | ||
58 | let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; | 58 | let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; |
59 | let resolved = analyzer.resolve_path(sb.db, &path)?; | 59 | let resolved = analyzer.resolve_path(sb.db, &path)?; |
60 | match resolved { | 60 | let res = match resolved { |
61 | PathResolution::Def(def) => Some(from_module_def(sb.db, def, Some(container))), | 61 | PathResolution::Def(def) => from_module_def(sb.db, def, Some(container)), |
62 | PathResolution::AssocItem(item) => Some(from_assoc_item(sb.db, item)), | 62 | PathResolution::AssocItem(item) => { |
63 | let def = match item { | ||
64 | hir::AssocItem::Function(it) => it.into(), | ||
65 | hir::AssocItem::Const(it) => it.into(), | ||
66 | hir::AssocItem::TypeAlias(it) => it.into(), | ||
67 | }; | ||
68 | from_module_def(sb.db, def, Some(container)) | ||
69 | } | ||
63 | PathResolution::Local(local) => { | 70 | PathResolution::Local(local) => { |
64 | let kind = NameKind::Local(local); | 71 | let kind = NameKind::Local(local); |
65 | let container = local.module(sb.db); | 72 | let container = local.module(sb.db); |
66 | Some(NameDefinition { kind, container, visibility: None }) | 73 | NameDefinition { kind, container, visibility: None } |
67 | } | 74 | } |
68 | PathResolution::TypeParam(par) => { | 75 | PathResolution::TypeParam(par) => { |
69 | let kind = NameKind::TypeParam(par); | 76 | let kind = NameKind::TypeParam(par); |
70 | let container = par.module(sb.db); | 77 | let container = par.module(sb.db); |
71 | Some(NameDefinition { kind, container, visibility }) | 78 | NameDefinition { kind, container, visibility } |
72 | } | 79 | } |
73 | PathResolution::Macro(def) => { | 80 | PathResolution::Macro(def) => { |
74 | let kind = NameKind::Macro(def); | 81 | let kind = NameKind::Macro(def); |
75 | Some(NameDefinition { kind, container, visibility }) | 82 | NameDefinition { kind, container, visibility } |
76 | } | 83 | } |
77 | PathResolution::SelfType(impl_block) => { | 84 | PathResolution::SelfType(impl_block) => { |
78 | let kind = NameKind::SelfType(impl_block); | 85 | let kind = NameKind::SelfType(impl_block); |
79 | let container = impl_block.module(sb.db); | 86 | let container = impl_block.module(sb.db); |
80 | Some(NameDefinition { kind, container, visibility }) | 87 | NameDefinition { kind, container, visibility } |
81 | } | 88 | } |
82 | } | 89 | }; |
90 | Some(res) | ||
83 | } | 91 | } |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index c5d249fe8..174e13595 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -320,19 +320,16 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
320 | fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { | 320 | fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { |
321 | match name_kind { | 321 | match name_kind { |
322 | Macro(_) => tags::MACRO, | 322 | Macro(_) => tags::MACRO, |
323 | Field(_) => tags::FIELD, | 323 | StructField(_) => tags::FIELD, |
324 | AssocItem(hir::AssocItem::Function(_)) => tags::FUNCTION, | 324 | ModuleDef(hir::ModuleDef::Module(_)) => tags::MODULE, |
325 | AssocItem(hir::AssocItem::Const(_)) => tags::CONSTANT, | 325 | ModuleDef(hir::ModuleDef::Function(_)) => tags::FUNCTION, |
326 | AssocItem(hir::AssocItem::TypeAlias(_)) => tags::TYPE, | 326 | ModuleDef(hir::ModuleDef::Adt(_)) => tags::TYPE, |
327 | Def(hir::ModuleDef::Module(_)) => tags::MODULE, | 327 | ModuleDef(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, |
328 | Def(hir::ModuleDef::Function(_)) => tags::FUNCTION, | 328 | ModuleDef(hir::ModuleDef::Const(_)) => tags::CONSTANT, |
329 | Def(hir::ModuleDef::Adt(_)) => tags::TYPE, | 329 | ModuleDef(hir::ModuleDef::Static(_)) => tags::CONSTANT, |
330 | Def(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, | 330 | ModuleDef(hir::ModuleDef::Trait(_)) => tags::TYPE, |
331 | Def(hir::ModuleDef::Const(_)) => tags::CONSTANT, | 331 | ModuleDef(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, |
332 | Def(hir::ModuleDef::Static(_)) => tags::CONSTANT, | 332 | ModuleDef(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, |
333 | Def(hir::ModuleDef::Trait(_)) => tags::TYPE, | ||
334 | Def(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, | ||
335 | Def(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, | ||
336 | SelfType(_) => tags::TYPE_SELF, | 333 | SelfType(_) => tags::TYPE_SELF, |
337 | TypeParam(_) => tags::TYPE_PARAM, | 334 | TypeParam(_) => tags::TYPE_PARAM, |
338 | Local(local) => { | 335 | Local(local) => { |
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 788906723..030f44f86 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). | 6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). |
7 | 7 | ||
8 | use hir::{ | 8 | use hir::{ |
9 | Adt, AssocItem, HasSource, ImplBlock, InFile, Local, MacroDef, Module, ModuleDef, SourceBinder, | 9 | Adt, HasSource, ImplBlock, InFile, Local, MacroDef, Module, ModuleDef, SourceBinder, |
10 | StructField, TypeParam, VariantDef, | 10 | StructField, TypeParam, VariantDef, |
11 | }; | 11 | }; |
12 | use ra_prof::profile; | 12 | use ra_prof::profile; |
@@ -20,9 +20,8 @@ use crate::RootDatabase; | |||
20 | #[derive(Debug, PartialEq, Eq)] | 20 | #[derive(Debug, PartialEq, Eq)] |
21 | pub enum NameKind { | 21 | pub enum NameKind { |
22 | Macro(MacroDef), | 22 | Macro(MacroDef), |
23 | Field(StructField), | 23 | StructField(StructField), |
24 | AssocItem(AssocItem), | 24 | ModuleDef(ModuleDef), |
25 | Def(ModuleDef), | ||
26 | SelfType(ImplBlock), | 25 | SelfType(ImplBlock), |
27 | Local(Local), | 26 | Local(Local), |
28 | TypeParam(TypeParam), | 27 | TypeParam(TypeParam), |
@@ -92,29 +91,17 @@ pub fn classify_name( | |||
92 | ast::FnDef(it) => { | 91 | ast::FnDef(it) => { |
93 | let src = name.with_value(it); | 92 | let src = name.with_value(it); |
94 | let def: hir::Function = sb.to_def(src)?; | 93 | let def: hir::Function = sb.to_def(src)?; |
95 | if parent.parent().and_then(ast::ItemList::cast).map_or(false, |it| it.syntax().parent().and_then(ast::Module::cast).is_none()) { | 94 | Some(from_module_def(sb.db, def.into(), None)) |
96 | Some(from_assoc_item(sb.db, def.into())) | ||
97 | } else { | ||
98 | Some(from_module_def(sb.db, def.into(), None)) | ||
99 | } | ||
100 | }, | 95 | }, |
101 | ast::ConstDef(it) => { | 96 | ast::ConstDef(it) => { |
102 | let src = name.with_value(it); | 97 | let src = name.with_value(it); |
103 | let def: hir::Const = sb.to_def(src)?; | 98 | let def: hir::Const = sb.to_def(src)?; |
104 | if parent.parent().and_then(ast::ItemList::cast).is_some() { | 99 | Some(from_module_def(sb.db, def.into(), None)) |
105 | Some(from_assoc_item(sb.db, def.into())) | ||
106 | } else { | ||
107 | Some(from_module_def(sb.db, def.into(), None)) | ||
108 | } | ||
109 | }, | 100 | }, |
110 | ast::TypeAliasDef(it) => { | 101 | ast::TypeAliasDef(it) => { |
111 | let src = name.with_value(it); | 102 | let src = name.with_value(it); |
112 | let def: hir::TypeAlias = sb.to_def(src)?; | 103 | let def: hir::TypeAlias = sb.to_def(src)?; |
113 | if parent.parent().and_then(ast::ItemList::cast).is_some() { | 104 | Some(from_module_def(sb.db, def.into(), None)) |
114 | Some(from_assoc_item(sb.db, def.into())) | ||
115 | } else { | ||
116 | Some(from_module_def(sb.db, def.into(), None)) | ||
117 | } | ||
118 | }, | 105 | }, |
119 | ast::MacroCall(it) => { | 106 | ast::MacroCall(it) => { |
120 | let src = name.with_value(it); | 107 | let src = name.with_value(it); |
@@ -142,19 +129,8 @@ pub fn classify_name( | |||
142 | } | 129 | } |
143 | } | 130 | } |
144 | 131 | ||
145 | pub fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { | ||
146 | let container = item.module(db); | ||
147 | let visibility = match item { | ||
148 | AssocItem::Function(f) => f.source(db).value.visibility(), | ||
149 | AssocItem::Const(c) => c.source(db).value.visibility(), | ||
150 | AssocItem::TypeAlias(a) => a.source(db).value.visibility(), | ||
151 | }; | ||
152 | let kind = NameKind::AssocItem(item); | ||
153 | NameDefinition { kind, container, visibility } | ||
154 | } | ||
155 | |||
156 | pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition { | 132 | pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition { |
157 | let kind = NameKind::Field(field); | 133 | let kind = NameKind::StructField(field); |
158 | let parent = field.parent_def(db); | 134 | let parent = field.parent_def(db); |
159 | let container = parent.module(db); | 135 | let container = parent.module(db); |
160 | let visibility = match parent { | 136 | let visibility = match parent { |
@@ -170,7 +146,7 @@ pub fn from_module_def( | |||
170 | def: ModuleDef, | 146 | def: ModuleDef, |
171 | module: Option<Module>, | 147 | module: Option<Module>, |
172 | ) -> NameDefinition { | 148 | ) -> NameDefinition { |
173 | let kind = NameKind::Def(def); | 149 | let kind = NameKind::ModuleDef(def); |
174 | let (container, visibility) = match def { | 150 | let (container, visibility) = match def { |
175 | ModuleDef::Module(it) => { | 151 | ModuleDef::Module(it) => { |
176 | let container = it.parent(db).or_else(|| Some(it)).unwrap(); | 152 | let container = it.parent(db).or_else(|| Some(it)).unwrap(); |
diff --git a/crates/ra_ide_db/src/imports_locator.rs b/crates/ra_ide_db/src/imports_locator.rs index 401b8ac0b..86383bcd0 100644 --- a/crates/ra_ide_db/src/imports_locator.rs +++ b/crates/ra_ide_db/src/imports_locator.rs | |||
@@ -44,7 +44,7 @@ impl<'a> ImportsLocator<'a> { | |||
44 | .chain(lib_results.into_iter()) | 44 | .chain(lib_results.into_iter()) |
45 | .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) | 45 | .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) |
46 | .filter_map(|name_definition_to_import| match name_definition_to_import { | 46 | .filter_map(|name_definition_to_import| match name_definition_to_import { |
47 | NameKind::Def(module_def) => Some(module_def), | 47 | NameKind::ModuleDef(module_def) => Some(module_def), |
48 | _ => None, | 48 | _ => None, |
49 | }) | 49 | }) |
50 | .collect() | 50 | .collect() |