aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/completion/complete_attribute.rs2
-rw-r--r--crates/ide/src/completion/complete_mod.rs33
-rw-r--r--crates/ide/src/completion/complete_qualified_path.rs2
-rw-r--r--crates/ide/src/completion/complete_unqualified_path.rs2
-rw-r--r--crates/ide/src/completion/completion_context.rs8
-rw-r--r--crates/ide/src/completion/patterns.rs9
6 files changed, 30 insertions, 26 deletions
diff --git a/crates/ide/src/completion/complete_attribute.rs b/crates/ide/src/completion/complete_attribute.rs
index 6394189f0..ef4fb6a91 100644
--- a/crates/ide/src/completion/complete_attribute.rs
+++ b/crates/ide/src/completion/complete_attribute.rs
@@ -13,7 +13,7 @@ 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 { 16 if ctx.mod_under_caret.is_some() {
17 return None; 17 return None;
18 } 18 }
19 19
diff --git a/crates/ide/src/completion/complete_mod.rs b/crates/ide/src/completion/complete_mod.rs
index 5d41d0f69..f1795d2f7 100644
--- a/crates/ide/src/completion/complete_mod.rs
+++ b/crates/ide/src/completion/complete_mod.rs
@@ -5,15 +5,22 @@ use hir::{Module, ModuleSource};
5use ide_db::RootDatabase; 5use ide_db::RootDatabase;
6use rustc_hash::FxHashSet; 6use rustc_hash::FxHashSet;
7 7
8use super::{completion_context::CompletionContext, completion_item::Completions}; 8use crate::{CompletionItem, CompletionItemKind};
9
10use super::{
11 completion_context::CompletionContext, completion_item::CompletionKind,
12 completion_item::Completions,
13};
9 14
10/// Complete mod declaration, i.e. `mod <|> ;` 15/// Complete mod declaration, i.e. `mod <|> ;`
11pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { 16pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
12 let _p = profile::span("completion::complete_mod"); 17 let mod_under_caret = match &ctx.mod_under_caret {
18 Some(mod_under_caret) if mod_under_caret.item_list().is_some() => return None,
19 Some(mod_under_caret) => mod_under_caret,
20 None => return None,
21 };
13 22
14 if !ctx.mod_is_prev { 23 let _p = profile::span("completion::complete_mod");
15 return None;
16 }
17 24
18 let current_module = ctx.scope.module()?; 25 let current_module = ctx.scope.module()?;
19 26
@@ -36,7 +43,7 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
36 module_declaration_source_file.file_id.original_file(ctx.db) 43 module_declaration_source_file.file_id.original_file(ctx.db)
37 }); 44 });
38 45
39 let mod_declaration_candidates = source_root 46 source_root
40 .iter() 47 .iter()
41 .filter(|submodule_candidate_file| submodule_candidate_file != &module_definition_file) 48 .filter(|submodule_candidate_file| submodule_candidate_file != &module_definition_file)
42 .filter(|submodule_candidate_file| { 49 .filter(|submodule_candidate_file| {
@@ -66,10 +73,16 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
66 _ => None, 73 _ => None,
67 }) 74 })
68 .filter(|name| !existing_mod_declarations.contains(name)) 75 .filter(|name| !existing_mod_declarations.contains(name))
69 .collect::<Vec<_>>(); 76 .for_each(|submodule_name| {
70 dbg!(mod_declaration_candidates); 77 let mut label = submodule_name;
71 78 if mod_under_caret.semicolon_token().is_none() {
72 // TODO kb actually add the results 79 label.push(';')
80 }
81 acc.add(
82 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label)
83 .kind(CompletionItemKind::Module),
84 )
85 });
73 86
74 Some(()) 87 Some(())
75} 88}
diff --git a/crates/ide/src/completion/complete_qualified_path.rs b/crates/ide/src/completion/complete_qualified_path.rs
index 351461351..184488a73 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() || ctx.mod_is_prev { 16 if ctx.attribute_under_caret.is_some() || ctx.mod_under_caret.is_some() {
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 9f2dc16ab..f2189dfde 100644
--- a/crates/ide/src/completion/complete_unqualified_path.rs
+++ b/crates/ide/src/completion/complete_unqualified_path.rs
@@ -13,7 +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 || ctx.mod_under_caret.is_some()
17 { 17 {
18 return; 18 return;
19 } 19 }
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs
index d289aac27..ea4830843 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, mod_is_prev, unsafe_is_prev, 22 is_in_loop_body, is_match_arm, unsafe_is_prev,
23 }, 23 },
24 CompletionConfig, 24 CompletionConfig,
25 }, 25 },
@@ -77,7 +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) mod_under_caret: Option<ast::Module>,
81 pub(super) unsafe_is_prev: bool, 81 pub(super) unsafe_is_prev: bool,
82 pub(super) if_is_prev: bool, 82 pub(super) if_is_prev: bool,
83 pub(super) block_expr_parent: bool, 83 pub(super) block_expr_parent: bool,
@@ -153,7 +153,7 @@ impl<'a> CompletionContext<'a> {
153 has_type_args: false, 153 has_type_args: false,
154 dot_receiver_is_ambiguous_float_literal: false, 154 dot_receiver_is_ambiguous_float_literal: false,
155 attribute_under_caret: None, 155 attribute_under_caret: None,
156 mod_is_prev: false, 156 mod_under_caret: None,
157 unsafe_is_prev: false, 157 unsafe_is_prev: false,
158 in_loop_body: false, 158 in_loop_body: false,
159 ref_pat_parent: false, 159 ref_pat_parent: false,
@@ -241,7 +241,7 @@ impl<'a> CompletionContext<'a> {
241 self.is_match_arm = is_match_arm(syntax_element.clone()); 241 self.is_match_arm = is_match_arm(syntax_element.clone());
242 self.has_item_list_or_source_file_parent = 242 self.has_item_list_or_source_file_parent =
243 has_item_list_or_source_file_parent(syntax_element.clone()); 243 has_item_list_or_source_file_parent(syntax_element.clone());
244 self.mod_is_prev = mod_is_prev(syntax_element); 244 self.mod_under_caret = find_node_at_offset(&file_with_fake_ident, offset);
245 } 245 }
246 246
247 fn fill( 247 fn fill(
diff --git a/crates/ide/src/completion/patterns.rs b/crates/ide/src/completion/patterns.rs
index bc4ce4d6f..b17ddf133 100644
--- a/crates/ide/src/completion/patterns.rs
+++ b/crates/ide/src/completion/patterns.rs
@@ -116,15 +116,6 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
116 .is_some() 116 .is_some()
117} 117}
118 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
128#[test] 119#[test]
129fn test_if_is_prev() { 120fn test_if_is_prev() {
130 check_pattern_is_applicable(r"if l<|>", if_is_prev); 121 check_pattern_is_applicable(r"if l<|>", if_is_prev);