aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r--crates/ra_ide_api/src/completion/complete_snippet.rs44
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs152
2 files changed, 94 insertions, 102 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_snippet.rs b/crates/ra_ide_api/src/completion/complete_snippet.rs
index e0368b3b2..a35f31511 100644
--- a/crates/ra_ide_api/src/completion/complete_snippet.rs
+++ b/crates/ra_ide_api/src/completion/complete_snippet.rs
@@ -84,33 +84,31 @@ mod tests {
84 #[test] 84 #[test]
85 fn completes_snippets_in_items() { 85 fn completes_snippets_in_items() {
86 assert_debug_snapshot_matches!( 86 assert_debug_snapshot_matches!(
87 do_snippet_completion( 87 do_snippet_completion(
88 r" 88 r"
89 #[cfg(test)] 89 #[cfg(test)]
90 mod tests { 90 mod tests {
91 <|> 91 <|>
92 } 92 }
93 " 93 "
94 ), 94 ),
95 @r###" 95 @r###"[
96 ⋮[ 96 CompletionItem {
97 ⋮ CompletionItem { 97 label: "Test function",
98 ⋮ label: "Test function", 98 source_range: [78; 78),
99 ⋮ source_range: [78; 78), 99 delete: [78; 78),
100 ⋮ delete: [78; 78), 100 insert: "#[test]\nfn ${1:feature}() {\n $0\n}",
101 ⋮ insert: "#[test]\nfn ${1:feature}() {\n $0\n}", 101 kind: Snippet,
102 ⋮ kind: Snippet, 102 lookup: "tfn",
103 ⋮ lookup: "tfn", 103 },
104 ⋮ }, 104 CompletionItem {
105 ⋮ CompletionItem { 105 label: "pub(crate)",
106 ⋮ label: "pub(crate)", 106 source_range: [78; 78),
107 ⋮ source_range: [78; 78), 107 delete: [78; 78),
108 ⋮ delete: [78; 78), 108 insert: "pub(crate) $0",
109 ⋮ insert: "pub(crate) $0", 109 kind: Snippet,
110 ⋮ kind: Snippet, 110 },
111 ⋮ }, 111]"###
112 ⋮] 112 );
113 "###
114 );
115 } 113 }
116} 114}
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 5df19990c..6878008d3 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -194,64 +194,60 @@ mod tests {
194 fn inserts_parens_for_function_calls() { 194 fn inserts_parens_for_function_calls() {
195 covers!(inserts_parens_for_function_calls); 195 covers!(inserts_parens_for_function_calls);
196 assert_debug_snapshot_matches!( 196 assert_debug_snapshot_matches!(
197 do_reference_completion( 197 do_reference_completion(
198 r" 198 r"
199 fn no_args() {} 199 fn no_args() {}
200 fn main() { no_<|> } 200 fn main() { no_<|> }
201 " 201 "
202 ), 202 ),
203 @r###" 203 @r###"[
204 ⋮[ 204 CompletionItem {
205 ⋮ CompletionItem { 205 label: "main",
206 ⋮ label: "main", 206 source_range: [61; 64),
207 ⋮ source_range: [61; 64), 207 delete: [61; 64),
208 ⋮ delete: [61; 64), 208 insert: "main()$0",
209 ⋮ insert: "main()$0", 209 kind: Function,
210 ⋮ kind: Function, 210 detail: "fn main()",
211 ⋮ detail: "fn main()", 211 },
212 ⋮ }, 212 CompletionItem {
213 ⋮ CompletionItem { 213 label: "no_args",
214 ⋮ label: "no_args", 214 source_range: [61; 64),
215 ⋮ source_range: [61; 64), 215 delete: [61; 64),
216 ⋮ delete: [61; 64), 216 insert: "no_args()$0",
217 ⋮ insert: "no_args()$0", 217 kind: Function,
218 ⋮ kind: Function, 218 detail: "fn no_args()",
219 ⋮ detail: "fn no_args()", 219 },
220 ⋮ }, 220]"###
221 ⋮] 221 );
222 "###
223 );
224 assert_debug_snapshot_matches!( 222 assert_debug_snapshot_matches!(
225 do_reference_completion( 223 do_reference_completion(
226 r" 224 r"
227 fn with_args(x: i32, y: String) {} 225 fn with_args(x: i32, y: String) {}
228 fn main() { with_<|> } 226 fn main() { with_<|> }
229 " 227 "
230 ), 228 ),
231 @r###" 229 @r###"[
232 ⋮[ 230 CompletionItem {
233 ⋮ CompletionItem { 231 label: "main",
234 ⋮ label: "main", 232 source_range: [80; 85),
235 ⋮ source_range: [80; 85), 233 delete: [80; 85),
236 ⋮ delete: [80; 85), 234 insert: "main()$0",
237 ⋮ insert: "main()$0", 235 kind: Function,
238 ⋮ kind: Function, 236 detail: "fn main()",
239 ⋮ detail: "fn main()", 237 },
240 ⋮ }, 238 CompletionItem {
241 ⋮ CompletionItem { 239 label: "with_args",
242 ⋮ label: "with_args", 240 source_range: [80; 85),
243 ⋮ source_range: [80; 85), 241 delete: [80; 85),
244 ⋮ delete: [80; 85), 242 insert: "with_args($0)",
245 ⋮ insert: "with_args($0)", 243 kind: Function,
246 ⋮ kind: Function, 244 detail: "fn with_args(x: i32, y: String)",
247 ⋮ detail: "fn with_args(x: i32, y: String)", 245 },
248 ⋮ }, 246]"###
249 ⋮] 247 );
250 "###
251 );
252 assert_debug_snapshot_matches!( 248 assert_debug_snapshot_matches!(
253 do_reference_completion( 249 do_reference_completion(
254 r" 250 r"
255 struct S {} 251 struct S {}
256 impl S { 252 impl S {
257 fn foo(&self) {} 253 fn foo(&self) {}
@@ -260,33 +256,31 @@ mod tests {
260 s.f<|> 256 s.f<|>
261 } 257 }
262 " 258 "
263 ), 259 ),
264 @r###" 260 @r###"[
265 ⋮[ 261 CompletionItem {
266 ⋮ CompletionItem { 262 label: "foo",
267 ⋮ label: "foo", 263 source_range: [163; 164),
268 ⋮ source_range: [163; 164), 264 delete: [163; 164),
269 ⋮ delete: [163; 164), 265 insert: "foo()$0",
270 ⋮ insert: "foo()$0", 266 kind: Method,
271 ⋮ kind: Method, 267 detail: "fn foo(&self)",
272 ⋮ detail: "fn foo(&self)", 268 },
273 ⋮ }, 269]"###
274 ⋮] 270 );
275 "###
276 );
277 } 271 }
278 272
279 #[test] 273 #[test]
280 fn dont_render_function_parens_in_use_item() { 274 fn dont_render_function_parens_in_use_item() {
281 assert_debug_snapshot_matches!( 275 assert_debug_snapshot_matches!(
282 do_reference_completion( 276 do_reference_completion(
283 " 277 "
284 //- /lib.rs 278 //- /lib.rs
285 mod m { pub fn foo() {} } 279 mod m { pub fn foo() {} }
286 use crate::m::f<|>; 280 use crate::m::f<|>;
287 " 281 "
288 ), 282 ),
289 @r#"[ 283 @r#"[
290 CompletionItem { 284 CompletionItem {
291 label: "foo", 285 label: "foo",
292 source_range: [40; 41), 286 source_range: [40; 41),
@@ -296,22 +290,22 @@ mod tests {
296 detail: "pub fn foo()", 290 detail: "pub fn foo()",
297 }, 291 },
298]"# 292]"#
299 ); 293 );
300 } 294 }
301 295
302 #[test] 296 #[test]
303 fn dont_render_function_parens_if_already_call() { 297 fn dont_render_function_parens_if_already_call() {
304 assert_debug_snapshot_matches!( 298 assert_debug_snapshot_matches!(
305 do_reference_completion( 299 do_reference_completion(
306 " 300 "
307 //- /lib.rs 301 //- /lib.rs
308 fn frobnicate() {} 302 fn frobnicate() {}
309 fn main() { 303 fn main() {
310 frob<|>(); 304 frob<|>();
311 } 305 }
312 " 306 "
313 ), 307 ),
314 @r#"[ 308 @r#"[
315 CompletionItem { 309 CompletionItem {
316 label: "frobnicate", 310 label: "frobnicate",
317 source_range: [35; 39), 311 source_range: [35; 39),
@@ -329,10 +323,10 @@ mod tests {
329 detail: "fn main()", 323 detail: "fn main()",
330 }, 324 },
331]"# 325]"#
332 ); 326 );
333 assert_debug_snapshot_matches!( 327 assert_debug_snapshot_matches!(
334 do_reference_completion( 328 do_reference_completion(
335 " 329 "
336 //- /lib.rs 330 //- /lib.rs
337 struct Foo {} 331 struct Foo {}
338 impl Foo { fn new() -> Foo {} } 332 impl Foo { fn new() -> Foo {} }
@@ -340,8 +334,8 @@ mod tests {
340 Foo::ne<|>(); 334 Foo::ne<|>();
341 } 335 }
342 " 336 "
343 ), 337 ),
344 @r#"[ 338 @r#"[
345 CompletionItem { 339 CompletionItem {
346 label: "new", 340 label: "new",
347 source_range: [67; 69), 341 source_range: [67; 69),
@@ -351,6 +345,6 @@ mod tests {
351 detail: "fn new() -> Foo", 345 detail: "fn new() -> Foo",
352 }, 346 },
353]"# 347]"#
354 ); 348 );
355 } 349 }
356} 350}