aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-21 14:14:28 +0100
committerLukas Wirth <[email protected]>2021-06-21 14:14:28 +0100
commit0729913525a55cad3ffe9876c1eb05f7b880d22d (patch)
tree7ce7b744bb168f245f201a95b19b584479d93eda /crates
parentb9d85f55b7a0a2159971b42bb5dae71efbfeada4 (diff)
Various keyword completion fixes
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_completion/src/completions/keyword.rs6
-rw-r--r--crates/ide_completion/src/context.rs7
-rw-r--r--crates/ide_completion/src/patterns.rs9
-rw-r--r--crates/ide_completion/src/tests/type_pos.rs16
4 files changed, 22 insertions, 16 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index e40ec6280..407f796ef 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -92,7 +92,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
92 } 92 }
93 93
94 if !ctx.has_visibility_prev_sibling() 94 if !ctx.has_visibility_prev_sibling()
95 && (expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_record_field()) 95 && (expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_field())
96 { 96 {
97 add_keyword("pub(crate)", "pub(crate) "); 97 add_keyword("pub(crate)", "pub(crate) ");
98 add_keyword("pub", "pub "); 98 add_keyword("pub", "pub ");
@@ -122,6 +122,10 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
122 add_keyword("union", "union $1 {\n $0\n}"); 122 add_keyword("union", "union $1 {\n $0\n}");
123 } 123 }
124 124
125 if ctx.expects_type() {
126 return;
127 }
128
125 if ctx.expects_expression() { 129 if ctx.expects_expression() {
126 if !has_block_expr_parent { 130 if !has_block_expr_parent {
127 add_keyword("unsafe", "unsafe {\n $0\n}"); 131 add_keyword("unsafe", "unsafe {\n $0\n}");
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs
index e49e434fa..4814bd64d 100644
--- a/crates/ide_completion/src/context.rs
+++ b/crates/ide_completion/src/context.rs
@@ -286,8 +286,11 @@ impl<'a> CompletionContext<'a> {
286 ) 286 )
287 } 287 }
288 288
289 pub(crate) fn expect_record_field(&self) -> bool { 289 pub(crate) fn expect_field(&self) -> bool {
290 matches!(self.completion_location, Some(ImmediateLocation::RecordField)) 290 matches!(
291 self.completion_location,
292 Some(ImmediateLocation::RecordField | ImmediateLocation::TupleField)
293 )
291 } 294 }
292 295
293 pub(crate) fn in_use_tree(&self) -> bool { 296 pub(crate) fn in_use_tree(&self) -> bool {
diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs
index 271409c38..757c9a3da 100644
--- a/crates/ide_completion/src/patterns.rs
+++ b/crates/ide_completion/src/patterns.rs
@@ -31,6 +31,7 @@ pub(crate) enum ImmediateLocation {
31 Impl, 31 Impl,
32 Trait, 32 Trait,
33 RecordField, 33 RecordField,
34 TupleField,
34 RefExpr, 35 RefExpr,
35 IdentPat, 36 IdentPat,
36 BlockExpr, 37 BlockExpr,
@@ -187,7 +188,13 @@ pub(crate) fn determine_location(
187 ast::SourceFile(_it) => ImmediateLocation::ItemList, 188 ast::SourceFile(_it) => ImmediateLocation::ItemList,
188 ast::ItemList(_it) => ImmediateLocation::ItemList, 189 ast::ItemList(_it) => ImmediateLocation::ItemList,
189 ast::RefExpr(_it) => ImmediateLocation::RefExpr, 190 ast::RefExpr(_it) => ImmediateLocation::RefExpr,
190 ast::RecordField(_it) => ImmediateLocation::RecordField, 191 ast::RecordField(it) => if it.ty().map_or(false, |it| it.syntax().text_range().contains(offset)) {
192 return None;
193 } else {
194 ImmediateLocation::RecordField
195 },
196 ast::TupleField(_it) => ImmediateLocation::TupleField,
197 ast::TupleFieldList(_it) => ImmediateLocation::TupleField,
191 ast::AssocItemList(it) => match it.syntax().parent().map(|it| it.kind()) { 198 ast::AssocItemList(it) => match it.syntax().parent().map(|it| it.kind()) {
192 Some(IMPL) => ImmediateLocation::Impl, 199 Some(IMPL) => ImmediateLocation::Impl,
193 Some(TRAIT) => ImmediateLocation::Trait, 200 Some(TRAIT) => ImmediateLocation::Trait,
diff --git a/crates/ide_completion/src/tests/type_pos.rs b/crates/ide_completion/src/tests/type_pos.rs
index 2bfecdd08..1ab47b27e 100644
--- a/crates/ide_completion/src/tests/type_pos.rs
+++ b/crates/ide_completion/src/tests/type_pos.rs
@@ -23,7 +23,6 @@ macro_rules! makro {}
23 23
24#[test] 24#[test]
25fn record_field_ty() { 25fn record_field_ty() {
26 // FIXME: pub shouldnt show up here
27 check_with( 26 check_with(
28 r#" 27 r#"
29struct Foo<'lt, T, const C: usize> { 28struct Foo<'lt, T, const C: usize> {
@@ -31,8 +30,6 @@ struct Foo<'lt, T, const C: usize> {
31} 30}
32"#, 31"#,
33 expect![[r#" 32 expect![[r#"
34 kw pub(crate)
35 kw pub
36 sp Self 33 sp Self
37 tp T 34 tp T
38 tt Trait 35 tt Trait
@@ -42,7 +39,7 @@ struct Foo<'lt, T, const C: usize> {
42 md module 39 md module
43 st Foo<…> 40 st Foo<…>
44 st Unit 41 st Unit
45 ma makro!(…) macro_rules! makro 42 ma makro!(…) macro_rules! makro
46 bt u32 43 bt u32
47 "#]], 44 "#]],
48 ) 45 )
@@ -50,12 +47,13 @@ struct Foo<'lt, T, const C: usize> {
50 47
51#[test] 48#[test]
52fn tuple_struct_field() { 49fn tuple_struct_field() {
53 // FIXME: pub should show up here
54 check_with( 50 check_with(
55 r#" 51 r#"
56struct Foo<'lt, T, const C: usize>(f$0); 52struct Foo<'lt, T, const C: usize>(f$0);
57"#, 53"#,
58 expect![[r#" 54 expect![[r#"
55 kw pub(crate)
56 kw pub
59 sp Self 57 sp Self
60 tp T 58 tp T
61 tt Trait 59 tt Trait
@@ -65,7 +63,7 @@ struct Foo<'lt, T, const C: usize>(f$0);
65 md module 63 md module
66 st Foo<…> 64 st Foo<…>
67 st Unit 65 st Unit
68 ma makro!(…) macro_rules! makro 66 ma makro!(…) macro_rules! makro
69 bt u32 67 bt u32
70 "#]], 68 "#]],
71 ) 69 )
@@ -73,13 +71,11 @@ struct Foo<'lt, T, const C: usize>(f$0);
73 71
74#[test] 72#[test]
75fn fn_return_type() { 73fn fn_return_type() {
76 // FIXME: return shouldnt show up here
77 check_with( 74 check_with(
78 r#" 75 r#"
79fn x<'lt, T, const C: usize>() -> $0 76fn x<'lt, T, const C: usize>() -> $0
80"#, 77"#,
81 expect![[r#" 78 expect![[r#"
82 kw return
83 tp T 79 tp T
84 tt Trait 80 tt Trait
85 en Enum 81 en Enum
@@ -95,7 +91,6 @@ fn x<'lt, T, const C: usize>() -> $0
95 91
96#[test] 92#[test]
97fn body_type_pos() { 93fn body_type_pos() {
98 // FIXME: return shouldnt show up here
99 check_with( 94 check_with(
100 r#" 95 r#"
101fn foo<'lt, T, const C: usize>() { 96fn foo<'lt, T, const C: usize>() {
@@ -104,7 +99,6 @@ fn foo<'lt, T, const C: usize>() {
104} 99}
105"#, 100"#,
106 expect![[r#" 101 expect![[r#"
107 kw return
108 tp T 102 tp T
109 tt Trait 103 tt Trait
110 en Enum 104 en Enum
@@ -136,7 +130,6 @@ fn foo<'lt, T, const C: usize>() {
136 130
137#[test] 131#[test]
138fn completes_types_and_const_in_arg_list() { 132fn completes_types_and_const_in_arg_list() {
139 // FIXME: return shouldnt show up here
140 // FIXME: we should complete the lifetime here for now 133 // FIXME: we should complete the lifetime here for now
141 check_with( 134 check_with(
142 r#" 135 r#"
@@ -147,7 +140,6 @@ trait Trait2 {
147fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {} 140fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
148"#, 141"#,
149 expect![[r#" 142 expect![[r#"
150 kw return
151 ta Foo = type Foo; 143 ta Foo = type Foo;
152 tp T 144 tp T
153 cp CONST_PARAM 145 cp CONST_PARAM