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_keyword.rs23
-rw-r--r--crates/ide/src/completion/complete_snippet.rs2
-rw-r--r--crates/ide/src/completion/completion_context.rs10
-rw-r--r--crates/ide/src/completion/patterns.rs8
4 files changed, 36 insertions, 7 deletions
diff --git a/crates/ide/src/completion/complete_keyword.rs b/crates/ide/src/completion/complete_keyword.rs
index 95e4ff1ac..53ba76e0e 100644
--- a/crates/ide/src/completion/complete_keyword.rs
+++ b/crates/ide/src/completion/complete_keyword.rs
@@ -129,8 +129,9 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
129 add_keyword(ctx, acc, "break", "break"); 129 add_keyword(ctx, acc, "break", "break");
130 } 130 }
131 } 131 }
132 if ctx.has_item_list_or_source_file_parent || ctx.has_impl_parent { 132 if ctx.has_item_list_or_source_file_parent || ctx.has_impl_parent | ctx.has_field_list_parent {
133 add_keyword(ctx, acc, "pub", "pub ") 133 add_keyword(ctx, acc, "pub(crate)", "pub(crate) ");
134 add_keyword(ctx, acc, "pub", "pub ");
134 } 135 }
135 136
136 if !ctx.is_trivial_path { 137 if !ctx.is_trivial_path {
@@ -227,6 +228,7 @@ mod tests {
227 kw impl 228 kw impl
228 kw mod 229 kw mod
229 kw pub 230 kw pub
231 kw pub(crate)
230 kw static 232 kw static
231 kw struct 233 kw struct
232 kw trait 234 kw trait
@@ -364,6 +366,7 @@ fn quux() -> i32 {
364 kw const 366 kw const
365 kw fn 367 kw fn
366 kw pub 368 kw pub
369 kw pub(crate)
367 kw type 370 kw type
368 kw unsafe 371 kw unsafe
369 "#]], 372 "#]],
@@ -524,4 +527,20 @@ pub mod future {
524 "#]], 527 "#]],
525 ) 528 )
526 } 529 }
530
531 #[test]
532 fn before_field() {
533 check(
534 r#"
535struct Foo {
536 <|>
537 pub f: i32,
538}
539"#,
540 expect![[r#"
541 kw pub
542 kw pub(crate)
543 "#]],
544 )
545 }
527} 546}
diff --git a/crates/ide/src/completion/complete_snippet.rs b/crates/ide/src/completion/complete_snippet.rs
index c3b03b199..4837d2910 100644
--- a/crates/ide/src/completion/complete_snippet.rs
+++ b/crates/ide/src/completion/complete_snippet.rs
@@ -65,7 +65,6 @@ fn ${1:feature}() {
65 .add_to(acc); 65 .add_to(acc);
66 66
67 snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}").add_to(acc); 67 snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}").add_to(acc);
68 snippet(ctx, cap, "pub(crate)", "pub(crate) $0").add_to(acc);
69} 68}
70 69
71#[cfg(test)] 70#[cfg(test)]
@@ -107,7 +106,6 @@ mod tests {
107"#, 106"#,
108 expect![[r#" 107 expect![[r#"
109 sn macro_rules 108 sn macro_rules
110 sn pub(crate)
111 sn tfn (Test function) 109 sn tfn (Test function)
112 sn tmod (Test module) 110 sn tmod (Test module)
113 "#]], 111 "#]],
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs
index 5adac7ebc..47355d5dc 100644
--- a/crates/ide/src/completion/completion_context.rs
+++ b/crates/ide/src/completion/completion_context.rs
@@ -16,9 +16,10 @@ use crate::{
16 call_info::ActiveParameter, 16 call_info::ActiveParameter,
17 completion::{ 17 completion::{
18 patterns::{ 18 patterns::{
19 has_bind_pat_parent, has_block_expr_parent, has_impl_as_prev_sibling, has_impl_parent, 19 has_bind_pat_parent, has_block_expr_parent, has_field_list_parent,
20 has_item_list_or_source_file_parent, has_ref_parent, has_trait_as_prev_sibling, 20 has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent,
21 has_trait_parent, if_is_prev, is_in_loop_body, is_match_arm, unsafe_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 }, 23 },
23 CompletionConfig, 24 CompletionConfig,
24 }, 25 },
@@ -84,6 +85,7 @@ pub(crate) struct CompletionContext<'a> {
84 pub(super) in_loop_body: bool, 85 pub(super) in_loop_body: bool,
85 pub(super) has_trait_parent: bool, 86 pub(super) has_trait_parent: bool,
86 pub(super) has_impl_parent: bool, 87 pub(super) has_impl_parent: bool,
88 pub(super) has_field_list_parent: bool,
87 pub(super) trait_as_prev_sibling: bool, 89 pub(super) trait_as_prev_sibling: bool,
88 pub(super) impl_as_prev_sibling: bool, 90 pub(super) impl_as_prev_sibling: bool,
89 pub(super) is_match_arm: bool, 91 pub(super) is_match_arm: bool,
@@ -157,6 +159,7 @@ impl<'a> CompletionContext<'a> {
157 block_expr_parent: false, 159 block_expr_parent: false,
158 has_trait_parent: false, 160 has_trait_parent: false,
159 has_impl_parent: false, 161 has_impl_parent: false,
162 has_field_list_parent: false,
160 trait_as_prev_sibling: false, 163 trait_as_prev_sibling: false,
161 impl_as_prev_sibling: false, 164 impl_as_prev_sibling: false,
162 if_is_prev: false, 165 if_is_prev: false,
@@ -230,6 +233,7 @@ impl<'a> CompletionContext<'a> {
230 self.in_loop_body = is_in_loop_body(syntax_element.clone()); 233 self.in_loop_body = is_in_loop_body(syntax_element.clone());
231 self.has_trait_parent = has_trait_parent(syntax_element.clone()); 234 self.has_trait_parent = has_trait_parent(syntax_element.clone());
232 self.has_impl_parent = has_impl_parent(syntax_element.clone()); 235 self.has_impl_parent = has_impl_parent(syntax_element.clone());
236 self.has_field_list_parent = has_field_list_parent(syntax_element.clone());
233 self.impl_as_prev_sibling = has_impl_as_prev_sibling(syntax_element.clone()); 237 self.impl_as_prev_sibling = has_impl_as_prev_sibling(syntax_element.clone());
234 self.trait_as_prev_sibling = has_trait_as_prev_sibling(syntax_element.clone()); 238 self.trait_as_prev_sibling = has_trait_as_prev_sibling(syntax_element.clone());
235 self.is_match_arm = is_match_arm(syntax_element.clone()); 239 self.is_match_arm = is_match_arm(syntax_element.clone());
diff --git a/crates/ide/src/completion/patterns.rs b/crates/ide/src/completion/patterns.rs
index ffc97c076..c6ae589db 100644
--- a/crates/ide/src/completion/patterns.rs
+++ b/crates/ide/src/completion/patterns.rs
@@ -34,6 +34,14 @@ pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool {
34fn test_has_impl_parent() { 34fn test_has_impl_parent() {
35 check_pattern_is_applicable(r"impl A { f<|> }", has_impl_parent); 35 check_pattern_is_applicable(r"impl A { f<|> }", has_impl_parent);
36} 36}
37pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool {
38 not_same_range_ancestor(element).filter(|it| it.kind() == RECORD_FIELD_LIST).is_some()
39}
40#[test]
41fn test_has_field_list_parent() {
42 check_pattern_is_applicable(r"struct Foo { f<|> }", has_field_list_parent);
43 check_pattern_is_applicable(r"struct Foo { f<|> pub f: i32}", has_field_list_parent);
44}
37 45
38pub(crate) fn has_block_expr_parent(element: SyntaxElement) -> bool { 46pub(crate) fn has_block_expr_parent(element: SyntaxElement) -> bool {
39 not_same_range_ancestor(element).filter(|it| it.kind() == BLOCK_EXPR).is_some() 47 not_same_range_ancestor(element).filter(|it| it.kind() == BLOCK_EXPR).is_some()