diff options
author | Aleksey Kladov <[email protected]> | 2019-01-24 12:40:52 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-24 12:40:52 +0000 |
commit | 2734636c532101565b1a4c4715790d4cc910ad47 (patch) | |
tree | e928bd977376f1cbd6b14c15fbe10ade7d09d709 /crates | |
parent | 1754dd9fdd1bf7d3d72aa2bcb25f33fd8885cd7c (diff) |
update ide_api to new hir
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_context.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/navigation_target.rs | 12 |
5 files changed, 14 insertions, 10 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 0d7942496..3aef479d9 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -44,6 +44,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
44 | } | 44 | } |
45 | _ => return, | 45 | _ => return, |
46 | }, | 46 | }, |
47 | |||
48 | hir::ModuleDef::Function(_) => return, | ||
47 | }; | 49 | }; |
48 | } | 50 | } |
49 | 51 | ||
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index ca2069e2a..578af6e5b 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs | |||
@@ -127,7 +127,7 @@ impl<'a> CompletionContext<'a> { | |||
127 | .ancestors() | 127 | .ancestors() |
128 | .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) | 128 | .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) |
129 | .find_map(ast::FnDef::cast); | 129 | .find_map(ast::FnDef::cast); |
130 | match (&self.module, self.function_syntax) { | 130 | match (self.module, self.function_syntax) { |
131 | (Some(module), Some(fn_def)) => { | 131 | (Some(module), Some(fn_def)) => { |
132 | let function = source_binder::function_from_module(self.db, module, fn_def); | 132 | let function = source_binder::function_from_module(self.db, module, fn_def); |
133 | self.function = Some(function); | 133 | self.function = Some(function); |
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 5d6718a8d..5b2ba7e4a 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -219,6 +219,7 @@ impl Builder { | |||
219 | }; | 219 | }; |
220 | let (kind, docs) = match def { | 220 | let (kind, docs) = match def { |
221 | hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None), | 221 | hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None), |
222 | hir::ModuleDef::Function(func) => return self.from_function(ctx, func), | ||
222 | hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { | 223 | hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { |
223 | hir::Def::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), | 224 | hir::Def::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), |
224 | hir::Def::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), | 225 | hir::Def::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), |
@@ -226,7 +227,6 @@ impl Builder { | |||
226 | hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), | 227 | hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), |
227 | hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), | 228 | hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), |
228 | hir::Def::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), | 229 | hir::Def::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), |
229 | hir::Def::Function(function) => return self.from_function(ctx, function), | ||
230 | _ => return self, | 230 | _ => return self, |
231 | }, | 231 | }, |
232 | }; | 232 | }; |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 323bb1cc1..46bdde00d 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -63,13 +63,11 @@ pub(crate) fn reference_definition( | |||
63 | let infer_result = function.infer(db); | 63 | let infer_result = function.infer(db); |
64 | let syntax_mapping = function.body_syntax_mapping(db); | 64 | let syntax_mapping = function.body_syntax_mapping(db); |
65 | let expr = ast::Expr::cast(method_call.syntax()).unwrap(); | 65 | let expr = ast::Expr::cast(method_call.syntax()).unwrap(); |
66 | if let Some(def_id) = syntax_mapping | 66 | if let Some(func) = syntax_mapping |
67 | .node_expr(expr) | 67 | .node_expr(expr) |
68 | .and_then(|it| infer_result.method_resolution(it)) | 68 | .and_then(|it| infer_result.method_resolution(it)) |
69 | { | 69 | { |
70 | if let Some(target) = NavigationTarget::from_def(db, hir::ModuleDef::Def(def_id)) { | 70 | return Exact(NavigationTarget::from_function(db, func)); |
71 | return Exact(target); | ||
72 | } | ||
73 | }; | 71 | }; |
74 | } | 72 | } |
75 | } | 73 | } |
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 1eb177665..19cea2fd6 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs | |||
@@ -96,6 +96,11 @@ impl NavigationTarget { | |||
96 | NavigationTarget::from_module(db, module) | 96 | NavigationTarget::from_module(db, module) |
97 | } | 97 | } |
98 | 98 | ||
99 | pub(crate) fn from_function(db: &RootDatabase, func: hir::Function) -> NavigationTarget { | ||
100 | let (file_id, fn_def) = func.source(db); | ||
101 | NavigationTarget::from_named(file_id.original_file(db), &*fn_def) | ||
102 | } | ||
103 | |||
99 | // TODO once Def::Item is gone, this should be able to always return a NavigationTarget | 104 | // TODO once Def::Item is gone, this should be able to always return a NavigationTarget |
100 | pub(crate) fn from_def( | 105 | pub(crate) fn from_def( |
101 | db: &RootDatabase, | 106 | db: &RootDatabase, |
@@ -106,6 +111,9 @@ impl NavigationTarget { | |||
106 | hir::ModuleDef::Module(module) => { | 111 | hir::ModuleDef::Module(module) => { |
107 | return Some(NavigationTarget::from_module(db, module)); | 112 | return Some(NavigationTarget::from_module(db, module)); |
108 | } | 113 | } |
114 | hir::ModuleDef::Function(func) => { | ||
115 | return Some(NavigationTarget::from_function(db, func)); | ||
116 | } | ||
109 | }; | 117 | }; |
110 | 118 | ||
111 | let res = match def { | 119 | let res = match def { |
@@ -121,10 +129,6 @@ impl NavigationTarget { | |||
121 | let (file_id, node) = ev.source(db); | 129 | let (file_id, node) = ev.source(db); |
122 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 130 | NavigationTarget::from_named(file_id.original_file(db), &*node) |
123 | } | 131 | } |
124 | Def::Function(f) => { | ||
125 | let (file_id, node) = f.source(db); | ||
126 | NavigationTarget::from_named(file_id.original_file(db), &*node) | ||
127 | } | ||
128 | Def::Trait(f) => { | 132 | Def::Trait(f) => { |
129 | let (file_id, node) = f.source(db); | 133 | let (file_id, node) = f.source(db); |
130 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 134 | NavigationTarget::from_named(file_id.original_file(db), &*node) |