diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_scope.rs | 36 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/completion_item.rs | 13 |
2 files changed, 39 insertions, 10 deletions
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index 514fd2f88..cd98efe95 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs | |||
@@ -74,7 +74,7 @@ mod tests { | |||
74 | let z = (); | 74 | let z = (); |
75 | } | 75 | } |
76 | ", | 76 | ", |
77 | "y;x;quux", | 77 | r#"y;x;quux "quux($0)""#, |
78 | ); | 78 | ); |
79 | } | 79 | } |
80 | 80 | ||
@@ -92,7 +92,7 @@ mod tests { | |||
92 | } | 92 | } |
93 | } | 93 | } |
94 | ", | 94 | ", |
95 | "b;a;quux", | 95 | r#"b;a;quux "quux()$0""#, |
96 | ); | 96 | ); |
97 | } | 97 | } |
98 | 98 | ||
@@ -106,7 +106,7 @@ mod tests { | |||
106 | } | 106 | } |
107 | } | 107 | } |
108 | ", | 108 | ", |
109 | "x;quux", | 109 | r#"x;quux "quux()$0""#, |
110 | ); | 110 | ); |
111 | } | 111 | } |
112 | 112 | ||
@@ -120,7 +120,7 @@ mod tests { | |||
120 | <|> | 120 | <|> |
121 | } | 121 | } |
122 | ", | 122 | ", |
123 | "quux;Foo;Baz", | 123 | r#"quux "quux()$0";Foo;Baz"#, |
124 | ); | 124 | ); |
125 | } | 125 | } |
126 | 126 | ||
@@ -134,7 +134,7 @@ mod tests { | |||
134 | fn quux() { <|> } | 134 | fn quux() { <|> } |
135 | } | 135 | } |
136 | ", | 136 | ", |
137 | "quux;Bar", | 137 | r#"quux "quux()$0";Bar"#, |
138 | ); | 138 | ); |
139 | } | 139 | } |
140 | 140 | ||
@@ -145,12 +145,12 @@ mod tests { | |||
145 | struct Foo; | 145 | struct Foo; |
146 | fn x() -> <|> | 146 | fn x() -> <|> |
147 | ", | 147 | ", |
148 | "Foo;x", | 148 | r#"Foo;x "x()$0""#, |
149 | ) | 149 | ) |
150 | } | 150 | } |
151 | 151 | ||
152 | #[test] | 152 | #[test] |
153 | fn dont_show_to_completions_for_shadowing() { | 153 | fn dont_show_both_completions_for_shadowing() { |
154 | check_reference_completion( | 154 | check_reference_completion( |
155 | r" | 155 | r" |
156 | fn foo() -> { | 156 | fn foo() -> { |
@@ -161,7 +161,7 @@ mod tests { | |||
161 | } | 161 | } |
162 | } | 162 | } |
163 | ", | 163 | ", |
164 | "bar;foo", | 164 | r#"bar;foo "foo()$0""#, |
165 | ) | 165 | ) |
166 | } | 166 | } |
167 | 167 | ||
@@ -169,4 +169,24 @@ mod tests { | |||
169 | fn completes_self_in_methods() { | 169 | fn completes_self_in_methods() { |
170 | check_reference_completion(r"impl S { fn foo(&self) { <|> } }", "self") | 170 | check_reference_completion(r"impl S { fn foo(&self) { <|> } }", "self") |
171 | } | 171 | } |
172 | |||
173 | #[test] | ||
174 | fn inserts_parens_for_function_calls() { | ||
175 | check_reference_completion( | ||
176 | r" | ||
177 | fn no_args() {} | ||
178 | fn main() { no_<|> } | ||
179 | ", | ||
180 | r#"no_args "no_args()$0" | ||
181 | main "main()$0""#, | ||
182 | ); | ||
183 | check_reference_completion( | ||
184 | r" | ||
185 | fn with_args(x: i32, y: String) {} | ||
186 | fn main() { with_<|> } | ||
187 | ", | ||
188 | r#"main "main()$0" | ||
189 | with_args "with_args($0)""#, | ||
190 | ); | ||
191 | } | ||
172 | } | 192 | } |
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index 1d294c553..b8fa39ae3 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs | |||
@@ -138,9 +138,18 @@ impl Builder { | |||
138 | .. | 138 | .. |
139 | } => CompletionItemKind::Enum, | 139 | } => CompletionItemKind::Enum, |
140 | PerNs { | 140 | PerNs { |
141 | values: Some(hir::Def::Function(..)), | 141 | values: Some(hir::Def::Function(function)), |
142 | .. | 142 | .. |
143 | } => CompletionItemKind::Function, | 143 | } => { |
144 | if let Some(sig_info) = function.signature_info(db) { | ||
145 | if sig_info.params.is_empty() { | ||
146 | self.snippet = Some(format!("{}()$0", self.label)); | ||
147 | } else { | ||
148 | self.snippet = Some(format!("{}($0)", self.label)); | ||
149 | } | ||
150 | } | ||
151 | CompletionItemKind::Function | ||
152 | } | ||
144 | _ => return self, | 153 | _ => return self, |
145 | }; | 154 | }; |
146 | self.kind = Some(kind); | 155 | self.kind = Some(kind); |