diff options
author | Kirill Bulatov <[email protected]> | 2020-09-07 17:21:39 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-09-09 23:42:20 +0100 |
commit | 6ba479cd058aa54a9f161085c7ff9ac1f12d8df3 (patch) | |
tree | 1fc72b28fba9df437edb514ec6c7c31af1d7406a /crates/ide | |
parent | 33179a0ae1ba9a908cc34a4cf87599ed779b9886 (diff) |
Finally cretae the mod completion module
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/completion.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/completion/complete_mod.rs | 39 | ||||
-rw-r--r-- | crates/ide/src/completion/completion_context.rs | 18 |
3 files changed, 42 insertions, 17 deletions
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; | |||
19 | mod complete_postfix; | 19 | mod complete_postfix; |
20 | mod complete_macro_in_item_position; | 20 | mod complete_macro_in_item_position; |
21 | mod complete_trait_impl; | 21 | mod complete_trait_impl; |
22 | mod complete_mod; | ||
22 | 23 | ||
23 | use ide_db::RootDatabase; | 24 | use 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 | |||
3 | use base_db::FileLoader; | ||
4 | use hir::ModuleSource; | ||
5 | |||
6 | use super::{completion_context::CompletionContext, completion_item::Completions}; | ||
7 | |||
8 | /// Complete mod declaration, i.e. `mod <|> ;` | ||
9 | pub(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 | ||
3 | use base_db::{FileLoader, SourceDatabase}; | 3 | use base_db::{FileLoader, SourceDatabase}; |
4 | use hir::{Semantics, SemanticsScope, Type}; | 4 | use hir::{ModuleSource, Semantics, SemanticsScope, Type}; |
5 | use ide_db::RootDatabase; | 5 | use ide_db::RootDatabase; |
6 | use syntax::{ | 6 | use 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()?; |