})
.filter_map(|file_name_and_extension| {
match file_name_and_extension {
- // TODO kb wrong resolution for nested non-file modules (mod tests {mod <|>)
+ // TODO kb wrong resolution for nested non-file modules (mod tests { mod <|> })
// TODO kb in src/bin when a module is included into another,
// the included file gets "moved" into a directory below and now cannot add any other modules
("mod", Some("rs")) | ("lib", Some("rs")) | ("main", Some("rs")) => None,
mod complete_postfix;
mod complete_macro_in_item_position;
mod complete_trait_impl;
+mod complete_mod;
use ide_db::RootDatabase;
complete_postfix::complete_postfix(&mut acc, &ctx);
complete_macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx);
complete_trait_impl::complete_trait_impl(&mut acc, &ctx);
+ complete_mod::complete_mod(&mut acc, &ctx);
Some(acc)
}
--- /dev/null
+//! Completes mod declarations.
+
+use base_db::FileLoader;
+use hir::ModuleSource;
+
+use super::{completion_context::CompletionContext, completion_item::Completions};
+
+/// Complete mod declaration, i.e. `mod <|> ;`
+pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) {
+ let module_names_for_import = ctx
+ .sema
+ // TODO kb this is wrong, since we need not the file module
+ .to_module_def(ctx.position.file_id)
+ .and_then(|current_module| {
+ dbg!(current_module.name(ctx.db));
+ dbg!(current_module.definition_source(ctx.db));
+ dbg!(current_module.declaration_source(ctx.db));
+ let mut zz = Vec::new();
+ let mut vv = Some(current_module);
+ while let Some(ModuleSource::Module(_)) =
+ vv.map(|vv| vv.definition_source(ctx.db).value)
+ {
+ zz.push(current_module.name(ctx.db));
+ vv = current_module.parent(ctx.db);
+ }
+ dbg!(zz);
+ let definition_source = current_module.definition_source(ctx.db);
+ // TODO kb filter out declarations in possible_sudmobule_names
+ // let declaration_source = current_module.declaration_source(ctx.db);
+ let module_definition_source_file = definition_source.file_id.original_file(ctx.db);
+ let mod_declaration_candidates =
+ ctx.db.possible_sudmobule_names(module_definition_source_file);
+ dbg!(mod_declaration_candidates);
+ // TODO kb exlude existing children from the candidates
+ let existing_children = current_module.children(ctx.db).collect::<Vec<_>>();
+ None::<Vec<String>>
+ })
+ .unwrap_or_default();
+}
//! FIXME: write short doc here
use base_db::{FileLoader, SourceDatabase};
-use hir::{Semantics, SemanticsScope, Type};
+use hir::{ModuleSource, Semantics, SemanticsScope, Type};
use ide_db::RootDatabase;
use syntax::{
algo::{find_covering_element, find_node_at_offset},
};
let fake_ident_token =
file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
- {
- let module_names_for_import = sema
- .to_module_def(position.file_id)
- .and_then(|current_module| {
- let definition_source = current_module.definition_source(db);
- let module_definition_source_file = definition_source.file_id.original_file(db);
- let mod_declaration_candidates =
- db.possible_sudmobule_names(module_definition_source_file);
- dbg!(mod_declaration_candidates);
- // TODO kb exlude existing children from the candidates
- let existing_children = current_module.children(db).collect::<Vec<_>>();
- None::<Vec<String>>
- })
- .unwrap_or_default();
- };
-
let krate = sema.to_module_def(position.file_id).map(|m| m.krate());
let original_token =
original_file.syntax().token_at_offset(position.offset).left_biased()?;