Complete semicolon when needed
This commit is contained in:
parent
57a260f579
commit
9fb83211f9
@ -13,7 +13,7 @@ use crate::completion::{
|
||||
};
|
||||
|
||||
pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||
if ctx.mod_is_prev {
|
||||
if ctx.mod_under_caret.is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,22 @@ use hir::{Module, ModuleSource};
|
||||
use ide_db::RootDatabase;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use super::{completion_context::CompletionContext, completion_item::Completions};
|
||||
use crate::{CompletionItem, CompletionItemKind};
|
||||
|
||||
use super::{
|
||||
completion_context::CompletionContext, completion_item::CompletionKind,
|
||||
completion_item::Completions,
|
||||
};
|
||||
|
||||
/// Complete mod declaration, i.e. `mod <|> ;`
|
||||
pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||
let _p = profile::span("completion::complete_mod");
|
||||
let mod_under_caret = match &ctx.mod_under_caret {
|
||||
Some(mod_under_caret) if mod_under_caret.item_list().is_some() => return None,
|
||||
Some(mod_under_caret) => mod_under_caret,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
if !ctx.mod_is_prev {
|
||||
return None;
|
||||
}
|
||||
let _p = profile::span("completion::complete_mod");
|
||||
|
||||
let current_module = ctx.scope.module()?;
|
||||
|
||||
@ -36,7 +43,7 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
|
||||
module_declaration_source_file.file_id.original_file(ctx.db)
|
||||
});
|
||||
|
||||
let mod_declaration_candidates = source_root
|
||||
source_root
|
||||
.iter()
|
||||
.filter(|submodule_candidate_file| submodule_candidate_file != &module_definition_file)
|
||||
.filter(|submodule_candidate_file| {
|
||||
@ -66,10 +73,16 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
|
||||
_ => None,
|
||||
})
|
||||
.filter(|name| !existing_mod_declarations.contains(name))
|
||||
.collect::<Vec<_>>();
|
||||
dbg!(mod_declaration_candidates);
|
||||
|
||||
// TODO kb actually add the results
|
||||
.for_each(|submodule_name| {
|
||||
let mut label = submodule_name;
|
||||
if mod_under_caret.semicolon_token().is_none() {
|
||||
label.push(';')
|
||||
}
|
||||
acc.add(
|
||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label)
|
||||
.kind(CompletionItemKind::Module),
|
||||
)
|
||||
});
|
||||
|
||||
Some(())
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||
None => return,
|
||||
};
|
||||
|
||||
if ctx.attribute_under_caret.is_some() || ctx.mod_is_prev {
|
||||
if ctx.attribute_under_caret.is_some() || ctx.mod_under_caret.is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
|
||||
if ctx.record_lit_syntax.is_some()
|
||||
|| ctx.record_pat_syntax.is_some()
|
||||
|| ctx.attribute_under_caret.is_some()
|
||||
|| ctx.mod_is_prev
|
||||
|| ctx.mod_under_caret.is_some()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ use crate::{
|
||||
has_bind_pat_parent, has_block_expr_parent, has_field_list_parent,
|
||||
has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent,
|
||||
has_ref_parent, has_trait_as_prev_sibling, has_trait_parent, if_is_prev,
|
||||
is_in_loop_body, is_match_arm, mod_is_prev, unsafe_is_prev,
|
||||
is_in_loop_body, is_match_arm, unsafe_is_prev,
|
||||
},
|
||||
CompletionConfig,
|
||||
},
|
||||
@ -77,7 +77,7 @@ pub(crate) struct CompletionContext<'a> {
|
||||
pub(super) is_path_type: bool,
|
||||
pub(super) has_type_args: bool,
|
||||
pub(super) attribute_under_caret: Option<ast::Attr>,
|
||||
pub(super) mod_is_prev: bool,
|
||||
pub(super) mod_under_caret: Option<ast::Module>,
|
||||
pub(super) unsafe_is_prev: bool,
|
||||
pub(super) if_is_prev: bool,
|
||||
pub(super) block_expr_parent: bool,
|
||||
@ -153,7 +153,7 @@ impl<'a> CompletionContext<'a> {
|
||||
has_type_args: false,
|
||||
dot_receiver_is_ambiguous_float_literal: false,
|
||||
attribute_under_caret: None,
|
||||
mod_is_prev: false,
|
||||
mod_under_caret: None,
|
||||
unsafe_is_prev: false,
|
||||
in_loop_body: false,
|
||||
ref_pat_parent: false,
|
||||
@ -241,7 +241,7 @@ impl<'a> CompletionContext<'a> {
|
||||
self.is_match_arm = is_match_arm(syntax_element.clone());
|
||||
self.has_item_list_or_source_file_parent =
|
||||
has_item_list_or_source_file_parent(syntax_element.clone());
|
||||
self.mod_is_prev = mod_is_prev(syntax_element);
|
||||
self.mod_under_caret = find_node_at_offset(&file_with_fake_ident, offset);
|
||||
}
|
||||
|
||||
fn fill(
|
||||
|
@ -116,15 +116,6 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
|
||||
.is_some()
|
||||
}
|
||||
|
||||
// TODO kb generify?
|
||||
pub(crate) fn mod_is_prev(element: SyntaxElement) -> bool {
|
||||
element
|
||||
.into_token()
|
||||
.and_then(|it| previous_non_trivia_token(it))
|
||||
.filter(|it| it.kind() == MOD_KW)
|
||||
.is_some()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_is_prev() {
|
||||
check_pattern_is_applicable(r"if l<|>", if_is_prev);
|
||||
|
Loading…
x
Reference in New Issue
Block a user