Skip to content

Commit 57a260f

Browse files
Properly reacto to keywords
1 parent cc43abc commit 57a260f

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

crates/ide/src/completion/complete_attribute.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ use crate::completion::{
1313
};
1414

1515
pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
16+
if ctx.mod_is_prev {
17+
return None;
18+
}
19+
1620
let attribute = ctx.attribute_under_caret.as_ref()?;
1721
match (attribute.path(), attribute.token_tree()) {
1822
(Some(path), Some(token_tree)) if path.to_string() == "derive" => {

crates/ide/src/completion/complete_mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ use super::{completion_context::CompletionContext, completion_item::Completions}
99

1010
/// Complete mod declaration, i.e. `mod <|> ;`
1111
pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
12+
let _p = profile::span("completion::complete_mod");
13+
14+
if !ctx.mod_is_prev {
15+
return None;
16+
}
17+
1218
let current_module = ctx.scope.module()?;
1319

1420
let module_definition_file =
@@ -63,7 +69,7 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
6369
.collect::<Vec<_>>();
6470
dbg!(mod_declaration_candidates);
6571

66-
// TODO kb exlude existing children from the candidates
72+
// TODO kb actually add the results
6773

6874
Some(())
6975
}

crates/ide/src/completion/complete_qualified_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
1313
None => return,
1414
};
1515

16-
if ctx.attribute_under_caret.is_some() {
16+
if ctx.attribute_under_caret.is_some() || ctx.mod_is_prev {
1717
return;
1818
}
1919

crates/ide/src/completion/complete_unqualified_path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
1313
if ctx.record_lit_syntax.is_some()
1414
|| ctx.record_pat_syntax.is_some()
1515
|| ctx.attribute_under_caret.is_some()
16+
|| ctx.mod_is_prev
1617
{
1718
return;
1819
}

crates/ide/src/completion/completion_context.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
has_bind_pat_parent, has_block_expr_parent, has_field_list_parent,
2020
has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent,
2121
has_ref_parent, has_trait_as_prev_sibling, has_trait_parent, if_is_prev,
22-
is_in_loop_body, is_match_arm, unsafe_is_prev,
22+
is_in_loop_body, is_match_arm, mod_is_prev, unsafe_is_prev,
2323
},
2424
CompletionConfig,
2525
},
@@ -77,6 +77,7 @@ pub(crate) struct CompletionContext<'a> {
7777
pub(super) is_path_type: bool,
7878
pub(super) has_type_args: bool,
7979
pub(super) attribute_under_caret: Option<ast::Attr>,
80+
pub(super) mod_is_prev: bool,
8081
pub(super) unsafe_is_prev: bool,
8182
pub(super) if_is_prev: bool,
8283
pub(super) block_expr_parent: bool,
@@ -152,6 +153,7 @@ impl<'a> CompletionContext<'a> {
152153
has_type_args: false,
153154
dot_receiver_is_ambiguous_float_literal: false,
154155
attribute_under_caret: None,
156+
mod_is_prev: false,
155157
unsafe_is_prev: false,
156158
in_loop_body: false,
157159
ref_pat_parent: false,
@@ -238,7 +240,8 @@ impl<'a> CompletionContext<'a> {
238240
self.trait_as_prev_sibling = has_trait_as_prev_sibling(syntax_element.clone());
239241
self.is_match_arm = is_match_arm(syntax_element.clone());
240242
self.has_item_list_or_source_file_parent =
241-
has_item_list_or_source_file_parent(syntax_element);
243+
has_item_list_or_source_file_parent(syntax_element.clone());
244+
self.mod_is_prev = mod_is_prev(syntax_element);
242245
}
243246

244247
fn fill(

crates/ide/src/completion/patterns.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
115115
.filter(|it| it.kind() == IF_KW)
116116
.is_some()
117117
}
118+
119+
// TODO kb generify?
120+
pub(crate) fn mod_is_prev(element: SyntaxElement) -> bool {
121+
element
122+
.into_token()
123+
.and_then(|it| previous_non_trivia_token(it))
124+
.filter(|it| it.kind() == MOD_KW)
125+
.is_some()
126+
}
127+
118128
#[test]
119129
fn test_if_is_prev() {
120130
check_pattern_is_applicable(r"if l<|>", if_is_prev);

0 commit comments

Comments
 (0)