diff options
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 37 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 61 | ||||
-rw-r--r-- | crates/ra_ide_api/src/db.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/navigation_target.rs | 13 | ||||
-rw-r--r-- | crates/ra_ide_api/src/rename.rs | 25 | ||||
-rw-r--r-- | crates/ra_ide_api/src/snapshots/tests__rename_mod.snap | 10 |
7 files changed, 76 insertions, 75 deletions
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) { | |||
13 | Some(it) => it, | 13 | Some(it) => it, |
14 | None => return, | 14 | None => return, |
15 | }; | 15 | }; |
16 | match def_id.resolve(ctx.db) { | 16 | match def_id { |
17 | hir::Def::Module(module) => { | 17 | hir::ModuleDef::Module(module) => { |
18 | let module_scope = module.scope(ctx.db); | 18 | let module_scope = module.scope(ctx.db); |
19 | for (name, res) in module_scope.entries() { | 19 | for (name, res) in module_scope.entries() { |
20 | CompletionItem::new( | 20 | CompletionItem::new( |
@@ -26,21 +26,24 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
26 | .add_to(acc); | 26 | .add_to(acc); |
27 | } | 27 | } |
28 | } | 28 | } |
29 | hir::Def::Enum(e) => { | 29 | |
30 | e.variants(ctx.db) | 30 | hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { |
31 | .into_iter() | 31 | hir::Def::Enum(e) => { |
32 | .for_each(|(variant_name, variant)| { | 32 | e.variants(ctx.db) |
33 | CompletionItem::new( | 33 | .into_iter() |
34 | CompletionKind::Reference, | 34 | .for_each(|(variant_name, variant)| { |
35 | ctx.source_range(), | 35 | CompletionItem::new( |
36 | variant_name.to_string(), | 36 | CompletionKind::Reference, |
37 | ) | 37 | ctx.source_range(), |
38 | .kind(CompletionItemKind::EnumVariant) | 38 | variant_name.to_string(), |
39 | .set_documentation(variant.docs(ctx.db)) | 39 | ) |
40 | .add_to(acc) | 40 | .kind(CompletionItemKind::EnumVariant) |
41 | }); | 41 | .set_documentation(variant.docs(ctx.db)) |
42 | } | 42 | .add_to(acc) |
43 | _ => return, | 43 | }); |
44 | } | ||
45 | _ => return, | ||
46 | }, | ||
44 | }; | 47 | }; |
45 | } | 48 | } |
46 | 49 | ||
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 @@ | |||
1 | use hir::{Docs, Documentation, PerNs}; | 1 | use hir::{Docs, Documentation}; |
2 | |||
3 | use crate::completion::completion_context::CompletionContext; | ||
4 | use ra_syntax::{ | 2 | use ra_syntax::{ |
5 | ast::{self, AstNode}, | 3 | ast::{self, AstNode}, |
6 | TextRange, | 4 | TextRange, |
@@ -8,6 +6,8 @@ use ra_syntax::{ | |||
8 | use ra_text_edit::TextEdit; | 6 | use ra_text_edit::TextEdit; |
9 | use test_utils::tested_by; | 7 | use test_utils::tested_by; |
10 | 8 | ||
9 | use crate::completion::completion_context::CompletionContext; | ||
10 | |||
11 | /// `CompletionItem` describes a single completion variant in the editor pop-up. | 11 | /// `CompletionItem` describes a single completion variant in the editor pop-up. |
12 | /// It is basically a POD with various properties. To construct a | 12 | /// It is basically a POD with various properties. To construct a |
13 | /// `CompletionItem`, use `new` method and the `Builder` struct. | 13 | /// `CompletionItem`, use `new` method and the `Builder` struct. |
@@ -209,41 +209,26 @@ impl Builder { | |||
209 | ctx: &CompletionContext, | 209 | ctx: &CompletionContext, |
210 | resolution: &hir::Resolution, | 210 | resolution: &hir::Resolution, |
211 | ) -> Builder { | 211 | ) -> Builder { |
212 | let resolved = resolution.def_id.map(|d| d.resolve(ctx.db)); | 212 | let def = resolution |
213 | let (kind, docs) = match resolved { | 213 | .def_id |
214 | PerNs { | 214 | .take_types() |
215 | types: Some(hir::Def::Module(..)), | 215 | .or(resolution.def_id.take_values()); |
216 | .. | 216 | let def = match def { |
217 | } => (CompletionItemKind::Module, None), | 217 | None => return self, |
218 | PerNs { | 218 | Some(it) => it, |
219 | types: Some(hir::Def::Struct(s)), | 219 | }; |
220 | .. | 220 | let (kind, docs) = match def { |
221 | } => (CompletionItemKind::Struct, s.docs(ctx.db)), | 221 | hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None), |
222 | PerNs { | 222 | hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { |
223 | types: Some(hir::Def::Enum(e)), | 223 | hir::Def::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), |
224 | .. | 224 | hir::Def::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), |
225 | } => (CompletionItemKind::Enum, e.docs(ctx.db)), | 225 | hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), |
226 | PerNs { | 226 | hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), |
227 | types: Some(hir::Def::Trait(t)), | 227 | hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), |
228 | .. | 228 | hir::Def::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), |
229 | } => (CompletionItemKind::Trait, t.docs(ctx.db)), | 229 | hir::Def::Function(function) => return self.from_function(ctx, function), |
230 | PerNs { | 230 | _ => return self, |
231 | types: Some(hir::Def::Type(t)), | 231 | }, |
232 | .. | ||
233 | } => (CompletionItemKind::TypeAlias, t.docs(ctx.db)), | ||
234 | PerNs { | ||
235 | values: Some(hir::Def::Const(c)), | ||
236 | .. | ||
237 | } => (CompletionItemKind::Const, c.docs(ctx.db)), | ||
238 | PerNs { | ||
239 | values: Some(hir::Def::Static(s)), | ||
240 | .. | ||
241 | } => (CompletionItemKind::Static, s.docs(ctx.db)), | ||
242 | PerNs { | ||
243 | values: Some(hir::Def::Function(function)), | ||
244 | .. | ||
245 | } => return self.from_function(ctx, function), | ||
246 | _ => return self, | ||
247 | }; | 232 | }; |
248 | self.kind = Some(kind); | 233 | self.kind = Some(kind); |
249 | self.documentation = docs; | 234 | 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! { | |||
72 | fn file_relative_path() for ra_db::FileRelativePathQuery; | 72 | fn file_relative_path() for ra_db::FileRelativePathQuery; |
73 | fn file_source_root() for ra_db::FileSourceRootQuery; | 73 | fn file_source_root() for ra_db::FileSourceRootQuery; |
74 | fn source_root() for ra_db::SourceRootQuery; | 74 | fn source_root() for ra_db::SourceRootQuery; |
75 | fn source_root_crates() for ra_db::SourceRootCratesQuery; | ||
75 | fn local_roots() for ra_db::LocalRootsQuery; | 76 | fn local_roots() for ra_db::LocalRootsQuery; |
76 | fn library_roots() for ra_db::LibraryRootsQuery; | 77 | fn library_roots() for ra_db::LibraryRootsQuery; |
77 | fn crate_graph() for ra_db::CrateGraphQuery; | 78 | 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( | |||
67 | .node_expr(expr) | 67 | .node_expr(expr) |
68 | .and_then(|it| infer_result.method_resolution(it)) | 68 | .and_then(|it| infer_result.method_resolution(it)) |
69 | { | 69 | { |
70 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { | 70 | if let Some(target) = NavigationTarget::from_def(db, hir::ModuleDef::Def(def_id)) { |
71 | return Exact(target); | 71 | return Exact(target); |
72 | } | 72 | } |
73 | }; | 73 | }; |
@@ -84,7 +84,7 @@ pub(crate) fn reference_definition( | |||
84 | { | 84 | { |
85 | let resolved = module.resolve_path(db, &path); | 85 | let resolved = module.resolve_path(db, &path); |
86 | if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { | 86 | if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { |
87 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { | 87 | if let Some(target) = NavigationTarget::from_def(db, def_id) { |
88 | return Exact(target); | 88 | return Exact(target); |
89 | } | 89 | } |
90 | } | 90 | } |
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 { | |||
97 | } | 97 | } |
98 | 98 | ||
99 | // TODO once Def::Item is gone, this should be able to always return a NavigationTarget | 99 | // TODO once Def::Item is gone, this should be able to always return a NavigationTarget |
100 | pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Option<NavigationTarget> { | 100 | pub(crate) fn from_def( |
101 | db: &RootDatabase, | ||
102 | module_def: hir::ModuleDef, | ||
103 | ) -> Option<NavigationTarget> { | ||
104 | let def = match module_def { | ||
105 | hir::ModuleDef::Def(def_id) => def_id.resolve(db), | ||
106 | hir::ModuleDef::Module(module) => { | ||
107 | return Some(NavigationTarget::from_module(db, module)); | ||
108 | } | ||
109 | }; | ||
110 | |||
101 | let res = match def { | 111 | let res = match def { |
102 | Def::Struct(s) => { | 112 | Def::Struct(s) => { |
103 | let (file_id, node) = s.source(db); | 113 | let (file_id, node) = s.source(db); |
@@ -131,7 +141,6 @@ impl NavigationTarget { | |||
131 | let (file_id, node) = f.source(db); | 141 | let (file_id, node) = f.source(db); |
132 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 142 | NavigationTarget::from_named(file_id.original_file(db), &*node) |
133 | } | 143 | } |
134 | Def::Module(m) => NavigationTarget::from_module(db, m), | ||
135 | Def::Item => return None, | 144 | Def::Item => return None, |
136 | }; | 145 | }; |
137 | Some(res) | 146 | 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( | |||
57 | ) -> Option<SourceChange> { | 57 | ) -> Option<SourceChange> { |
58 | let mut source_file_edits = Vec::new(); | 58 | let mut source_file_edits = Vec::new(); |
59 | let mut file_system_edits = Vec::new(); | 59 | let mut file_system_edits = Vec::new(); |
60 | |||
61 | if let Some(module) = module_from_declaration(db, position.file_id, &ast_module) { | 60 | if let Some(module) = module_from_declaration(db, position.file_id, &ast_module) { |
62 | let (file_id, module_source) = module.definition_source(db); | 61 | let (file_id, module_source) = module.definition_source(db); |
63 | match module_source { | 62 | match module_source { |
@@ -223,11 +222,15 @@ mod tests { | |||
223 | fn test_rename_mod() { | 222 | fn test_rename_mod() { |
224 | let (analysis, position) = analysis_and_position( | 223 | let (analysis, position) = analysis_and_position( |
225 | " | 224 | " |
226 | //- /bar.rs | 225 | //- /lib.rs |
227 | mod fo<|>o; | 226 | mod bar; |
228 | //- /bar/foo.rs | 227 | |
229 | // emtpy | 228 | //- /bar.rs |
230 | ", | 229 | mod foo<|>; |
230 | |||
231 | //- /bar/foo.rs | ||
232 | // emtpy | ||
233 | ", | ||
231 | ); | 234 | ); |
232 | let new_name = "foo2"; | 235 | let new_name = "foo2"; |
233 | let source_change = analysis.rename(position, new_name).unwrap(); | 236 | let source_change = analysis.rename(position, new_name).unwrap(); |
@@ -238,11 +241,11 @@ mod tests { | |||
238 | fn test_rename_mod_in_dir() { | 241 | fn test_rename_mod_in_dir() { |
239 | let (analysis, position) = analysis_and_position( | 242 | let (analysis, position) = analysis_and_position( |
240 | " | 243 | " |
241 | //- /lib.rs | 244 | //- /lib.rs |
242 | mod fo<|>o; | 245 | mod fo<|>o; |
243 | //- /foo/mod.rs | 246 | //- /foo/mod.rs |
244 | // emtpy | 247 | // emtpy |
245 | ", | 248 | ", |
246 | ); | 249 | ); |
247 | let new_name = "foo2"; | 250 | let new_name = "foo2"; |
248 | let source_change = analysis.rename(position, new_name).unwrap(); | 251 | 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 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-22T14:45:00.975229300+00:00" | 2 | created: "2019-01-24T08:39:53.759318522+00:00" |
3 | creator: insta@0.4.0 | 3 | creator: insta@0.5.2 |
4 | expression: "&source_change" | 4 | expression: "&source_change" |
5 | source: "crates\\ra_ide_api\\src\\rename.rs" | 5 | source: crates/ra_ide_api/src/rename.rs |
6 | --- | 6 | --- |
7 | Some( | 7 | Some( |
8 | SourceChange { | 8 | SourceChange { |
@@ -10,7 +10,7 @@ Some( | |||
10 | source_file_edits: [ | 10 | source_file_edits: [ |
11 | SourceFileEdit { | 11 | SourceFileEdit { |
12 | file_id: FileId( | 12 | file_id: FileId( |
13 | 1 | 13 | 2 |
14 | ), | 14 | ), |
15 | edit: TextEdit { | 15 | edit: TextEdit { |
16 | atoms: [ | 16 | atoms: [ |
@@ -25,7 +25,7 @@ Some( | |||
25 | file_system_edits: [ | 25 | file_system_edits: [ |
26 | MoveFile { | 26 | MoveFile { |
27 | src: FileId( | 27 | src: FileId( |
28 | 2 | 28 | 3 |
29 | ), | 29 | ), |
30 | dst_source_root: SourceRootId( | 30 | dst_source_root: SourceRootId( |
31 | 0 | 31 | 0 |