From 2734636c532101565b1a4c4715790d4cc910ad47 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Jan 2019 15:40:52 +0300 Subject: update ide_api to new hir --- crates/ra_ide_api/src/completion/complete_path.rs | 2 ++ crates/ra_ide_api/src/completion/completion_context.rs | 2 +- crates/ra_ide_api/src/completion/completion_item.rs | 2 +- crates/ra_ide_api/src/goto_definition.rs | 6 ++---- 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) { } _ => return, }, + + hir::ModuleDef::Function(_) => return, }; } 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> { .ancestors() .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) .find_map(ast::FnDef::cast); - match (&self.module, self.function_syntax) { + match (self.module, self.function_syntax) { (Some(module), Some(fn_def)) => { let function = source_binder::function_from_module(self.db, module, fn_def); 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 { }; let (kind, docs) = match def { hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None), + hir::ModuleDef::Function(func) => return self.from_function(ctx, func), hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { hir::Def::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), hir::Def::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), @@ -226,7 +227,6 @@ impl Builder { hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), hir::Def::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), - hir::Def::Function(function) => return self.from_function(ctx, function), _ => return self, }, }; 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( let infer_result = function.infer(db); let syntax_mapping = function.body_syntax_mapping(db); let expr = ast::Expr::cast(method_call.syntax()).unwrap(); - if let Some(def_id) = syntax_mapping + if let Some(func) = syntax_mapping .node_expr(expr) .and_then(|it| infer_result.method_resolution(it)) { - if let Some(target) = NavigationTarget::from_def(db, hir::ModuleDef::Def(def_id)) { - return Exact(target); - } + return Exact(NavigationTarget::from_function(db, func)); }; } } 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 { NavigationTarget::from_module(db, module) } + pub(crate) fn from_function(db: &RootDatabase, func: hir::Function) -> NavigationTarget { + let (file_id, fn_def) = func.source(db); + NavigationTarget::from_named(file_id.original_file(db), &*fn_def) + } + // TODO once Def::Item is gone, this should be able to always return a NavigationTarget pub(crate) fn from_def( db: &RootDatabase, @@ -106,6 +111,9 @@ impl NavigationTarget { hir::ModuleDef::Module(module) => { return Some(NavigationTarget::from_module(db, module)); } + hir::ModuleDef::Function(func) => { + return Some(NavigationTarget::from_function(db, func)); + } }; let res = match def { @@ -121,10 +129,6 @@ impl NavigationTarget { let (file_id, node) = ev.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } - Def::Function(f) => { - let (file_id, node) = f.source(db); - NavigationTarget::from_named(file_id.original_file(db), &*node) - } Def::Trait(f) => { let (file_id, node) = f.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) -- cgit v1.2.3