aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-09-07 17:21:39 +0100
committerKirill Bulatov <[email protected]>2020-09-09 23:42:20 +0100
commit6ba479cd058aa54a9f161085c7ff9ac1f12d8df3 (patch)
tree1fc72b28fba9df437edb514ec6c7c31af1d7406a /crates
parent33179a0ae1ba9a908cc34a4cf87599ed779b9886 (diff)
Finally cretae the mod completion module
Diffstat (limited to 'crates')
-rw-r--r--crates/base_db/src/lib.rs2
-rw-r--r--crates/ide/src/completion.rs2
-rw-r--r--crates/ide/src/completion/complete_mod.rs39
-rw-r--r--crates/ide/src/completion/completion_context.rs18
4 files changed, 43 insertions, 18 deletions
diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs
index 9733e1fd3..321007d33 100644
--- a/crates/base_db/src/lib.rs
+++ b/crates/base_db/src/lib.rs
@@ -199,7 +199,7 @@ fn possible_sudmobule_names(module_files: &FileSet, module_file: FileId) -> Vec<
199 }) 199 })
200 .filter_map(|file_name_and_extension| { 200 .filter_map(|file_name_and_extension| {
201 match file_name_and_extension { 201 match file_name_and_extension {
202 // TODO kb wrong resolution for nested non-file modules (mod tests {mod <|>) 202 // TODO kb wrong resolution for nested non-file modules (mod tests { mod <|> })
203 // TODO kb in src/bin when a module is included into another, 203 // TODO kb in src/bin when a module is included into another,
204 // the included file gets "moved" into a directory below and now cannot add any other modules 204 // the included file gets "moved" into a directory below and now cannot add any other modules
205 ("mod", Some("rs")) | ("lib", Some("rs")) | ("main", Some("rs")) => None, 205 ("mod", Some("rs")) | ("lib", Some("rs")) | ("main", Some("rs")) => None,
diff --git a/crates/ide/src/completion.rs b/crates/ide/src/completion.rs
index 33bed6991..daea2aa95 100644
--- a/crates/ide/src/completion.rs
+++ b/crates/ide/src/completion.rs
@@ -19,6 +19,7 @@ mod complete_unqualified_path;
19mod complete_postfix; 19mod complete_postfix;
20mod complete_macro_in_item_position; 20mod complete_macro_in_item_position;
21mod complete_trait_impl; 21mod complete_trait_impl;
22mod complete_mod;
22 23
23use ide_db::RootDatabase; 24use ide_db::RootDatabase;
24 25
@@ -124,6 +125,7 @@ pub(crate) fn completions(
124 complete_postfix::complete_postfix(&mut acc, &ctx); 125 complete_postfix::complete_postfix(&mut acc, &ctx);
125 complete_macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx); 126 complete_macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx);
126 complete_trait_impl::complete_trait_impl(&mut acc, &ctx); 127 complete_trait_impl::complete_trait_impl(&mut acc, &ctx);
128 complete_mod::complete_mod(&mut acc, &ctx);
127 129
128 Some(acc) 130 Some(acc)
129} 131}
diff --git a/crates/ide/src/completion/complete_mod.rs b/crates/ide/src/completion/complete_mod.rs
new file mode 100644
index 000000000..4c1e79603
--- /dev/null
+++ b/crates/ide/src/completion/complete_mod.rs
@@ -0,0 +1,39 @@
1//! Completes mod declarations.
2
3use base_db::FileLoader;
4use hir::ModuleSource;
5
6use super::{completion_context::CompletionContext, completion_item::Completions};
7
8/// Complete mod declaration, i.e. `mod <|> ;`
9pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) {
10 let module_names_for_import = ctx
11 .sema
12 // TODO kb this is wrong, since we need not the file module
13 .to_module_def(ctx.position.file_id)
14 .and_then(|current_module| {
15 dbg!(current_module.name(ctx.db));
16 dbg!(current_module.definition_source(ctx.db));
17 dbg!(current_module.declaration_source(ctx.db));
18 let mut zz = Vec::new();
19 let mut vv = Some(current_module);
20 while let Some(ModuleSource::Module(_)) =
21 vv.map(|vv| vv.definition_source(ctx.db).value)
22 {
23 zz.push(current_module.name(ctx.db));
24 vv = current_module.parent(ctx.db);
25 }
26 dbg!(zz);
27 let definition_source = current_module.definition_source(ctx.db);
28 // TODO kb filter out declarations in possible_sudmobule_names
29 // let declaration_source = current_module.declaration_source(ctx.db);
30 let module_definition_source_file = definition_source.file_id.original_file(ctx.db);
31 let mod_declaration_candidates =
32 ctx.db.possible_sudmobule_names(module_definition_source_file);
33 dbg!(mod_declaration_candidates);
34 // TODO kb exlude existing children from the candidates
35 let existing_children = current_module.children(ctx.db).collect::<Vec<_>>();
36 None::<Vec<String>>
37 })
38 .unwrap_or_default();
39}
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs
index a8fe44083..31886942a 100644
--- a/crates/ide/src/completion/completion_context.rs
+++ b/crates/ide/src/completion/completion_context.rs
@@ -1,7 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use base_db::{FileLoader, SourceDatabase}; 3use base_db::{FileLoader, SourceDatabase};
4use hir::{Semantics, SemanticsScope, Type}; 4use hir::{ModuleSource, Semantics, SemanticsScope, Type};
5use ide_db::RootDatabase; 5use ide_db::RootDatabase;
6use syntax::{ 6use syntax::{
7 algo::{find_covering_element, find_node_at_offset}, 7 algo::{find_covering_element, find_node_at_offset},
@@ -112,22 +112,6 @@ impl<'a> CompletionContext<'a> {
112 }; 112 };
113 let fake_ident_token = 113 let fake_ident_token =
114 file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap(); 114 file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
115 {
116 let module_names_for_import = sema
117 .to_module_def(position.file_id)
118 .and_then(|current_module| {
119 let definition_source = current_module.definition_source(db);
120 let module_definition_source_file = definition_source.file_id.original_file(db);
121 let mod_declaration_candidates =
122 db.possible_sudmobule_names(module_definition_source_file);
123 dbg!(mod_declaration_candidates);
124 // TODO kb exlude existing children from the candidates
125 let existing_children = current_module.children(db).collect::<Vec<_>>();
126 None::<Vec<String>>
127 })
128 .unwrap_or_default();
129 };
130
131 let krate = sema.to_module_def(position.file_id).map(|m| m.krate()); 115 let krate = sema.to_module_def(position.file_id).map(|m| m.krate());
132 let original_token = 116 let original_token =
133 original_file.syntax().token_at_offset(position.offset).left_biased()?; 117 original_file.syntax().token_at_offset(position.offset).left_biased()?;