From 3ab1519cb27b927074ed7fbbb18a856e6e7fabb8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 23 Jan 2019 23:14:13 +0300 Subject: Change ids strategy this is a part of larghish hir refactoring which aims to * replace per-source-root module trees with per crate trees * switch from a monotyped DedId to type-specific ids --- crates/ra_ide_api/src/completion/complete_path.rs | 37 +++++++------ .../ra_ide_api/src/completion/completion_item.rs | 61 ++++++++-------------- crates/ra_ide_api/src/db.rs | 1 + crates/ra_ide_api/src/goto_definition.rs | 4 +- crates/ra_ide_api/src/navigation_target.rs | 13 ++++- crates/ra_ide_api/src/rename.rs | 25 +++++---- .../src/snapshots/tests__rename_mod.snap | 10 ++-- 7 files changed, 76 insertions(+), 75 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index e44b76c4a..0d7942496 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -13,8 +13,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { Some(it) => it, None => return, }; - match def_id.resolve(ctx.db) { - hir::Def::Module(module) => { + match def_id { + hir::ModuleDef::Module(module) => { let module_scope = module.scope(ctx.db); for (name, res) in module_scope.entries() { CompletionItem::new( @@ -26,21 +26,24 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { .add_to(acc); } } - 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::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, + }, }; } diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 18c151932..5d6718a8d 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -1,6 +1,4 @@ -use hir::{Docs, Documentation, PerNs}; - -use crate::completion::completion_context::CompletionContext; +use hir::{Docs, Documentation}; use ra_syntax::{ ast::{self, AstNode}, TextRange, @@ -8,6 +6,8 @@ use ra_syntax::{ use ra_text_edit::TextEdit; use test_utils::tested_by; +use crate::completion::completion_context::CompletionContext; + /// `CompletionItem` describes a single completion variant in the editor pop-up. /// It is basically a POD with various properties. To construct a /// `CompletionItem`, use `new` method and the `Builder` struct. @@ -209,41 +209,26 @@ impl Builder { ctx: &CompletionContext, resolution: &hir::Resolution, ) -> Builder { - let resolved = resolution.def_id.map(|d| d.resolve(ctx.db)); - let (kind, docs) = match resolved { - PerNs { - types: Some(hir::Def::Module(..)), - .. - } => (CompletionItemKind::Module, None), - PerNs { - types: Some(hir::Def::Struct(s)), - .. - } => (CompletionItemKind::Struct, s.docs(ctx.db)), - PerNs { - types: Some(hir::Def::Enum(e)), - .. - } => (CompletionItemKind::Enum, e.docs(ctx.db)), - PerNs { - types: Some(hir::Def::Trait(t)), - .. - } => (CompletionItemKind::Trait, t.docs(ctx.db)), - PerNs { - types: Some(hir::Def::Type(t)), - .. - } => (CompletionItemKind::TypeAlias, t.docs(ctx.db)), - PerNs { - values: Some(hir::Def::Const(c)), - .. - } => (CompletionItemKind::Const, c.docs(ctx.db)), - PerNs { - values: Some(hir::Def::Static(s)), - .. - } => (CompletionItemKind::Static, s.docs(ctx.db)), - PerNs { - values: Some(hir::Def::Function(function)), - .. - } => return self.from_function(ctx, function), - _ => return self, + let def = resolution + .def_id + .take_types() + .or(resolution.def_id.take_values()); + let def = match def { + None => return self, + Some(it) => it, + }; + let (kind, docs) = match def { + hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None), + 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)), + hir::Def::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), + hir::Def::Function(function) => return self.from_function(ctx, function), + _ => return self, + }, }; self.kind = Some(kind); self.documentation = docs; diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index ba0eb1cb8..bff6b7237 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -72,6 +72,7 @@ salsa::database_storage! { fn file_relative_path() for ra_db::FileRelativePathQuery; fn file_source_root() for ra_db::FileSourceRootQuery; fn source_root() for ra_db::SourceRootQuery; + fn source_root_crates() for ra_db::SourceRootCratesQuery; fn local_roots() for ra_db::LocalRootsQuery; fn library_roots() for ra_db::LibraryRootsQuery; fn crate_graph() for ra_db::CrateGraphQuery; diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index b1becca03..323bb1cc1 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -67,7 +67,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, hir::ModuleDef::Def(def_id)) { return Exact(target); } }; @@ -84,7 +84,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) { return Exact(target); } } diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 21c15c0c0..1eb177665 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -97,7 +97,17 @@ impl NavigationTarget { } // TODO once Def::Item is gone, this should be able to always return a NavigationTarget - pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Option { + pub(crate) fn from_def( + db: &RootDatabase, + module_def: hir::ModuleDef, + ) -> Option { + let def = match module_def { + hir::ModuleDef::Def(def_id) => def_id.resolve(db), + hir::ModuleDef::Module(module) => { + return Some(NavigationTarget::from_module(db, module)); + } + }; + let res = match def { Def::Struct(s) => { let (file_id, node) = s.source(db); @@ -131,7 +141,6 @@ 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 None, }; Some(res) diff --git a/crates/ra_ide_api/src/rename.rs b/crates/ra_ide_api/src/rename.rs index 53dc273c6..5b767addd 100644 --- a/crates/ra_ide_api/src/rename.rs +++ b/crates/ra_ide_api/src/rename.rs @@ -57,7 +57,6 @@ fn rename_mod( ) -> Option { let mut source_file_edits = Vec::new(); let mut file_system_edits = Vec::new(); - if let Some(module) = module_from_declaration(db, position.file_id, &ast_module) { let (file_id, module_source) = module.definition_source(db); match module_source { @@ -223,11 +222,15 @@ mod tests { fn test_rename_mod() { let (analysis, position) = analysis_and_position( " - //- /bar.rs - mod fo<|>o; - //- /bar/foo.rs - // emtpy - ", + //- /lib.rs + mod bar; + + //- /bar.rs + mod foo<|>; + + //- /bar/foo.rs + // emtpy + ", ); let new_name = "foo2"; let source_change = analysis.rename(position, new_name).unwrap(); @@ -238,11 +241,11 @@ mod tests { fn test_rename_mod_in_dir() { let (analysis, position) = analysis_and_position( " - //- /lib.rs - mod fo<|>o; - //- /foo/mod.rs - // emtpy - ", + //- /lib.rs + mod fo<|>o; + //- /foo/mod.rs + // emtpy + ", ); let new_name = "foo2"; let source_change = analysis.rename(position, new_name).unwrap(); diff --git a/crates/ra_ide_api/src/snapshots/tests__rename_mod.snap b/crates/ra_ide_api/src/snapshots/tests__rename_mod.snap index 3267d1ac5..890426db7 100644 --- a/crates/ra_ide_api/src/snapshots/tests__rename_mod.snap +++ b/crates/ra_ide_api/src/snapshots/tests__rename_mod.snap @@ -1,8 +1,8 @@ --- -created: "2019-01-22T14:45:00.975229300+00:00" -creator: insta@0.4.0 +created: "2019-01-24T08:39:53.759318522+00:00" +creator: insta@0.5.2 expression: "&source_change" -source: "crates\\ra_ide_api\\src\\rename.rs" +source: crates/ra_ide_api/src/rename.rs --- Some( SourceChange { @@ -10,7 +10,7 @@ Some( source_file_edits: [ SourceFileEdit { file_id: FileId( - 1 + 2 ), edit: TextEdit { atoms: [ @@ -25,7 +25,7 @@ Some( file_system_edits: [ MoveFile { src: FileId( - 2 + 3 ), dst_source_root: SourceRootId( 0 -- cgit v1.2.3 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(-) (limited to 'crates/ra_ide_api/src') 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 From 60a607d33f1c50acd0a4218da32abe35b2941e38 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Jan 2019 17:54:18 +0300 Subject: new struct id --- crates/ra_ide_api/src/completion/complete_dot.rs | 33 +++++++++++++----------- 1 file changed, 18 insertions(+), 15 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 32fd497be..1a2b0b2f6 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}; +use hir::{Ty, Def, AdtDef}; use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind}; use crate::completion::completion_item::CompletionKind; @@ -28,21 +28,24 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) Ty::Adt { def_id, ref substs, .. } => { - 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); + 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); + } } - } - // TODO unions - _ => {} + // TODO unions + _ => {} + }, } } Ty::Tuple(fields) => { -- cgit v1.2.3 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 From 6a5a1f590201ba962a1f77ce1a7ff5870712728d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Jan 2019 23:36:16 +0300 Subject: adapt ide_api to the new API --- crates/ra_ide_api/src/completion/complete_path.rs | 5 ++++- crates/ra_ide_api/src/completion/completion_item.rs | 1 + crates/ra_ide_api/src/navigation_target.rs | 11 +++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index e039a333c..4768efdc1 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -40,7 +40,10 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { .add_to(acc) }); } - hir::ModuleDef::Function(_) | hir::ModuleDef::Struct(_) | hir::ModuleDef::Def(_) => return, + hir::ModuleDef::Function(_) + | hir::ModuleDef::Struct(_) + | hir::ModuleDef::Def(_) + | hir::ModuleDef::EnumVariant(_) => return, }; } diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index f2301653a..ee1f8bce0 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -222,6 +222,7 @@ impl Builder { 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::EnumVariant(it) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), hir::Def::Type(it) => (CompletionItemKind::TypeAlias, 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 b92670f36..fc76338d2 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -128,13 +128,16 @@ impl NavigationTarget { &*node, )); } + hir::ModuleDef::EnumVariant(var) => { + let (file_id, node) = var.source(db); + 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) - } Def::Trait(f) => { let (file_id, node) = f.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) -- cgit v1.2.3 From 1db2cbcb8bd61b4f19f61cc6319343e5ad894515 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 00:50:08 +0300 Subject: move consts&statics to new id --- crates/ra_ide_api/src/completion/complete_path.rs | 2 ++ .../ra_ide_api/src/completion/completion_item.rs | 4 ++-- crates/ra_ide_api/src/navigation_target.rs | 22 ++++++++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 4768efdc1..bd5484516 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -43,6 +43,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { hir::ModuleDef::Function(_) | hir::ModuleDef::Struct(_) | hir::ModuleDef::Def(_) + | hir::ModuleDef::Const(_) + | hir::ModuleDef::Static(_) | hir::ModuleDef::EnumVariant(_) => return, }; } diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index ee1f8bce0..2f8ec41d2 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -223,11 +223,11 @@ impl Builder { hir::ModuleDef::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), hir::ModuleDef::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), hir::ModuleDef::EnumVariant(it) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), + hir::ModuleDef::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), + hir::ModuleDef::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), hir::ModuleDef::Def(def_id) => match def_id.resolve(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)), - hir::Def::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), _ => return self, }, }; diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index fc76338d2..8406fee31 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -121,6 +121,20 @@ impl NavigationTarget { &*node, )); } + hir::ModuleDef::Const(s) => { + let (file_id, node) = s.source(db); + return Some(NavigationTarget::from_named( + file_id.original_file(db), + &*node, + )); + } + hir::ModuleDef::Static(s) => { + let (file_id, node) = s.source(db); + return Some(NavigationTarget::from_named( + file_id.original_file(db), + &*node, + )); + } hir::ModuleDef::Enum(e) => { let (file_id, node) = e.source(db); return Some(NavigationTarget::from_named( @@ -146,14 +160,6 @@ impl NavigationTarget { 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); - NavigationTarget::from_named(file_id.original_file(db), &*node) - } - Def::Const(f) => { - let (file_id, node) = f.source(db); - NavigationTarget::from_named(file_id.original_file(db), &*node) - } Def::Item => return None, }; Some(res) -- cgit v1.2.3 From 0f2f3a21e7e624f920d182869896347af309e909 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 01:31:32 +0300 Subject: Migrate trait & type to new ids --- crates/ra_ide_api/src/completion/complete_path.rs | 7 +-- .../ra_ide_api/src/completion/completion_item.rs | 8 ++- crates/ra_ide_api/src/navigation_target.rs | 59 ++++++++++------------ 3 files changed, 32 insertions(+), 42 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index bd5484516..e72586e2e 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -40,12 +40,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { .add_to(acc) }); } - hir::ModuleDef::Function(_) - | hir::ModuleDef::Struct(_) - | hir::ModuleDef::Def(_) - | hir::ModuleDef::Const(_) - | hir::ModuleDef::Static(_) - | hir::ModuleDef::EnumVariant(_) => return, + _ => return, }; } diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 2f8ec41d2..4e679281c 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -225,11 +225,9 @@ impl Builder { hir::ModuleDef::EnumVariant(it) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), hir::ModuleDef::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), hir::ModuleDef::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), - hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { - hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), - hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), - _ => return self, - }, + hir::ModuleDef::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), + hir::ModuleDef::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), + hir::ModuleDef::Def(_) => return self, }; self.kind = Some(kind); self.documentation = docs; diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 8406fee31..2e11d2de3 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -3,7 +3,7 @@ use ra_syntax::{ SyntaxNode, AstNode, SmolStr, TextRange, ast, SyntaxKind::{self, NAME}, }; -use hir::{Def, ModuleSource}; +use hir::{ModuleSource}; use crate::{FileSymbol, db::RootDatabase}; @@ -106,63 +106,60 @@ impl NavigationTarget { db: &RootDatabase, module_def: hir::ModuleDef, ) -> Option { - let def = match module_def { - hir::ModuleDef::Def(def_id) => def_id.resolve(db), - hir::ModuleDef::Module(module) => { - return Some(NavigationTarget::from_module(db, module)); - } - hir::ModuleDef::Function(func) => { - return Some(NavigationTarget::from_function(db, func)); - } + match module_def { + hir::ModuleDef::Def(_) => return None, + hir::ModuleDef::Module(module) => Some(NavigationTarget::from_module(db, module)), + hir::ModuleDef::Function(func) => Some(NavigationTarget::from_function(db, func)), hir::ModuleDef::Struct(s) => { let (file_id, node) = s.source(db); - return Some(NavigationTarget::from_named( + Some(NavigationTarget::from_named( file_id.original_file(db), &*node, - )); + )) } hir::ModuleDef::Const(s) => { let (file_id, node) = s.source(db); - return Some(NavigationTarget::from_named( + Some(NavigationTarget::from_named( file_id.original_file(db), &*node, - )); + )) } hir::ModuleDef::Static(s) => { let (file_id, node) = s.source(db); - return Some(NavigationTarget::from_named( + Some(NavigationTarget::from_named( file_id.original_file(db), &*node, - )); + )) } hir::ModuleDef::Enum(e) => { let (file_id, node) = e.source(db); - return Some(NavigationTarget::from_named( + Some(NavigationTarget::from_named( file_id.original_file(db), &*node, - )); + )) } hir::ModuleDef::EnumVariant(var) => { let (file_id, node) = var.source(db); - return Some(NavigationTarget::from_named( + Some(NavigationTarget::from_named( file_id.original_file(db), &*node, - )); + )) } - }; - - let res = match def { - Def::Trait(f) => { - let (file_id, node) = f.source(db); - NavigationTarget::from_named(file_id.original_file(db), &*node) + hir::ModuleDef::Trait(e) => { + let (file_id, node) = e.source(db); + Some(NavigationTarget::from_named( + file_id.original_file(db), + &*node, + )) } - Def::Type(f) => { - let (file_id, node) = f.source(db); - NavigationTarget::from_named(file_id.original_file(db), &*node) + hir::ModuleDef::Type(e) => { + let (file_id, node) = e.source(db); + Some(NavigationTarget::from_named( + file_id.original_file(db), + &*node, + )) } - Def::Item => return None, - }; - Some(res) + } } #[cfg(test)] -- cgit v1.2.3 From ff9c5bef7b198cde4358610c565cd0b6dc466de5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 01:32:47 +0300 Subject: ModuleDef is Def-free --- crates/ra_ide_api/src/completion/completion_item.rs | 1 - crates/ra_ide_api/src/navigation_target.rs | 1 - 2 files changed, 2 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 4e679281c..3ba6c33ee 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -227,7 +227,6 @@ impl Builder { hir::ModuleDef::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), hir::ModuleDef::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), hir::ModuleDef::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), - hir::ModuleDef::Def(_) => return self, }; self.kind = Some(kind); self.documentation = docs; diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 2e11d2de3..c5be8e01b 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -107,7 +107,6 @@ impl NavigationTarget { module_def: hir::ModuleDef, ) -> Option { match module_def { - hir::ModuleDef::Def(_) => return None, hir::ModuleDef::Module(module) => Some(NavigationTarget::from_module(db, module)), hir::ModuleDef::Function(func) => Some(NavigationTarget::from_function(db, func)), hir::ModuleDef::Struct(s) => { -- cgit v1.2.3