return;
}
- let has_trait_or_impl_parent = ctx.has_impl_or_trait_parent();
+ let expects_assoc_item = ctx.expects_assoc_item();
let has_block_expr_parent = ctx.has_block_expr_parent();
- let has_item_list_parent = ctx.has_item_list_parent();
+ let expects_item = ctx.expects_item();
if ctx.has_impl_or_trait_prev_sibling() {
add_keyword(ctx, acc, "where", "where ");
return;
}
if ctx.previous_token_is(T![unsafe]) {
- if has_item_list_parent || has_block_expr_parent {
+ if expects_item || has_block_expr_parent {
add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}")
}
- if has_item_list_parent || has_block_expr_parent {
+ if expects_item || has_block_expr_parent {
add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
}
return;
}
- if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent {
+ if expects_item || expects_assoc_item || has_block_expr_parent {
add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}");
}
- if has_item_list_parent || has_block_expr_parent {
+ if expects_item || has_block_expr_parent {
add_keyword(ctx, acc, "use", "use ");
add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
}
- if has_item_list_parent {
+ if expects_item {
add_keyword(ctx, acc, "enum", "enum $1 {\n $0\n}");
add_keyword(ctx, acc, "struct", "struct $0");
add_keyword(ctx, acc, "union", "union $1 {\n $0\n}");
add_keyword(ctx, acc, "else", "else {\n $0\n}");
add_keyword(ctx, acc, "else if", "else if $1 {\n $0\n}");
}
- if has_item_list_parent || has_block_expr_parent {
+ if expects_item || has_block_expr_parent {
add_keyword(ctx, acc, "mod", "mod $0");
}
if ctx.has_ident_or_ref_pat_parent() {
add_keyword(ctx, acc, "mut", "mut ");
}
- if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent {
+ if expects_item || expects_assoc_item || has_block_expr_parent {
add_keyword(ctx, acc, "const", "const ");
add_keyword(ctx, acc, "type", "type ");
}
- if has_item_list_parent || has_block_expr_parent {
+ if expects_item || has_block_expr_parent {
add_keyword(ctx, acc, "static", "static ");
};
- if has_item_list_parent || has_block_expr_parent {
+ if expects_item || has_block_expr_parent {
add_keyword(ctx, acc, "extern", "extern ");
}
- if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent || ctx.is_match_arm
- {
+ if expects_item || expects_assoc_item || has_block_expr_parent || ctx.is_match_arm {
add_keyword(ctx, acc, "unsafe", "unsafe ");
}
if ctx.in_loop_body {
add_keyword(ctx, acc, "break", "break");
}
}
- if has_item_list_parent || ctx.has_impl_parent() || ctx.has_field_list_parent() {
+ if expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_record_field() {
add_keyword(ctx, acc, "pub(crate)", "pub(crate) ");
add_keyword(ctx, acc, "pub", "pub ");
}
no_completion_required: bool,
}
+
impl<'a> CompletionContext<'a> {
pub(super) fn new(
db: &'a RootDatabase,
self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind)
}
- pub(crate) fn has_impl_or_trait_parent(&self) -> bool {
+ pub(crate) fn expects_assoc_item(&self) -> bool {
matches!(
self.completion_location,
Some(ImmediateLocation::Trait) | Some(ImmediateLocation::Impl)
)
}
- pub(crate) fn has_block_expr_parent(&self) -> bool {
- matches!(self.completion_location, Some(ImmediateLocation::BlockExpr))
+ pub(crate) fn expects_non_trait_assoc_item(&self) -> bool {
+ matches!(self.completion_location, Some(ImmediateLocation::Impl))
}
- pub(crate) fn has_item_list_parent(&self) -> bool {
+ pub(crate) fn expects_item(&self) -> bool {
matches!(self.completion_location, Some(ImmediateLocation::ItemList))
}
+ pub(crate) fn has_block_expr_parent(&self) -> bool {
+ matches!(self.completion_location, Some(ImmediateLocation::BlockExpr))
+ }
+
pub(crate) fn has_ident_or_ref_pat_parent(&self) -> bool {
matches!(
self.completion_location,
)
}
- pub(crate) fn has_impl_parent(&self) -> bool {
- matches!(self.completion_location, Some(ImmediateLocation::Impl))
- }
-
- pub(crate) fn has_field_list_parent(&self) -> bool {
+ pub(crate) fn expect_record_field(&self) -> bool {
matches!(self.completion_location, Some(ImmediateLocation::RecordFieldList))
}
|| self.record_pat_syntax.is_some()
|| self.attribute_under_caret.is_some()
|| self.mod_declaration_under_caret.is_some()
- || self.has_impl_or_trait_parent()
}
fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: TextSize) {
+ dbg!(file_with_fake_ident);
let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap();
let syntax_element = NodeOrToken::Token(fake_ident_token);
self.previous_token = previous_token(syntax_element.clone());