From aea1f95a665b56da5953907a122475db0c9a9c44 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Jan 2019 19:04:02 +0300 Subject: adapt ide_api to the new API --- crates/ra_ide_api/src/completion/complete_dot.rs | 32 ++++++++++---------- crates/ra_ide_api/src/completion/complete_path.rs | 35 ++++++++++------------ .../ra_ide_api/src/completion/completion_item.rs | 4 +-- crates/ra_ide_api/src/navigation_target.rs | 20 ++++++++----- 4 files changed, 45 insertions(+), 46 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 1a2b0b2f6..d0fa8146c 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -1,4 +1,4 @@ -use hir::{Ty, Def, AdtDef}; +use hir::{Ty, AdtDef}; use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind}; use crate::completion::completion_item::CompletionKind; @@ -29,23 +29,21 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) def_id, ref substs, .. } => { match def_id { - AdtDef::Struct() => {} - AdtDef::Def(def_id) => match def_id.resolve(ctx.db) { - Def::Struct(s) => { - for field in s.fields(ctx.db) { - CompletionItem::new( - CompletionKind::Reference, - ctx.source_range(), - field.name().to_string(), - ) - .kind(CompletionItemKind::Field) - .set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string())) - .add_to(acc); - } + AdtDef::Struct(s) => { + for field in s.fields(ctx.db) { + CompletionItem::new( + CompletionKind::Reference, + ctx.source_range(), + field.name().to_string(), + ) + .kind(CompletionItemKind::Field) + .set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string())) + .add_to(acc); } - // TODO unions - _ => {} - }, + } + + // TODO unions + AdtDef::Enum(_) => (), } } Ty::Tuple(fields) => { diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 3aef479d9..e039a333c 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -26,26 +26,21 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { .add_to(acc); } } - - hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { - hir::Def::Enum(e) => { - e.variants(ctx.db) - .into_iter() - .for_each(|(variant_name, variant)| { - CompletionItem::new( - CompletionKind::Reference, - ctx.source_range(), - variant_name.to_string(), - ) - .kind(CompletionItemKind::EnumVariant) - .set_documentation(variant.docs(ctx.db)) - .add_to(acc) - }); - } - _ => return, - }, - - hir::ModuleDef::Function(_) => return, + hir::ModuleDef::Enum(e) => { + e.variants(ctx.db) + .into_iter() + .for_each(|(variant_name, variant)| { + CompletionItem::new( + CompletionKind::Reference, + ctx.source_range(), + variant_name.to_string(), + ) + .kind(CompletionItemKind::EnumVariant) + .set_documentation(variant.docs(ctx.db)) + .add_to(acc) + }); + } + hir::ModuleDef::Function(_) | hir::ModuleDef::Struct(_) | hir::ModuleDef::Def(_) => return, }; } diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 5b2ba7e4a..f2301653a 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -220,9 +220,9 @@ 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::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), + hir::ModuleDef::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), 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)), hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 19cea2fd6..b92670f36 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -114,17 +114,23 @@ impl NavigationTarget { hir::ModuleDef::Function(func) => { return Some(NavigationTarget::from_function(db, func)); } - }; - - let res = match def { - Def::Struct(s) => { + hir::ModuleDef::Struct(s) => { let (file_id, node) = s.source(db); - NavigationTarget::from_named(file_id.original_file(db), &*node) + return Some(NavigationTarget::from_named( + file_id.original_file(db), + &*node, + )); } - Def::Enum(e) => { + hir::ModuleDef::Enum(e) => { let (file_id, node) = e.source(db); - NavigationTarget::from_named(file_id.original_file(db), &*node) + return Some(NavigationTarget::from_named( + file_id.original_file(db), + &*node, + )); } + }; + + let res = match def { Def::EnumVariant(ev) => { let (file_id, node) = ev.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) -- cgit v1.2.3