From 9446be29992fe14ec529874622311c3ae7a49b0e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:43:25 +0300 Subject: remove Cancelable from adt API --- crates/ra_ide_api/src/completion/complete_dot.rs | 2 +- crates/ra_ide_api/src/completion/complete_path.rs | 2 +- crates/ra_ide_api/src/navigation_target.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 37985b398..bf6d91a09 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -29,7 +29,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) Ty::Adt { def_id, .. } => { match def_id.resolve(ctx.db)? { Def::Struct(s) => { - for field in s.fields(ctx.db)? { + for field in s.fields(ctx.db) { CompletionItem::new( CompletionKind::Reference, field.name().to_string(), diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index a25ad3f13..6388197be 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -22,7 +22,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C } } hir::Def::Enum(e) => { - e.variants(ctx.db)? + e.variants(ctx.db) .into_iter() .for_each(|(variant_name, _variant)| { CompletionItem::new(CompletionKind::Reference, variant_name.to_string()) diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 7562b9a1f..306dbfd92 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -112,15 +112,15 @@ impl NavigationTarget { pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable> { let res = match def { Def::Struct(s) => { - let (file_id, node) = s.source(db)?; + let (file_id, node) = s.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::Enum(e) => { - let (file_id, node) = e.source(db)?; + let (file_id, node) = e.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::EnumVariant(ev) => { - let (file_id, node) = ev.source(db)?; + let (file_id, node) = ev.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::Function(f) => { -- cgit v1.2.3 From 9dd4099d9388b5f61e99f923dd6c523f76ad43ff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:45:01 +0300 Subject: remove Cancelable from static&const API --- crates/ra_ide_api/src/navigation_target.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 306dbfd92..965dfc0ca 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -128,19 +128,19 @@ impl NavigationTarget { NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::Trait(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::Type(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::Static(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::Const(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::Module(m) => NavigationTarget::from_module(db, m)?, -- cgit v1.2.3 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_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 +- 6 files changed, 18 insertions(+), 30 deletions(-) (limited to 'crates/ra_ide_api/src') 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