aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/completion/complete_attribute.rs4
-rw-r--r--crates/ide/src/completion/complete_mod.rs8
-rw-r--r--crates/ide/src/completion/complete_qualified_path.rs2
-rw-r--r--crates/ide/src/completion/complete_unqualified_path.rs1
-rw-r--r--crates/ide/src/completion/completion_context.rs7
-rw-r--r--crates/ide/src/completion/patterns.rs10
6 files changed, 28 insertions, 4 deletions
diff --git a/crates/ide/src/completion/complete_attribute.rs b/crates/ide/src/completion/complete_attribute.rs
index 0abfaebcb..6394189f0 100644
--- a/crates/ide/src/completion/complete_attribute.rs
+++ b/crates/ide/src/completion/complete_attribute.rs
@@ -13,6 +13,10 @@ use crate::completion::{
13}; 13};
14 14
15pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { 15pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
16 if ctx.mod_is_prev {
17 return None;
18 }
19
16 let attribute = ctx.attribute_under_caret.as_ref()?; 20 let attribute = ctx.attribute_under_caret.as_ref()?;
17 match (attribute.path(), attribute.token_tree()) { 21 match (attribute.path(), attribute.token_tree()) {
18 (Some(path), Some(token_tree)) if path.to_string() == "derive" => { 22 (Some(path), Some(token_tree)) if path.to_string() == "derive" => {
diff --git a/crates/ide/src/completion/complete_mod.rs b/crates/ide/src/completion/complete_mod.rs
index c5757a310..5d41d0f69 100644
--- a/crates/ide/src/completion/complete_mod.rs
+++ b/crates/ide/src/completion/complete_mod.rs
@@ -9,6 +9,12 @@ use super::{completion_context::CompletionContext, completion_item::Completions}
9 9
10/// Complete mod declaration, i.e. `mod <|> ;` 10/// Complete mod declaration, i.e. `mod <|> ;`
11pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { 11pub(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
12 let current_module = ctx.scope.module()?; 18 let current_module = ctx.scope.module()?;
13 19
14 let module_definition_file = 20 let module_definition_file =
@@ -63,7 +69,7 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
63 .collect::<Vec<_>>(); 69 .collect::<Vec<_>>();
64 dbg!(mod_declaration_candidates); 70 dbg!(mod_declaration_candidates);
65 71
66 // TODO kb exlude existing children from the candidates 72 // TODO kb actually add the results
67 73
68 Some(()) 74 Some(())
69} 75}
diff --git a/crates/ide/src/completion/complete_qualified_path.rs b/crates/ide/src/completion/complete_qualified_path.rs
index accb09f7e..351461351 100644
--- a/crates/ide/src/completion/complete_qualified_path.rs
+++ b/crates/ide/src/completion/complete_qualified_path.rs
@@ -13,7 +13,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
13 None => return, 13 None => return,
14 }; 14 };
15 15
16 if ctx.attribute_under_caret.is_some() { 16 if ctx.attribute_under_caret.is_some() || ctx.mod_is_prev {
17 return; 17 return;
18 } 18 }
19 19
diff --git a/crates/ide/src/completion/complete_unqualified_path.rs b/crates/ide/src/completion/complete_unqualified_path.rs
index 1f1b682a7..9f2dc16ab 100644
--- a/crates/ide/src/completion/complete_unqualified_path.rs
+++ b/crates/ide/src/completion/complete_unqualified_path.rs
@@ -13,6 +13,7 @@ pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
13 if ctx.record_lit_syntax.is_some() 13 if ctx.record_lit_syntax.is_some()
14 || ctx.record_pat_syntax.is_some() 14 || ctx.record_pat_syntax.is_some()
15 || ctx.attribute_under_caret.is_some() 15 || ctx.attribute_under_caret.is_some()
16 || ctx.mod_is_prev
16 { 17 {
17 return; 18 return;
18 } 19 }
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs
index 47355d5dc..d289aac27 100644
--- a/crates/ide/src/completion/completion_context.rs
+++ b/crates/ide/src/completion/completion_context.rs
@@ -19,7 +19,7 @@ use crate::{
19 has_bind_pat_parent, has_block_expr_parent, has_field_list_parent, 19 has_bind_pat_parent, has_block_expr_parent, has_field_list_parent,
20 has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent, 20 has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent,
21 has_ref_parent, has_trait_as_prev_sibling, has_trait_parent, if_is_prev, 21 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,
23 }, 23 },
24 CompletionConfig, 24 CompletionConfig,
25 }, 25 },
@@ -77,6 +77,7 @@ pub(crate) struct CompletionContext<'a> {
77 pub(super) is_path_type: bool, 77 pub(super) is_path_type: bool,
78 pub(super) has_type_args: bool, 78 pub(super) has_type_args: bool,
79 pub(super) attribute_under_caret: Option<ast::Attr>, 79 pub(super) attribute_under_caret: Option<ast::Attr>,
80 pub(super) mod_is_prev: bool,
80 pub(super) unsafe_is_prev: bool, 81 pub(super) unsafe_is_prev: bool,
81 pub(super) if_is_prev: bool, 82 pub(super) if_is_prev: bool,
82 pub(super) block_expr_parent: bool, 83 pub(super) block_expr_parent: bool,
@@ -152,6 +153,7 @@ impl<'a> CompletionContext<'a> {
152 has_type_args: false, 153 has_type_args: false,
153 dot_receiver_is_ambiguous_float_literal: false, 154 dot_receiver_is_ambiguous_float_literal: false,
154 attribute_under_caret: None, 155 attribute_under_caret: None,
156 mod_is_prev: false,
155 unsafe_is_prev: false, 157 unsafe_is_prev: false,
156 in_loop_body: false, 158 in_loop_body: false,
157 ref_pat_parent: false, 159 ref_pat_parent: false,
@@ -238,7 +240,8 @@ impl<'a> CompletionContext<'a> {
238 self.trait_as_prev_sibling = has_trait_as_prev_sibling(syntax_element.clone()); 240 self.trait_as_prev_sibling = has_trait_as_prev_sibling(syntax_element.clone());
239 self.is_match_arm = is_match_arm(syntax_element.clone()); 241 self.is_match_arm = is_match_arm(syntax_element.clone());
240 self.has_item_list_or_source_file_parent = 242 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);
242 } 245 }
243 246
244 fn fill( 247 fn fill(
diff --git a/crates/ide/src/completion/patterns.rs b/crates/ide/src/completion/patterns.rs
index c6ae589db..bc4ce4d6f 100644
--- a/crates/ide/src/completion/patterns.rs
+++ b/crates/ide/src/completion/patterns.rs
@@ -115,6 +115,16 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
115 .filter(|it| it.kind() == IF_KW) 115 .filter(|it| it.kind() == IF_KW)
116 .is_some() 116 .is_some()
117} 117}
118
119// TODO kb generify?
120pub(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
118#[test] 128#[test]
119fn test_if_is_prev() { 129fn test_if_is_prev() {
120 check_pattern_is_applicable(r"if l<|>", if_is_prev); 130 check_pattern_is_applicable(r"if l<|>", if_is_prev);