aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs14
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs14
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs2
-rw-r--r--crates/ra_syntax/src/grammar/items/nominal.rs4
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.rs2
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.txt62
7 files changed, 94 insertions, 6 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 65bba6dc7..80d0b1663 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -16,7 +16,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca
16 None => return Ok(()), 16 None => return Ok(()),
17 }; 17 };
18 let receiver_ty = infer_result[expr].clone(); 18 let receiver_ty = infer_result[expr].clone();
19 if !ctx.is_method_call { 19 if !ctx.is_call {
20 complete_fields(acc, ctx, receiver_ty)?; 20 complete_fields(acc, ctx, receiver_ty)?;
21 } 21 }
22 Ok(()) 22 Ok(())
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index 4723a65a6..2494d28ed 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -125,4 +125,18 @@ mod tests {
125 "foo", 125 "foo",
126 ) 126 )
127 } 127 }
128
129 #[test]
130 fn dont_render_function_parens_if_already_call() {
131 check_reference_completion(
132 "
133 //- /lib.rs
134 fn frobnicate() {}
135 fn main() {
136 frob<|>();
137 }
138 ",
139 "main;frobnicate",
140 )
141 }
128} 142}
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index 01786bb69..113f6c070 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -32,8 +32,8 @@ pub(super) struct CompletionContext<'a> {
32 pub(super) is_new_item: bool, 32 pub(super) is_new_item: bool,
33 /// The receiver if this is a field or method access, i.e. writing something.<|> 33 /// The receiver if this is a field or method access, i.e. writing something.<|>
34 pub(super) dot_receiver: Option<&'a ast::Expr>, 34 pub(super) dot_receiver: Option<&'a ast::Expr>,
35 /// If this is a method call in particular, i.e. the () are already there. 35 /// If this is a call (method or function) in particular, i.e. the () are already there.
36 pub(super) is_method_call: bool, 36 pub(super) is_call: bool,
37} 37}
38 38
39impl<'a> CompletionContext<'a> { 39impl<'a> CompletionContext<'a> {
@@ -60,7 +60,7 @@ impl<'a> CompletionContext<'a> {
60 can_be_stmt: false, 60 can_be_stmt: false,
61 is_new_item: false, 61 is_new_item: false,
62 dot_receiver: None, 62 dot_receiver: None,
63 is_method_call: false, 63 is_call: false,
64 }; 64 };
65 ctx.fill(original_file, position.offset); 65 ctx.fill(original_file, position.offset);
66 Ok(Some(ctx)) 66 Ok(Some(ctx))
@@ -172,6 +172,12 @@ impl<'a> CompletionContext<'a> {
172 } 172 }
173 } 173 }
174 } 174 }
175 self.is_call = path
176 .syntax()
177 .parent()
178 .and_then(ast::PathExpr::cast)
179 .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
180 .is_some()
175 } 181 }
176 if let Some(field_expr) = ast::FieldExpr::cast(parent) { 182 if let Some(field_expr) = ast::FieldExpr::cast(parent) {
177 // The receiver comes before the point of insertion of the fake 183 // The receiver comes before the point of insertion of the fake
@@ -187,7 +193,7 @@ impl<'a> CompletionContext<'a> {
187 .expr() 193 .expr()
188 .map(|e| e.syntax().range()) 194 .map(|e| e.syntax().range())
189 .and_then(|r| find_node_with_range(original_file.syntax(), r)); 195 .and_then(|r| find_node_with_range(original_file.syntax(), r));
190 self.is_method_call = true; 196 self.is_call = true;
191 } 197 }
192 } 198 }
193} 199}
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 334449fae..6a9770429 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -165,7 +165,7 @@ impl Builder {
165 165
166 fn from_function(mut self, ctx: &CompletionContext, function: hir::Function) -> Builder { 166 fn from_function(mut self, ctx: &CompletionContext, function: hir::Function) -> Builder {
167 // If not an import, add parenthesis automatically. 167 // If not an import, add parenthesis automatically.
168 if ctx.use_item_syntax.is_none() { 168 if ctx.use_item_syntax.is_none() && !ctx.is_call {
169 if function.signature(ctx.db).args().is_empty() { 169 if function.signature(ctx.db).args().is_empty() {
170 self.snippet = Some(format!("{}()$0", self.label)); 170 self.snippet = Some(format!("{}()$0", self.label));
171 } else { 171 } else {
diff --git a/crates/ra_syntax/src/grammar/items/nominal.rs b/crates/ra_syntax/src/grammar/items/nominal.rs
index 8d02ad555..495462ca7 100644
--- a/crates/ra_syntax/src/grammar/items/nominal.rs
+++ b/crates/ra_syntax/src/grammar/items/nominal.rs
@@ -29,6 +29,10 @@ pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) {
29 L_CURLY => named_field_def_list(p), 29 L_CURLY => named_field_def_list(p),
30 L_PAREN if kind == STRUCT_KW => { 30 L_PAREN if kind == STRUCT_KW => {
31 pos_field_list(p); 31 pos_field_list(p);
32 // test tuple_struct_where
33 // struct Test<T>(T) where T: Clone;
34 // struct Test<T>(T);
35 type_params::opt_where_clause(p);
32 p.expect(SEMI); 36 p.expect(SEMI);
33 } 37 }
34 _ if kind == STRUCT_KW => { 38 _ if kind == STRUCT_KW => {
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.rs
new file mode 100644
index 000000000..ddd59016d
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.rs
@@ -0,0 +1,2 @@
1struct Test<T>(T) where T: Clone;
2struct Test<T>(T);
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.txt
new file mode 100644
index 000000000..b7de83072
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.txt
@@ -0,0 +1,62 @@
1SOURCE_FILE@[0; 53)
2 STRUCT_DEF@[0; 33)
3 STRUCT_KW@[0; 6)
4 WHITESPACE@[6; 7)
5 NAME@[7; 11)
6 IDENT@[7; 11) "Test"
7 TYPE_PARAM_LIST@[11; 14)
8 L_ANGLE@[11; 12)
9 TYPE_PARAM@[12; 13)
10 NAME@[12; 13)
11 IDENT@[12; 13) "T"
12 R_ANGLE@[13; 14)
13 POS_FIELD_LIST@[14; 17)
14 L_PAREN@[14; 15)
15 POS_FIELD@[15; 16)
16 PATH_TYPE@[15; 16)
17 PATH@[15; 16)
18 PATH_SEGMENT@[15; 16)
19 NAME_REF@[15; 16)
20 IDENT@[15; 16) "T"
21 R_PAREN@[16; 17)
22 WHITESPACE@[17; 18)
23 WHERE_CLAUSE@[18; 32)
24 WHERE_KW@[18; 23)
25 WHITESPACE@[23; 24)
26 WHERE_PRED@[24; 32)
27 PATH_TYPE@[24; 25)
28 PATH@[24; 25)
29 PATH_SEGMENT@[24; 25)
30 NAME_REF@[24; 25)
31 IDENT@[24; 25) "T"
32 COLON@[25; 26)
33 WHITESPACE@[26; 27)
34 PATH_TYPE@[27; 32)
35 PATH@[27; 32)
36 PATH_SEGMENT@[27; 32)
37 NAME_REF@[27; 32)
38 IDENT@[27; 32) "Clone"
39 SEMI@[32; 33)
40 WHITESPACE@[33; 34)
41 STRUCT_DEF@[34; 52)
42 STRUCT_KW@[34; 40)
43 WHITESPACE@[40; 41)
44 NAME@[41; 45)
45 IDENT@[41; 45) "Test"
46 TYPE_PARAM_LIST@[45; 48)
47 L_ANGLE@[45; 46)
48 TYPE_PARAM@[46; 47)
49 NAME@[46; 47)
50 IDENT@[46; 47) "T"
51 R_ANGLE@[47; 48)
52 POS_FIELD_LIST@[48; 51)
53 L_PAREN@[48; 49)
54 POS_FIELD@[49; 50)
55 PATH_TYPE@[49; 50)
56 PATH@[49; 50)
57 PATH_SEGMENT@[49; 50)
58 NAME_REF@[49; 50)
59 IDENT@[49; 50) "T"
60 R_PAREN@[50; 51)
61 SEMI@[51; 52)
62 WHITESPACE@[52; 53)