From f1367e0370d5de5cba13c853c7df5f0c5a0edf59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:50:16 +0300 Subject: remove Cancelable from navigation target --- crates/ra_hir/src/code_model_api.rs | 4 +-- crates/ra_hir/src/code_model_impl/module.rs | 2 +- crates/ra_hir/src/expr.rs | 4 +-- crates/ra_hir/src/ids.rs | 7 ++--- crates/ra_hir/src/ty.rs | 6 ++-- crates/ra_ide_api/src/completion/complete_dot.rs | 2 +- crates/ra_ide_api/src/completion/complete_path.rs | 2 +- .../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 | 34 +++++++--------------- crates/ra_ide_api/src/parent_module.rs | 2 +- 11 files changed, 29 insertions(+), 42 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index f6d1d6b23..f28e077c6 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -297,8 +297,8 @@ impl Function { self.def_id } - pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable> { diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index f27523753..331b0500e 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -148,7 +148,7 @@ impl Module { } else { return Ok(PerNs::none()); }; - let module = match curr.resolve(db)? { + let module = match curr.resolve(db) { Def::Module(it) => it, Def::Enum(e) => { if segments.len() == idx + 1 { diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 5081466a2..a1e8da348 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -832,10 +832,10 @@ pub(crate) fn body_syntax_mapping( db: &impl HirDatabase, def_id: DefId, ) -> Cancelable> { - let def = def_id.resolve(db)?; + let def = def_id.resolve(db); let body_syntax_mapping = match def { - Def::Function(f) => collect_fn_body_syntax(&f.source(db)?.1), + Def::Function(f) => collect_fn_body_syntax(&f.source(db).1), // TODO: consts, etc. _ => panic!("Trying to get body for item type without body"), }; diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 7b572061a..3cbf8070f 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -159,9 +159,9 @@ impl DefId { db.as_ref().id2loc(self) } - pub fn resolve(self, db: &impl HirDatabase) -> Cancelable { + pub fn resolve(self, db: &impl HirDatabase) -> Def { let loc = self.loc(db); - let res = match loc.kind { + match loc.kind { DefKind::Module => { let module = Module::from_module_id(db, loc.source_root_id, loc.module_id); Def::Module(module) @@ -195,8 +195,7 @@ impl DefId { DefKind::StructCtor => Def::Item, DefKind::Item => Def::Item, - }; - Ok(res) + } } pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index b0642d905..3607969ed 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -481,7 +481,7 @@ pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> C } pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable { - let def = def_id.resolve(db)?; + let def = def_id.resolve(db); match def { Def::Module(..) => { log::debug!("trying to get type for module {:?}", def_id); @@ -507,7 +507,7 @@ pub(super) fn type_for_field( def_id: DefId, field: Name, ) -> Cancelable> { - let def = def_id.resolve(db)?; + let def = def_id.resolve(db); let variant_data = match def { Def::Struct(s) => s.variant_data(db)?, Def::EnumVariant(ev) => ev.variant_data(db), @@ -877,7 +877,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } else { return Ok((Ty::Unknown, None)); }; - Ok(match def_id.resolve(self.db)? { + Ok(match def_id.resolve(self.db) { Def::Struct(s) => { let ty = type_for_struct(self.db, s)?; (ty, Some(def_id)) diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index bf6d91a09..886dc54d4 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -27,7 +27,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) for receiver in receiver.autoderef(ctx.db) { match receiver { Ty::Adt { def_id, .. } => { - match def_id.resolve(ctx.db)? { + match def_id.resolve(ctx.db) { Def::Struct(s) => { for field in s.fields(ctx.db) { CompletionItem::new( diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 6388197be..207a509b3 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -12,7 +12,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C Some(it) => it, None => return Ok(()), }; - match def_id.resolve(ctx.db)? { + match def_id.resolve(ctx.db) { hir::Def::Module(module) => { let module_scope = module.scope(ctx.db)?; for (name, res) in module_scope.entries() { diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index b75d65de3..11d00f78c 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -144,7 +144,7 @@ impl Builder { ctx: &CompletionContext, resolution: &hir::Resolution, ) -> Builder { - let resolved = resolution.def_id.and_then(|d| d.resolve(ctx.db).ok()); + let resolved = resolution.def_id.map(|d| d.resolve(ctx.db)); let kind = match resolved { PerNs { types: Some(hir::Def::Module(..)), diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 591f36cce..7229293a4 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -70,7 +70,7 @@ pub(crate) fn reference_definition( .node_expr(expr) .and_then(|it| infer_result.method_resolution(it)) { - if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)?)? { + if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { return Ok(Exact(target)); } }; @@ -87,7 +87,7 @@ pub(crate) fn reference_definition( { let resolved = module.resolve_path(db, &path)?; if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { - if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)?)? { + if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { return Ok(Exact(target)); } } @@ -112,7 +112,7 @@ fn name_definition( if let Some(child_module) = hir::source_binder::module_from_declaration(db, file_id, module) { - let nav = NavigationTarget::from_module(db, child_module)?; + let nav = NavigationTarget::from_module(db, child_module); return Ok(Some(vec![nav])); } } diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 965dfc0ca..21c15c0c0 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -1,4 +1,4 @@ -use ra_db::{FileId, Cancelable}; +use ra_db::FileId; use ra_syntax::{ SyntaxNode, AstNode, SmolStr, TextRange, ast, SyntaxKind::{self, NAME}, @@ -69,47 +69,35 @@ impl NavigationTarget { } } - pub(crate) fn from_module( - db: &RootDatabase, - module: hir::Module, - ) -> Cancelable { + pub(crate) fn from_module(db: &RootDatabase, module: hir::Module) -> NavigationTarget { let (file_id, source) = module.definition_source(db); let name = module .name(db) .map(|it| it.to_string().into()) .unwrap_or_default(); - let res = match source { + match source { ModuleSource::SourceFile(node) => { NavigationTarget::from_syntax(file_id, name, None, node.syntax()) } ModuleSource::Module(node) => { NavigationTarget::from_syntax(file_id, name, None, node.syntax()) } - }; - Ok(res) + } } - pub(crate) fn from_module_to_decl( - db: &RootDatabase, - module: hir::Module, - ) -> Cancelable { + pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { let name = module .name(db) .map(|it| it.to_string().into()) .unwrap_or_default(); if let Some((file_id, source)) = module.declaration_source(db) { - return Ok(NavigationTarget::from_syntax( - file_id, - name, - None, - source.syntax(), - )); + return NavigationTarget::from_syntax(file_id, name, None, source.syntax()); } NavigationTarget::from_module(db, module) } // TODO once Def::Item is gone, this should be able to always return a NavigationTarget - pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable> { + pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Option { let res = match def { Def::Struct(s) => { let (file_id, node) = s.source(db); @@ -124,7 +112,7 @@ impl NavigationTarget { NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::Function(f) => { - let (file_id, node) = f.source(db)?; + let (file_id, node) = f.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::Trait(f) => { @@ -143,10 +131,10 @@ impl NavigationTarget { let (file_id, node) = f.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } - Def::Module(m) => NavigationTarget::from_module(db, m)?, - Def::Item => return Ok(None), + Def::Module(m) => NavigationTarget::from_module(db, m), + Def::Item => return None, }; - Ok(Some(res)) + Some(res) } #[cfg(test)] diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index 451304739..379b3f3a4 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs @@ -12,7 +12,7 @@ pub(crate) fn parent_module( None => return Ok(Vec::new()), Some(it) => it, }; - let nav = NavigationTarget::from_module_to_decl(db, module)?; + let nav = NavigationTarget::from_module_to_decl(db, module); Ok(vec![nav]) } -- cgit v1.2.3