aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-09-12 22:10:16 +0100
committerAleksey Kladov <[email protected]>2019-09-12 22:10:16 +0100
commit45117c63884366ee82102a782a62a09fefff746b (patch)
treeb66d9ca105e39b96b78bf7f3659d1858577a2c8c /crates/ra_ide_api
parentd8b621cf26b59ff5ae9379b50fc822590b6a3a4e (diff)
make various enums "inherit" from AdtDef
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs13
-rw-r--r--crates/ra_ide_api/src/completion/complete_pattern.rs2
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs12
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs4
-rw-r--r--crates/ra_ide_api/src/hover.rs12
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs4
6 files changed, 24 insertions, 23 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index 457a3d10c..df14f465a 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -1,4 +1,4 @@
1use hir::{Either, Resolution}; 1use hir::{AdtDef, Either, Resolution};
2use ra_syntax::AstNode; 2use ra_syntax::AstNode;
3use test_utils::tested_by; 3use test_utils::tested_by;
4 4
@@ -37,19 +37,14 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
37 acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def)); 37 acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def));
38 } 38 }
39 } 39 }
40 hir::ModuleDef::Enum(_) 40 hir::ModuleDef::AdtDef(_) | hir::ModuleDef::TypeAlias(_) => {
41 | hir::ModuleDef::Struct(_) 41 if let hir::ModuleDef::AdtDef(AdtDef::Enum(e)) = def {
42 | hir::ModuleDef::Union(_)
43 | hir::ModuleDef::TypeAlias(_) => {
44 if let hir::ModuleDef::Enum(e) = def {
45 for variant in e.variants(ctx.db) { 42 for variant in e.variants(ctx.db) {
46 acc.add_enum_variant(ctx, variant); 43 acc.add_enum_variant(ctx, variant);
47 } 44 }
48 } 45 }
49 let ty = match def { 46 let ty = match def {
50 hir::ModuleDef::Enum(e) => e.ty(ctx.db), 47 hir::ModuleDef::AdtDef(adt) => adt.ty(ctx.db),
51 hir::ModuleDef::Struct(s) => s.ty(ctx.db),
52 hir::ModuleDef::Union(u) => u.ty(ctx.db),
53 hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), 48 hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db),
54 _ => unreachable!(), 49 _ => unreachable!(),
55 }; 50 };
diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs
index fb02844fa..05db973e4 100644
--- a/crates/ra_ide_api/src/completion/complete_pattern.rs
+++ b/crates/ra_ide_api/src/completion/complete_pattern.rs
@@ -15,7 +15,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
15 _ => continue, 15 _ => continue,
16 }; 16 };
17 match def { 17 match def {
18 hir::ModuleDef::Enum(..) 18 hir::ModuleDef::AdtDef(hir::AdtDef::Enum(..))
19 | hir::ModuleDef::EnumVariant(..) 19 | hir::ModuleDef::EnumVariant(..)
20 | hir::ModuleDef::Const(..) 20 | hir::ModuleDef::Const(..)
21 | hir::ModuleDef::Module(..) => (), 21 | hir::ModuleDef::Module(..) => (),
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 5cabe9a32..e9bf2b96d 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -67,9 +67,15 @@ impl Completions {
67 Resolution::Def(Function(func)) => { 67 Resolution::Def(Function(func)) => {
68 return self.add_function_with_name(ctx, Some(local_name), *func); 68 return self.add_function_with_name(ctx, Some(local_name), *func);
69 } 69 }
70 Resolution::Def(Struct(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), 70 Resolution::Def(AdtDef(hir::AdtDef::Struct(it))) => {
71 Resolution::Def(Union(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), 71 (CompletionItemKind::Struct, it.docs(ctx.db))
72 Resolution::Def(Enum(it)) => (CompletionItemKind::Enum, it.docs(ctx.db)), 72 }
73 Resolution::Def(AdtDef(hir::AdtDef::Union(it))) => {
74 (CompletionItemKind::Struct, it.docs(ctx.db))
75 }
76 Resolution::Def(AdtDef(hir::AdtDef::Enum(it))) => {
77 (CompletionItemKind::Enum, it.docs(ctx.db))
78 }
73 Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), 79 Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)),
74 Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), 80 Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)),
75 Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), 81 Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)),
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index c85214bb3..b8085f077 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -193,9 +193,7 @@ impl NavigationTarget {
193 let nav = match module_def { 193 let nav = match module_def {
194 hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), 194 hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
195 hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func), 195 hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func),
196 hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()), 196 hir::ModuleDef::AdtDef(it) => NavigationTarget::from_adt_def(db, it),
197 hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()),
198 hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
199 hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), 197 hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it),
200 hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), 198 hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it),
201 hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it), 199 hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it),
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 4b7847de8..f7b7cb8f8 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,4 +1,4 @@
1use hir::{HasSource, HirDisplay}; 1use hir::{AdtDef, HasSource, HirDisplay};
2use ra_db::SourceDatabase; 2use ra_db::SourceDatabase;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::{ 4 algo::{
@@ -129,9 +129,13 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
129 } 129 }
130 } 130 }
131 hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)), 131 hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)),
132 hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)), 132 hir::ModuleDef::AdtDef(AdtDef::Struct(it)) => {
133 hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)), 133 res.extend(from_def_source(db, it))
134 hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)), 134 }
135 hir::ModuleDef::AdtDef(AdtDef::Union(it)) => {
136 res.extend(from_def_source(db, it))
137 }
138 hir::ModuleDef::AdtDef(AdtDef::Enum(it)) => res.extend(from_def_source(db, it)),
135 hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), 139 hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)),
136 hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), 140 hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)),
137 hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), 141 hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)),
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index 06ccf0728..ee7531d37 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -107,9 +107,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
107 Some(AssocItem(hir::ImplItem::TypeAlias(_))) => "type", 107 Some(AssocItem(hir::ImplItem::TypeAlias(_))) => "type",
108 Some(Def(hir::ModuleDef::Module(_))) => "module", 108 Some(Def(hir::ModuleDef::Module(_))) => "module",
109 Some(Def(hir::ModuleDef::Function(_))) => "function", 109 Some(Def(hir::ModuleDef::Function(_))) => "function",
110 Some(Def(hir::ModuleDef::Struct(_))) => "type", 110 Some(Def(hir::ModuleDef::AdtDef(_))) => "type",
111 Some(Def(hir::ModuleDef::Union(_))) => "type",
112 Some(Def(hir::ModuleDef::Enum(_))) => "type",
113 Some(Def(hir::ModuleDef::EnumVariant(_))) => "constant", 111 Some(Def(hir::ModuleDef::EnumVariant(_))) => "constant",
114 Some(Def(hir::ModuleDef::Const(_))) => "constant", 112 Some(Def(hir::ModuleDef::Const(_))) => "constant",
115 Some(Def(hir::ModuleDef::Static(_))) => "constant", 113 Some(Def(hir::ModuleDef::Static(_))) => "constant",