Properly reacto to keywords
This commit is contained in:
parent
cc43abcde8
commit
57a260f579
@ -13,6 +13,10 @@ use crate::completion::{
|
||||
};
|
||||
|
||||
pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||
if ctx.mod_is_prev {
|
||||
return None;
|
||||
}
|
||||
|
||||
let attribute = ctx.attribute_under_caret.as_ref()?;
|
||||
match (attribute.path(), attribute.token_tree()) {
|
||||
(Some(path), Some(token_tree)) if path.to_string() == "derive" => {
|
||||
|
@ -9,6 +9,12 @@ use super::{completion_context::CompletionContext, 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");
|
||||
|
||||
if !ctx.mod_is_prev {
|
||||
return None;
|
||||
}
|
||||
|
||||
let current_module = ctx.scope.module()?;
|
||||
|
||||
let module_definition_file =
|
||||
@ -63,7 +69,7 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
|
||||
.collect::<Vec<_>>();
|
||||
dbg!(mod_declaration_candidates);
|
||||
|
||||
// TODO kb exlude existing children from the candidates
|
||||
// TODO kb actually add the results
|
||||
|
||||
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() {
|
||||
if ctx.attribute_under_caret.is_some() || ctx.mod_is_prev {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -13,6 +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
|
||||
{
|
||||
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, unsafe_is_prev,
|
||||
is_in_loop_body, is_match_arm, mod_is_prev, unsafe_is_prev,
|
||||
},
|
||||
CompletionConfig,
|
||||
},
|
||||
@ -77,6 +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) unsafe_is_prev: bool,
|
||||
pub(super) if_is_prev: bool,
|
||||
pub(super) block_expr_parent: bool,
|
||||
@ -152,6 +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,
|
||||
unsafe_is_prev: false,
|
||||
in_loop_body: false,
|
||||
ref_pat_parent: false,
|
||||
@ -238,7 +240,8 @@ impl<'a> CompletionContext<'a> {
|
||||
self.trait_as_prev_sibling = has_trait_as_prev_sibling(syntax_element.clone());
|
||||
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);
|
||||
has_item_list_or_source_file_parent(syntax_element.clone());
|
||||
self.mod_is_prev = mod_is_prev(syntax_element);
|
||||
}
|
||||
|
||||
fn fill(
|
||||
|
@ -115,6 +115,16 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
|
||||
.filter(|it| it.kind() == IF_KW)
|
||||
.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