mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +00:00
Finally cretae the mod completion module
This commit is contained in:
parent
33179a0ae1
commit
6ba479cd05
4 changed files with 43 additions and 18 deletions
|
@ -199,7 +199,7 @@ fn possible_sudmobule_names(module_files: &FileSet, module_file: FileId) -> Vec<
|
||||||
})
|
})
|
||||||
.filter_map(|file_name_and_extension| {
|
.filter_map(|file_name_and_extension| {
|
||||||
match 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,
|
// 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
|
// 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", Some("rs")) | ("lib", Some("rs")) | ("main", Some("rs")) => None,
|
||||||
|
|
|
@ -19,6 +19,7 @@ mod complete_unqualified_path;
|
||||||
mod complete_postfix;
|
mod complete_postfix;
|
||||||
mod complete_macro_in_item_position;
|
mod complete_macro_in_item_position;
|
||||||
mod complete_trait_impl;
|
mod complete_trait_impl;
|
||||||
|
mod complete_mod;
|
||||||
|
|
||||||
use ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
|
|
||||||
|
@ -124,6 +125,7 @@ pub(crate) fn completions(
|
||||||
complete_postfix::complete_postfix(&mut acc, &ctx);
|
complete_postfix::complete_postfix(&mut acc, &ctx);
|
||||||
complete_macro_in_item_position::complete_macro_in_item_position(&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_trait_impl::complete_trait_impl(&mut acc, &ctx);
|
||||||
|
complete_mod::complete_mod(&mut acc, &ctx);
|
||||||
|
|
||||||
Some(acc)
|
Some(acc)
|
||||||
}
|
}
|
||||||
|
|
39
crates/ide/src/completion/complete_mod.rs
Normal file
39
crates/ide/src/completion/complete_mod.rs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
//! 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();
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use base_db::{FileLoader, SourceDatabase};
|
use base_db::{FileLoader, SourceDatabase};
|
||||||
use hir::{Semantics, SemanticsScope, Type};
|
use hir::{ModuleSource, Semantics, SemanticsScope, Type};
|
||||||
use ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
algo::{find_covering_element, find_node_at_offset},
|
algo::{find_covering_element, find_node_at_offset},
|
||||||
|
@ -112,22 +112,6 @@ impl<'a> CompletionContext<'a> {
|
||||||
};
|
};
|
||||||
let fake_ident_token =
|
let fake_ident_token =
|
||||||
file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
|
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 krate = sema.to_module_def(position.file_id).map(|m| m.krate());
|
||||||
let original_token =
|
let original_token =
|
||||||
original_file.syntax().token_at_offset(position.offset).left_biased()?;
|
original_file.syntax().token_at_offset(position.offset).left_biased()?;
|
||||||
|
|
Loading…
Reference in a new issue