diff options
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 185 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 166 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 534 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 148 |
5 files changed, 562 insertions, 475 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 28c8324d0..86c11a283 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -119,27 +119,28 @@ mod tests { | |||
119 | ", | 119 | ", |
120 | ), | 120 | ), |
121 | @r###" | 121 | @r###" |
122 | ⋮[ | 122 | [ |
123 | ⋮ CompletionItem { | 123 | CompletionItem { |
124 | ⋮ label: "foo", | 124 | label: "foo(…)", |
125 | ⋮ source_range: [187; 187), | 125 | source_range: [187; 187), |
126 | ⋮ delete: [187; 187), | 126 | delete: [187; 187), |
127 | ⋮ insert: "foo()$0", | 127 | insert: "foo()$0", |
128 | ⋮ kind: Method, | 128 | kind: Method, |
129 | ⋮ detail: "fn foo(self)", | 129 | lookup: "foo", |
130 | ⋮ }, | 130 | detail: "fn foo(self)", |
131 | ⋮ CompletionItem { | 131 | }, |
132 | ⋮ label: "the_field", | 132 | CompletionItem { |
133 | ⋮ source_range: [187; 187), | 133 | label: "the_field", |
134 | ⋮ delete: [187; 187), | 134 | source_range: [187; 187), |
135 | ⋮ insert: "the_field", | 135 | delete: [187; 187), |
136 | ⋮ kind: Field, | 136 | insert: "the_field", |
137 | ⋮ detail: "(u32,)", | 137 | kind: Field, |
138 | ⋮ documentation: Documentation( | 138 | detail: "(u32,)", |
139 | ⋮ "This is the_field", | 139 | documentation: Documentation( |
140 | ⋮ ), | 140 | "This is the_field", |
141 | ⋮ }, | 141 | ), |
142 | ⋮] | 142 | }, |
143 | ] | ||
143 | "### | 144 | "### |
144 | ); | 145 | ); |
145 | } | 146 | } |
@@ -158,24 +159,25 @@ mod tests { | |||
158 | ", | 159 | ", |
159 | ), | 160 | ), |
160 | @r###" | 161 | @r###" |
161 | ⋮[ | 162 | [ |
162 | ⋮ CompletionItem { | 163 | CompletionItem { |
163 | ⋮ label: "foo", | 164 | label: "foo(…)", |
164 | ⋮ source_range: [126; 126), | 165 | source_range: [126; 126), |
165 | ⋮ delete: [126; 126), | 166 | delete: [126; 126), |
166 | ⋮ insert: "foo()$0", | 167 | insert: "foo()$0", |
167 | ⋮ kind: Method, | 168 | kind: Method, |
168 | ⋮ detail: "fn foo(&self)", | 169 | lookup: "foo", |
169 | ⋮ }, | 170 | detail: "fn foo(&self)", |
170 | ⋮ CompletionItem { | 171 | }, |
171 | ⋮ label: "the_field", | 172 | CompletionItem { |
172 | ⋮ source_range: [126; 126), | 173 | label: "the_field", |
173 | ⋮ delete: [126; 126), | 174 | source_range: [126; 126), |
174 | ⋮ insert: "the_field", | 175 | delete: [126; 126), |
175 | ⋮ kind: Field, | 176 | insert: "the_field", |
176 | ⋮ detail: "(u32, i32)", | 177 | kind: Field, |
177 | ⋮ }, | 178 | detail: "(u32, i32)", |
178 | ⋮] | 179 | }, |
180 | ] | ||
179 | "### | 181 | "### |
180 | ); | 182 | ); |
181 | } | 183 | } |
@@ -210,16 +212,17 @@ mod tests { | |||
210 | ", | 212 | ", |
211 | ), | 213 | ), |
212 | @r###" | 214 | @r###" |
213 | ⋮[ | 215 | [ |
214 | ⋮ CompletionItem { | 216 | CompletionItem { |
215 | ⋮ label: "the_method", | 217 | label: "the_method(…)", |
216 | ⋮ source_range: [144; 144), | 218 | source_range: [144; 144), |
217 | ⋮ delete: [144; 144), | 219 | delete: [144; 144), |
218 | ⋮ insert: "the_method()$0", | 220 | insert: "the_method()$0", |
219 | ⋮ kind: Method, | 221 | kind: Method, |
220 | ⋮ detail: "fn the_method(&self)", | 222 | lookup: "the_method", |
221 | ⋮ }, | 223 | detail: "fn the_method(&self)", |
222 | ⋮] | 224 | }, |
225 | ] | ||
223 | "### | 226 | "### |
224 | ); | 227 | ); |
225 | } | 228 | } |
@@ -238,16 +241,17 @@ mod tests { | |||
238 | ", | 241 | ", |
239 | ), | 242 | ), |
240 | @r###" | 243 | @r###" |
241 | ⋮[ | 244 | [ |
242 | ⋮ CompletionItem { | 245 | CompletionItem { |
243 | ⋮ label: "the_method", | 246 | label: "the_method(…)", |
244 | ⋮ source_range: [151; 151), | 247 | source_range: [151; 151), |
245 | ⋮ delete: [151; 151), | 248 | delete: [151; 151), |
246 | ⋮ insert: "the_method()$0", | 249 | insert: "the_method()$0", |
247 | ⋮ kind: Method, | 250 | kind: Method, |
248 | ⋮ detail: "fn the_method(&self)", | 251 | lookup: "the_method", |
249 | ⋮ }, | 252 | detail: "fn the_method(&self)", |
250 | ⋮] | 253 | }, |
254 | ] | ||
251 | "### | 255 | "### |
252 | ); | 256 | ); |
253 | } | 257 | } |
@@ -266,16 +270,17 @@ mod tests { | |||
266 | ", | 270 | ", |
267 | ), | 271 | ), |
268 | @r###" | 272 | @r###" |
269 | ⋮[ | 273 | [ |
270 | ⋮ CompletionItem { | 274 | CompletionItem { |
271 | ⋮ label: "the_method", | 275 | label: "the_method(…)", |
272 | ⋮ source_range: [155; 155), | 276 | source_range: [155; 155), |
273 | ⋮ delete: [155; 155), | 277 | delete: [155; 155), |
274 | ⋮ insert: "the_method()$0", | 278 | insert: "the_method()$0", |
275 | ⋮ kind: Method, | 279 | kind: Method, |
276 | ⋮ detail: "fn the_method(&self)", | 280 | lookup: "the_method", |
277 | ⋮ }, | 281 | detail: "fn the_method(&self)", |
278 | ⋮] | 282 | }, |
283 | ] | ||
279 | "### | 284 | "### |
280 | ); | 285 | ); |
281 | } | 286 | } |
@@ -317,16 +322,17 @@ mod tests { | |||
317 | ", | 322 | ", |
318 | ), | 323 | ), |
319 | @r###" | 324 | @r###" |
320 | ⋮[ | 325 | [ |
321 | ⋮ CompletionItem { | 326 | CompletionItem { |
322 | ⋮ label: "the_method", | 327 | label: "the_method(…)", |
323 | ⋮ source_range: [249; 249), | 328 | source_range: [249; 249), |
324 | ⋮ delete: [249; 249), | 329 | delete: [249; 249), |
325 | ⋮ insert: "the_method()$0", | 330 | insert: "the_method()$0", |
326 | ⋮ kind: Method, | 331 | kind: Method, |
327 | ⋮ detail: "fn the_method(&self)", | 332 | lookup: "the_method", |
328 | ⋮ }, | 333 | detail: "fn the_method(&self)", |
329 | ⋮] | 334 | }, |
335 | ] | ||
330 | "### | 336 | "### |
331 | ); | 337 | ); |
332 | } | 338 | } |
@@ -386,16 +392,17 @@ mod tests { | |||
386 | ", | 392 | ", |
387 | ), | 393 | ), |
388 | @r###" | 394 | @r###" |
389 | ⋮[ | 395 | [ |
390 | ⋮ CompletionItem { | 396 | CompletionItem { |
391 | ⋮ label: "blah", | 397 | label: "blah(…)", |
392 | ⋮ source_range: [299; 300), | 398 | source_range: [299; 300), |
393 | ⋮ delete: [299; 300), | 399 | delete: [299; 300), |
394 | ⋮ insert: "blah()$0", | 400 | insert: "blah()$0", |
395 | ⋮ kind: Method, | 401 | kind: Method, |
396 | ⋮ detail: "pub fn blah(&self)", | 402 | lookup: "blah", |
397 | ⋮ }, | 403 | detail: "pub fn blah(&self)", |
398 | ⋮] | 404 | }, |
405 | ] | ||
399 | "### | 406 | "### |
400 | ); | 407 | ); |
401 | } | 408 | } |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index e01197fe4..b5e8bf591 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -375,19 +375,22 @@ mod tests { | |||
375 | fn foo() { let _ = S::<|> } | 375 | fn foo() { let _ = S::<|> } |
376 | " | 376 | " |
377 | ), | 377 | ), |
378 | @r###"[ | 378 | @r###" |
379 | CompletionItem { | 379 | [ |
380 | label: "m", | 380 | CompletionItem { |
381 | source_range: [100; 100), | 381 | label: "m(…)", |
382 | delete: [100; 100), | 382 | source_range: [100; 100), |
383 | insert: "m()$0", | 383 | delete: [100; 100), |
384 | kind: Function, | 384 | insert: "m()$0", |
385 | detail: "fn m()", | 385 | kind: Function, |
386 | documentation: Documentation( | 386 | lookup: "m", |
387 | "An associated method", | 387 | detail: "fn m()", |
388 | ), | 388 | documentation: Documentation( |
389 | }, | 389 | "An associated method", |
390 | ]"### | 390 | ), |
391 | }, | ||
392 | ] | ||
393 | "### | ||
391 | ); | 394 | ); |
392 | } | 395 | } |
393 | 396 | ||
@@ -474,19 +477,22 @@ mod tests { | |||
474 | fn foo() { let _ = S::<|> } | 477 | fn foo() { let _ = S::<|> } |
475 | " | 478 | " |
476 | ), | 479 | ), |
477 | @r###"[ | 480 | @r###" |
478 | CompletionItem { | 481 | [ |
479 | label: "m", | 482 | CompletionItem { |
480 | source_range: [100; 100), | 483 | label: "m(…)", |
481 | delete: [100; 100), | 484 | source_range: [100; 100), |
482 | insert: "m()$0", | 485 | delete: [100; 100), |
483 | kind: Function, | 486 | insert: "m()$0", |
484 | detail: "fn m()", | 487 | kind: Function, |
485 | documentation: Documentation( | 488 | lookup: "m", |
486 | "An associated method", | 489 | detail: "fn m()", |
487 | ), | 490 | documentation: Documentation( |
488 | }, | 491 | "An associated method", |
489 | ]"### | 492 | ), |
493 | }, | ||
494 | ] | ||
495 | "### | ||
490 | ); | 496 | ); |
491 | } | 497 | } |
492 | 498 | ||
@@ -507,19 +513,22 @@ mod tests { | |||
507 | fn foo() { let _ = U::<|> } | 513 | fn foo() { let _ = U::<|> } |
508 | " | 514 | " |
509 | ), | 515 | ), |
510 | @r###"[ | 516 | @r###" |
511 | CompletionItem { | 517 | [ |
512 | label: "m", | 518 | CompletionItem { |
513 | source_range: [101; 101), | 519 | label: "m(…)", |
514 | delete: [101; 101), | 520 | source_range: [101; 101), |
515 | insert: "m()$0", | 521 | delete: [101; 101), |
516 | kind: Function, | 522 | insert: "m()$0", |
517 | detail: "fn m()", | 523 | kind: Function, |
518 | documentation: Documentation( | 524 | lookup: "m", |
519 | "An associated method", | 525 | detail: "fn m()", |
520 | ), | 526 | documentation: Documentation( |
521 | }, | 527 | "An associated method", |
522 | ]"### | 528 | ), |
529 | }, | ||
530 | ] | ||
531 | "### | ||
523 | ); | 532 | ); |
524 | } | 533 | } |
525 | 534 | ||
@@ -564,24 +573,28 @@ mod tests { | |||
564 | } | 573 | } |
565 | " | 574 | " |
566 | ), | 575 | ), |
567 | @r###"[ | 576 | @r###" |
568 | CompletionItem { | 577 | [ |
569 | label: "bar", | 578 | CompletionItem { |
570 | source_range: [185; 185), | 579 | label: "bar(…)", |
571 | delete: [185; 185), | 580 | source_range: [185; 185), |
572 | insert: "bar()$0", | 581 | delete: [185; 185), |
573 | kind: Function, | 582 | insert: "bar()$0", |
574 | detail: "fn bar()", | 583 | kind: Function, |
575 | }, | 584 | lookup: "bar", |
576 | CompletionItem { | 585 | detail: "fn bar()", |
577 | label: "foo", | 586 | }, |
578 | source_range: [185; 185), | 587 | CompletionItem { |
579 | delete: [185; 185), | 588 | label: "foo(…)", |
580 | insert: "foo()$0", | 589 | source_range: [185; 185), |
581 | kind: Function, | 590 | delete: [185; 185), |
582 | detail: "fn foo()", | 591 | insert: "foo()$0", |
583 | }, | 592 | kind: Function, |
584 | ]"### | 593 | lookup: "foo", |
594 | detail: "fn foo()", | ||
595 | }, | ||
596 | ] | ||
597 | "### | ||
585 | ); | 598 | ); |
586 | } | 599 | } |
587 | 600 | ||
@@ -600,24 +613,27 @@ mod tests { | |||
600 | } | 613 | } |
601 | " | 614 | " |
602 | ), | 615 | ), |
603 | @r###"[ | 616 | @r###" |
604 | CompletionItem { | 617 | [ |
605 | label: "foo!", | 618 | CompletionItem { |
606 | source_range: [179; 179), | 619 | label: "foo!", |
607 | delete: [179; 179), | 620 | source_range: [179; 179), |
608 | insert: "foo!($0)", | 621 | delete: [179; 179), |
609 | kind: Macro, | 622 | insert: "foo!($0)", |
610 | detail: "#[macro_export]\nmacro_rules! foo", | 623 | kind: Macro, |
611 | }, | 624 | detail: "#[macro_export]\nmacro_rules! foo", |
612 | CompletionItem { | 625 | }, |
613 | label: "main", | 626 | CompletionItem { |
614 | source_range: [179; 179), | 627 | label: "main(…)", |
615 | delete: [179; 179), | 628 | source_range: [179; 179), |
616 | insert: "main()$0", | 629 | delete: [179; 179), |
617 | kind: Function, | 630 | insert: "main()$0", |
618 | detail: "fn main()", | 631 | kind: Function, |
619 | }, | 632 | lookup: "main", |
620 | ]"### | 633 | detail: "fn main()", |
634 | }, | ||
635 | ] | ||
636 | "### | ||
621 | ); | 637 | ); |
622 | } | 638 | } |
623 | } | 639 | } |
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 84826cdcc..b64540365 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -145,32 +145,35 @@ mod tests { | |||
145 | } | 145 | } |
146 | " | 146 | " |
147 | ), | 147 | ), |
148 | @r###"[ | 148 | @r###" |
149 | CompletionItem { | 149 | [ |
150 | label: "quux", | 150 | CompletionItem { |
151 | source_range: [91; 91), | 151 | label: "quux(…)", |
152 | delete: [91; 91), | 152 | source_range: [91; 91), |
153 | insert: "quux($0)", | 153 | delete: [91; 91), |
154 | kind: Function, | 154 | insert: "quux($0)", |
155 | detail: "fn quux(x: i32)", | 155 | kind: Function, |
156 | }, | 156 | lookup: "quux", |
157 | CompletionItem { | 157 | detail: "fn quux(x: i32)", |
158 | label: "x", | 158 | }, |
159 | source_range: [91; 91), | 159 | CompletionItem { |
160 | delete: [91; 91), | 160 | label: "x", |
161 | insert: "x", | 161 | source_range: [91; 91), |
162 | kind: Binding, | 162 | delete: [91; 91), |
163 | detail: "i32", | 163 | insert: "x", |
164 | }, | 164 | kind: Binding, |
165 | CompletionItem { | 165 | detail: "i32", |
166 | label: "y", | 166 | }, |
167 | source_range: [91; 91), | 167 | CompletionItem { |
168 | delete: [91; 91), | 168 | label: "y", |
169 | insert: "y", | 169 | source_range: [91; 91), |
170 | kind: Binding, | 170 | delete: [91; 91), |
171 | detail: "i32", | 171 | insert: "y", |
172 | }, | 172 | kind: Binding, |
173 | ]"### | 173 | detail: "i32", |
174 | }, | ||
175 | ] | ||
176 | "### | ||
174 | ); | 177 | ); |
175 | } | 178 | } |
176 | 179 | ||
@@ -190,31 +193,34 @@ mod tests { | |||
190 | } | 193 | } |
191 | " | 194 | " |
192 | ), | 195 | ), |
193 | @r###"[ | 196 | @r###" |
194 | CompletionItem { | 197 | [ |
195 | label: "a", | 198 | CompletionItem { |
196 | source_range: [242; 242), | 199 | label: "a", |
197 | delete: [242; 242), | 200 | source_range: [242; 242), |
198 | insert: "a", | 201 | delete: [242; 242), |
199 | kind: Binding, | 202 | insert: "a", |
200 | }, | 203 | kind: Binding, |
201 | CompletionItem { | 204 | }, |
202 | label: "b", | 205 | CompletionItem { |
203 | source_range: [242; 242), | 206 | label: "b", |
204 | delete: [242; 242), | 207 | source_range: [242; 242), |
205 | insert: "b", | 208 | delete: [242; 242), |
206 | kind: Binding, | 209 | insert: "b", |
207 | detail: "i32", | 210 | kind: Binding, |
208 | }, | 211 | detail: "i32", |
209 | CompletionItem { | 212 | }, |
210 | label: "quux", | 213 | CompletionItem { |
211 | source_range: [242; 242), | 214 | label: "quux(…)", |
212 | delete: [242; 242), | 215 | source_range: [242; 242), |
213 | insert: "quux()$0", | 216 | delete: [242; 242), |
214 | kind: Function, | 217 | insert: "quux()$0", |
215 | detail: "fn quux()", | 218 | kind: Function, |
216 | }, | 219 | lookup: "quux", |
217 | ]"### | 220 | detail: "fn quux()", |
221 | }, | ||
222 | ] | ||
223 | "### | ||
218 | ); | 224 | ); |
219 | } | 225 | } |
220 | 226 | ||
@@ -230,23 +236,26 @@ mod tests { | |||
230 | } | 236 | } |
231 | " | 237 | " |
232 | ), | 238 | ), |
233 | @r###"[ | 239 | @r###" |
234 | CompletionItem { | 240 | [ |
235 | label: "quux", | 241 | CompletionItem { |
236 | source_range: [95; 95), | 242 | label: "quux(…)", |
237 | delete: [95; 95), | 243 | source_range: [95; 95), |
238 | insert: "quux()$0", | 244 | delete: [95; 95), |
239 | kind: Function, | 245 | insert: "quux()$0", |
240 | detail: "fn quux()", | 246 | kind: Function, |
241 | }, | 247 | lookup: "quux", |
242 | CompletionItem { | 248 | detail: "fn quux()", |
243 | label: "x", | 249 | }, |
244 | source_range: [95; 95), | 250 | CompletionItem { |
245 | delete: [95; 95), | 251 | label: "x", |
246 | insert: "x", | 252 | source_range: [95; 95), |
247 | kind: Binding, | 253 | delete: [95; 95), |
248 | }, | 254 | insert: "x", |
249 | ]"### | 255 | kind: Binding, |
256 | }, | ||
257 | ] | ||
258 | "### | ||
250 | ); | 259 | ); |
251 | } | 260 | } |
252 | 261 | ||
@@ -260,23 +269,26 @@ mod tests { | |||
260 | } | 269 | } |
261 | " | 270 | " |
262 | ), | 271 | ), |
263 | @r###"[ | 272 | @r###" |
264 | CompletionItem { | 273 | [ |
265 | label: "T", | 274 | CompletionItem { |
266 | source_range: [52; 52), | 275 | label: "T", |
267 | delete: [52; 52), | 276 | source_range: [52; 52), |
268 | insert: "T", | 277 | delete: [52; 52), |
269 | kind: TypeParam, | 278 | insert: "T", |
270 | }, | 279 | kind: TypeParam, |
271 | CompletionItem { | 280 | }, |
272 | label: "quux", | 281 | CompletionItem { |
273 | source_range: [52; 52), | 282 | label: "quux(…)", |
274 | delete: [52; 52), | 283 | source_range: [52; 52), |
275 | insert: "quux()$0", | 284 | delete: [52; 52), |
276 | kind: Function, | 285 | insert: "quux()$0", |
277 | detail: "fn quux<T>()", | 286 | kind: Function, |
278 | }, | 287 | lookup: "quux", |
279 | ]"### | 288 | detail: "fn quux<T>()", |
289 | }, | ||
290 | ] | ||
291 | "### | ||
280 | ); | 292 | ); |
281 | } | 293 | } |
282 | 294 | ||
@@ -300,11 +312,12 @@ mod tests { | |||
300 | kind: TypeParam, | 312 | kind: TypeParam, |
301 | }, | 313 | }, |
302 | CompletionItem { | 314 | CompletionItem { |
303 | label: "X", | 315 | label: "X<…>", |
304 | source_range: [54; 54), | 316 | source_range: [54; 54), |
305 | delete: [54; 54), | 317 | delete: [54; 54), |
306 | insert: "X<$0>", | 318 | insert: "X<$0>", |
307 | kind: Struct, | 319 | kind: Struct, |
320 | lookup: "X", | ||
308 | }, | 321 | }, |
309 | ] | 322 | ] |
310 | "### | 323 | "### |
@@ -354,30 +367,33 @@ mod tests { | |||
354 | } | 367 | } |
355 | " | 368 | " |
356 | ), | 369 | ), |
357 | @r###"[ | 370 | @r###" |
358 | CompletionItem { | 371 | [ |
359 | label: "Baz", | 372 | CompletionItem { |
360 | source_range: [105; 105), | 373 | label: "Baz", |
361 | delete: [105; 105), | 374 | source_range: [105; 105), |
362 | insert: "Baz", | 375 | delete: [105; 105), |
363 | kind: Enum, | 376 | insert: "Baz", |
364 | }, | 377 | kind: Enum, |
365 | CompletionItem { | 378 | }, |
366 | label: "Foo", | 379 | CompletionItem { |
367 | source_range: [105; 105), | 380 | label: "Foo", |
368 | delete: [105; 105), | 381 | source_range: [105; 105), |
369 | insert: "Foo", | 382 | delete: [105; 105), |
370 | kind: Struct, | 383 | insert: "Foo", |
371 | }, | 384 | kind: Struct, |
372 | CompletionItem { | 385 | }, |
373 | label: "quux", | 386 | CompletionItem { |
374 | source_range: [105; 105), | 387 | label: "quux(…)", |
375 | delete: [105; 105), | 388 | source_range: [105; 105), |
376 | insert: "quux()$0", | 389 | delete: [105; 105), |
377 | kind: Function, | 390 | insert: "quux()$0", |
378 | detail: "fn quux()", | 391 | kind: Function, |
379 | }, | 392 | lookup: "quux", |
380 | ]"### | 393 | detail: "fn quux()", |
394 | }, | ||
395 | ] | ||
396 | "### | ||
381 | ); | 397 | ); |
382 | } | 398 | } |
383 | 399 | ||
@@ -417,23 +433,26 @@ mod tests { | |||
417 | } | 433 | } |
418 | " | 434 | " |
419 | ), | 435 | ), |
420 | @r###"[ | 436 | @r###" |
421 | CompletionItem { | 437 | [ |
422 | label: "Bar", | 438 | CompletionItem { |
423 | source_range: [117; 117), | 439 | label: "Bar", |
424 | delete: [117; 117), | 440 | source_range: [117; 117), |
425 | insert: "Bar", | 441 | delete: [117; 117), |
426 | kind: Struct, | 442 | insert: "Bar", |
427 | }, | 443 | kind: Struct, |
428 | CompletionItem { | 444 | }, |
429 | label: "quux", | 445 | CompletionItem { |
430 | source_range: [117; 117), | 446 | label: "quux(…)", |
431 | delete: [117; 117), | 447 | source_range: [117; 117), |
432 | insert: "quux()$0", | 448 | delete: [117; 117), |
433 | kind: Function, | 449 | insert: "quux()$0", |
434 | detail: "fn quux()", | 450 | kind: Function, |
435 | }, | 451 | lookup: "quux", |
436 | ]"### | 452 | detail: "fn quux()", |
453 | }, | ||
454 | ] | ||
455 | "### | ||
437 | ); | 456 | ); |
438 | } | 457 | } |
439 | 458 | ||
@@ -456,11 +475,12 @@ mod tests { | |||
456 | kind: Struct, | 475 | kind: Struct, |
457 | }, | 476 | }, |
458 | CompletionItem { | 477 | CompletionItem { |
459 | label: "x", | 478 | label: "x(…)", |
460 | source_range: [55; 55), | 479 | source_range: [55; 55), |
461 | delete: [55; 55), | 480 | delete: [55; 55), |
462 | insert: "x()$0", | 481 | insert: "x()$0", |
463 | kind: Function, | 482 | kind: Function, |
483 | lookup: "x", | ||
464 | detail: "fn x()", | 484 | detail: "fn x()", |
465 | }, | 485 | }, |
466 | ] | 486 | ] |
@@ -482,24 +502,27 @@ mod tests { | |||
482 | } | 502 | } |
483 | " | 503 | " |
484 | ), | 504 | ), |
485 | @r###"[ | 505 | @r###" |
486 | CompletionItem { | 506 | [ |
487 | label: "bar", | 507 | CompletionItem { |
488 | source_range: [146; 146), | 508 | label: "bar", |
489 | delete: [146; 146), | 509 | source_range: [146; 146), |
490 | insert: "bar", | 510 | delete: [146; 146), |
491 | kind: Binding, | 511 | insert: "bar", |
492 | detail: "i32", | 512 | kind: Binding, |
493 | }, | 513 | detail: "i32", |
494 | CompletionItem { | 514 | }, |
495 | label: "foo", | 515 | CompletionItem { |
496 | source_range: [146; 146), | 516 | label: "foo(…)", |
497 | delete: [146; 146), | 517 | source_range: [146; 146), |
498 | insert: "foo()$0", | 518 | delete: [146; 146), |
499 | kind: Function, | 519 | insert: "foo()$0", |
500 | detail: "fn foo()", | 520 | kind: Function, |
501 | }, | 521 | lookup: "foo", |
502 | ]"### | 522 | detail: "fn foo()", |
523 | }, | ||
524 | ] | ||
525 | "### | ||
503 | ); | 526 | ); |
504 | } | 527 | } |
505 | 528 | ||
@@ -554,11 +577,12 @@ mod tests { | |||
554 | kind: Struct, | 577 | kind: Struct, |
555 | }, | 578 | }, |
556 | CompletionItem { | 579 | CompletionItem { |
557 | label: "foo", | 580 | label: "foo(…)", |
558 | source_range: [18; 18), | 581 | source_range: [18; 18), |
559 | delete: [18; 18), | 582 | delete: [18; 18), |
560 | insert: "foo()$0", | 583 | insert: "foo()$0", |
561 | kind: Function, | 584 | kind: Function, |
585 | lookup: "foo", | ||
562 | detail: "fn foo()", | 586 | detail: "fn foo()", |
563 | }, | 587 | }, |
564 | CompletionItem { | 588 | CompletionItem { |
@@ -606,54 +630,57 @@ mod tests { | |||
606 | } | 630 | } |
607 | " | 631 | " |
608 | ), | 632 | ), |
609 | @r##"[ | 633 | @r###" |
610 | CompletionItem { | 634 | [ |
611 | label: "bar!", | 635 | CompletionItem { |
612 | source_range: [252; 252), | 636 | label: "bar!", |
613 | delete: [252; 252), | 637 | source_range: [252; 252), |
614 | insert: "bar!($0)", | 638 | delete: [252; 252), |
615 | kind: Macro, | 639 | insert: "bar!($0)", |
616 | detail: "macro_rules! bar", | 640 | kind: Macro, |
617 | }, | 641 | detail: "macro_rules! bar", |
618 | CompletionItem { | 642 | }, |
619 | label: "baz!", | 643 | CompletionItem { |
620 | source_range: [252; 252), | 644 | label: "baz!", |
621 | delete: [252; 252), | 645 | source_range: [252; 252), |
622 | insert: "baz!($0)", | 646 | delete: [252; 252), |
623 | kind: Macro, | 647 | insert: "baz!($0)", |
624 | detail: "#[macro_export]\nmacro_rules! baz", | 648 | kind: Macro, |
625 | }, | 649 | detail: "#[macro_export]\nmacro_rules! baz", |
626 | CompletionItem { | 650 | }, |
627 | label: "foo!", | 651 | CompletionItem { |
628 | source_range: [252; 252), | 652 | label: "foo!", |
629 | delete: [252; 252), | 653 | source_range: [252; 252), |
630 | insert: "foo!($0)", | 654 | delete: [252; 252), |
631 | kind: Macro, | 655 | insert: "foo!($0)", |
632 | detail: "macro_rules! foo", | 656 | kind: Macro, |
633 | }, | 657 | detail: "macro_rules! foo", |
634 | CompletionItem { | 658 | }, |
635 | label: "m1", | 659 | CompletionItem { |
636 | source_range: [252; 252), | 660 | label: "m1", |
637 | delete: [252; 252), | 661 | source_range: [252; 252), |
638 | insert: "m1", | 662 | delete: [252; 252), |
639 | kind: Module, | 663 | insert: "m1", |
640 | }, | 664 | kind: Module, |
641 | CompletionItem { | 665 | }, |
642 | label: "m2", | 666 | CompletionItem { |
643 | source_range: [252; 252), | 667 | label: "m2", |
644 | delete: [252; 252), | 668 | source_range: [252; 252), |
645 | insert: "m2", | 669 | delete: [252; 252), |
646 | kind: Module, | 670 | insert: "m2", |
647 | }, | 671 | kind: Module, |
648 | CompletionItem { | 672 | }, |
649 | label: "main", | 673 | CompletionItem { |
650 | source_range: [252; 252), | 674 | label: "main(…)", |
651 | delete: [252; 252), | 675 | source_range: [252; 252), |
652 | insert: "main()$0", | 676 | delete: [252; 252), |
653 | kind: Function, | 677 | insert: "main()$0", |
654 | detail: "fn main()", | 678 | kind: Function, |
655 | }, | 679 | lookup: "main", |
656 | ]"## | 680 | detail: "fn main()", |
681 | }, | ||
682 | ] | ||
683 | "### | ||
657 | ); | 684 | ); |
658 | } | 685 | } |
659 | 686 | ||
@@ -672,24 +699,27 @@ mod tests { | |||
672 | } | 699 | } |
673 | " | 700 | " |
674 | ), | 701 | ), |
675 | @r##"[ | 702 | @r###" |
676 | CompletionItem { | 703 | [ |
677 | label: "foo", | 704 | CompletionItem { |
678 | source_range: [49; 49), | 705 | label: "foo!", |
679 | delete: [49; 49), | 706 | source_range: [49; 49), |
680 | insert: "foo()$0", | 707 | delete: [49; 49), |
681 | kind: Function, | 708 | insert: "foo!($0)", |
682 | detail: "fn foo()", | 709 | kind: Macro, |
683 | }, | 710 | detail: "macro_rules! foo", |
684 | CompletionItem { | 711 | }, |
685 | label: "foo!", | 712 | CompletionItem { |
686 | source_range: [49; 49), | 713 | label: "foo(…)", |
687 | delete: [49; 49), | 714 | source_range: [49; 49), |
688 | insert: "foo!($0)", | 715 | delete: [49; 49), |
689 | kind: Macro, | 716 | insert: "foo()$0", |
690 | detail: "macro_rules! foo", | 717 | kind: Function, |
691 | }, | 718 | lookup: "foo", |
692 | ]"## | 719 | detail: "fn foo()", |
720 | }, | ||
721 | ] | ||
722 | "### | ||
693 | ); | 723 | ); |
694 | } | 724 | } |
695 | 725 | ||
@@ -708,24 +738,27 @@ mod tests { | |||
708 | } | 738 | } |
709 | " | 739 | " |
710 | ), | 740 | ), |
711 | @r##"[ | 741 | @r###" |
712 | CompletionItem { | 742 | [ |
713 | label: "foo!", | 743 | CompletionItem { |
714 | source_range: [57; 57), | 744 | label: "foo!", |
715 | delete: [57; 57), | 745 | source_range: [57; 57), |
716 | insert: "foo!($0)", | 746 | delete: [57; 57), |
717 | kind: Macro, | 747 | insert: "foo!($0)", |
718 | detail: "macro_rules! foo", | 748 | kind: Macro, |
719 | }, | 749 | detail: "macro_rules! foo", |
720 | CompletionItem { | 750 | }, |
721 | label: "main", | 751 | CompletionItem { |
722 | source_range: [57; 57), | 752 | label: "main(…)", |
723 | delete: [57; 57), | 753 | source_range: [57; 57), |
724 | insert: "main()$0", | 754 | delete: [57; 57), |
725 | kind: Function, | 755 | insert: "main()$0", |
726 | detail: "fn main()", | 756 | kind: Function, |
727 | }, | 757 | lookup: "main", |
728 | ]"## | 758 | detail: "fn main()", |
759 | }, | ||
760 | ] | ||
761 | "### | ||
729 | ); | 762 | ); |
730 | } | 763 | } |
731 | 764 | ||
@@ -744,24 +777,27 @@ mod tests { | |||
744 | } | 777 | } |
745 | " | 778 | " |
746 | ), | 779 | ), |
747 | @r##"[ | 780 | @r###" |
748 | CompletionItem { | 781 | [ |
749 | label: "foo!", | 782 | CompletionItem { |
750 | source_range: [50; 50), | 783 | label: "foo!", |
751 | delete: [50; 50), | 784 | source_range: [50; 50), |
752 | insert: "foo!($0)", | 785 | delete: [50; 50), |
753 | kind: Macro, | 786 | insert: "foo!($0)", |
754 | detail: "macro_rules! foo", | 787 | kind: Macro, |
755 | }, | 788 | detail: "macro_rules! foo", |
756 | CompletionItem { | 789 | }, |
757 | label: "main", | 790 | CompletionItem { |
758 | source_range: [50; 50), | 791 | label: "main(…)", |
759 | delete: [50; 50), | 792 | source_range: [50; 50), |
760 | insert: "main()$0", | 793 | delete: [50; 50), |
761 | kind: Function, | 794 | insert: "main()$0", |
762 | detail: "fn main()", | 795 | kind: Function, |
763 | }, | 796 | lookup: "main", |
764 | ]"## | 797 | detail: "fn main()", |
798 | }, | ||
799 | ] | ||
800 | "### | ||
765 | ); | 801 | ); |
766 | } | 802 | } |
767 | } | 803 | } |
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index b1f0390ec..3e6933bc1 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -216,6 +216,10 @@ impl Builder { | |||
216 | self.lookup = Some(lookup.into()); | 216 | self.lookup = Some(lookup.into()); |
217 | self | 217 | self |
218 | } | 218 | } |
219 | pub(crate) fn label(mut self, label: impl Into<String>) -> Builder { | ||
220 | self.label = label.into(); | ||
221 | self | ||
222 | } | ||
219 | pub(crate) fn insert_text(mut self, insert_text: impl Into<String>) -> Builder { | 223 | pub(crate) fn insert_text(mut self, insert_text: impl Into<String>) -> Builder { |
220 | self.insert_text = Some(insert_text.into()); | 224 | self.insert_text = Some(insert_text.into()); |
221 | self | 225 | self |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index b7807ef8e..175a27ba9 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -116,7 +116,10 @@ impl Completions { | |||
116 | if let Some(def) = generic_def { | 116 | if let Some(def) = generic_def { |
117 | if has_non_default_type_params(def, ctx.db) { | 117 | if has_non_default_type_params(def, ctx.db) { |
118 | tested_by!(inserts_angle_brackets_for_generics); | 118 | tested_by!(inserts_angle_brackets_for_generics); |
119 | completion_item = completion_item.insert_snippet(format!("{}<$0>", local_name)); | 119 | completion_item = completion_item |
120 | .lookup_by(local_name.clone()) | ||
121 | .label(format!("{}<…>", local_name)) | ||
122 | .insert_snippet(format!("{}<$0>", local_name)); | ||
120 | } | 123 | } |
121 | } | 124 | } |
122 | } | 125 | } |
@@ -169,14 +172,15 @@ impl Completions { | |||
169 | let ast_node = func.source(ctx.db).ast; | 172 | let ast_node = func.source(ctx.db).ast; |
170 | let detail = function_label(&ast_node); | 173 | let detail = function_label(&ast_node); |
171 | 174 | ||
172 | let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name) | 175 | let mut builder = |
173 | .kind(if data.has_self_param() { | 176 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) |
174 | CompletionItemKind::Method | 177 | .kind(if data.has_self_param() { |
175 | } else { | 178 | CompletionItemKind::Method |
176 | CompletionItemKind::Function | 179 | } else { |
177 | }) | 180 | CompletionItemKind::Function |
178 | .set_documentation(func.docs(ctx.db)) | 181 | }) |
179 | .detail(detail); | 182 | .set_documentation(func.docs(ctx.db)) |
183 | .detail(detail); | ||
180 | 184 | ||
181 | // Add `<>` for generic types | 185 | // Add `<>` for generic types |
182 | if ctx.use_item_syntax.is_none() | 186 | if ctx.use_item_syntax.is_none() |
@@ -190,7 +194,10 @@ impl Completions { | |||
190 | } else { | 194 | } else { |
191 | format!("{}($0)", data.name()) | 195 | format!("{}($0)", data.name()) |
192 | }; | 196 | }; |
193 | builder = builder.insert_snippet(snippet); | 197 | builder = builder |
198 | .lookup_by(name.clone()) | ||
199 | .label(format!("{}(…)", name)) | ||
200 | .insert_snippet(snippet); | ||
194 | } | 201 | } |
195 | 202 | ||
196 | self.add(builder) | 203 | self.add(builder) |
@@ -269,24 +276,28 @@ mod tests { | |||
269 | fn main() { no_<|> } | 276 | fn main() { no_<|> } |
270 | " | 277 | " |
271 | ), | 278 | ), |
272 | @r###"[ | 279 | @r###" |
273 | CompletionItem { | 280 | [ |
274 | label: "main", | 281 | CompletionItem { |
275 | source_range: [61; 64), | 282 | label: "main(…)", |
276 | delete: [61; 64), | 283 | source_range: [61; 64), |
277 | insert: "main()$0", | 284 | delete: [61; 64), |
278 | kind: Function, | 285 | insert: "main()$0", |
279 | detail: "fn main()", | 286 | kind: Function, |
280 | }, | 287 | lookup: "main", |
281 | CompletionItem { | 288 | detail: "fn main()", |
282 | label: "no_args", | 289 | }, |
283 | source_range: [61; 64), | 290 | CompletionItem { |
284 | delete: [61; 64), | 291 | label: "no_args(…)", |
285 | insert: "no_args()$0", | 292 | source_range: [61; 64), |
286 | kind: Function, | 293 | delete: [61; 64), |
287 | detail: "fn no_args()", | 294 | insert: "no_args()$0", |
288 | }, | 295 | kind: Function, |
289 | ]"### | 296 | lookup: "no_args", |
297 | detail: "fn no_args()", | ||
298 | }, | ||
299 | ] | ||
300 | "### | ||
290 | ); | 301 | ); |
291 | assert_debug_snapshot!( | 302 | assert_debug_snapshot!( |
292 | do_reference_completion( | 303 | do_reference_completion( |
@@ -295,24 +306,28 @@ mod tests { | |||
295 | fn main() { with_<|> } | 306 | fn main() { with_<|> } |
296 | " | 307 | " |
297 | ), | 308 | ), |
298 | @r###"[ | 309 | @r###" |
299 | CompletionItem { | 310 | [ |
300 | label: "main", | 311 | CompletionItem { |
301 | source_range: [80; 85), | 312 | label: "main(…)", |
302 | delete: [80; 85), | 313 | source_range: [80; 85), |
303 | insert: "main()$0", | 314 | delete: [80; 85), |
304 | kind: Function, | 315 | insert: "main()$0", |
305 | detail: "fn main()", | 316 | kind: Function, |
306 | }, | 317 | lookup: "main", |
307 | CompletionItem { | 318 | detail: "fn main()", |
308 | label: "with_args", | 319 | }, |
309 | source_range: [80; 85), | 320 | CompletionItem { |
310 | delete: [80; 85), | 321 | label: "with_args(…)", |
311 | insert: "with_args($0)", | 322 | source_range: [80; 85), |
312 | kind: Function, | 323 | delete: [80; 85), |
313 | detail: "fn with_args(x: i32, y: String)", | 324 | insert: "with_args($0)", |
314 | }, | 325 | kind: Function, |
315 | ]"### | 326 | lookup: "with_args", |
327 | detail: "fn with_args(x: i32, y: String)", | ||
328 | }, | ||
329 | ] | ||
330 | "### | ||
316 | ); | 331 | ); |
317 | assert_debug_snapshot!( | 332 | assert_debug_snapshot!( |
318 | do_reference_completion( | 333 | do_reference_completion( |
@@ -326,16 +341,19 @@ mod tests { | |||
326 | } | 341 | } |
327 | " | 342 | " |
328 | ), | 343 | ), |
329 | @r###"[ | 344 | @r###" |
330 | CompletionItem { | 345 | [ |
331 | label: "foo", | 346 | CompletionItem { |
332 | source_range: [163; 164), | 347 | label: "foo(…)", |
333 | delete: [163; 164), | 348 | source_range: [163; 164), |
334 | insert: "foo()$0", | 349 | delete: [163; 164), |
335 | kind: Method, | 350 | insert: "foo()$0", |
336 | detail: "fn foo(&self)", | 351 | kind: Method, |
337 | }, | 352 | lookup: "foo", |
338 | ]"### | 353 | detail: "fn foo(&self)", |
354 | }, | ||
355 | ] | ||
356 | "### | ||
339 | ); | 357 | ); |
340 | } | 358 | } |
341 | 359 | ||
@@ -430,18 +448,20 @@ mod tests { | |||
430 | @r###" | 448 | @r###" |
431 | [ | 449 | [ |
432 | CompletionItem { | 450 | CompletionItem { |
433 | label: "Vec", | 451 | label: "Vec<…>", |
434 | source_range: [61; 63), | 452 | source_range: [61; 63), |
435 | delete: [61; 63), | 453 | delete: [61; 63), |
436 | insert: "Vec<$0>", | 454 | insert: "Vec<$0>", |
437 | kind: Struct, | 455 | kind: Struct, |
456 | lookup: "Vec", | ||
438 | }, | 457 | }, |
439 | CompletionItem { | 458 | CompletionItem { |
440 | label: "foo", | 459 | label: "foo(…)", |
441 | source_range: [61; 63), | 460 | source_range: [61; 63), |
442 | delete: [61; 63), | 461 | delete: [61; 63), |
443 | insert: "foo($0)", | 462 | insert: "foo($0)", |
444 | kind: Function, | 463 | kind: Function, |
464 | lookup: "foo", | ||
445 | detail: "fn foo(xs: Ve)", | 465 | detail: "fn foo(xs: Ve)", |
446 | }, | 466 | }, |
447 | ] | 467 | ] |
@@ -457,18 +477,20 @@ mod tests { | |||
457 | @r###" | 477 | @r###" |
458 | [ | 478 | [ |
459 | CompletionItem { | 479 | CompletionItem { |
460 | label: "Vec", | 480 | label: "Vec<…>", |
461 | source_range: [64; 66), | 481 | source_range: [64; 66), |
462 | delete: [64; 66), | 482 | delete: [64; 66), |
463 | insert: "Vec<$0>", | 483 | insert: "Vec<$0>", |
464 | kind: TypeAlias, | 484 | kind: TypeAlias, |
485 | lookup: "Vec", | ||
465 | }, | 486 | }, |
466 | CompletionItem { | 487 | CompletionItem { |
467 | label: "foo", | 488 | label: "foo(…)", |
468 | source_range: [64; 66), | 489 | source_range: [64; 66), |
469 | delete: [64; 66), | 490 | delete: [64; 66), |
470 | insert: "foo($0)", | 491 | insert: "foo($0)", |
471 | kind: Function, | 492 | kind: Function, |
493 | lookup: "foo", | ||
472 | detail: "fn foo(xs: Ve)", | 494 | detail: "fn foo(xs: Ve)", |
473 | }, | 495 | }, |
474 | ] | 496 | ] |
@@ -491,11 +513,12 @@ mod tests { | |||
491 | kind: Struct, | 513 | kind: Struct, |
492 | }, | 514 | }, |
493 | CompletionItem { | 515 | CompletionItem { |
494 | label: "foo", | 516 | label: "foo(…)", |
495 | source_range: [68; 70), | 517 | source_range: [68; 70), |
496 | delete: [68; 70), | 518 | delete: [68; 70), |
497 | insert: "foo($0)", | 519 | insert: "foo($0)", |
498 | kind: Function, | 520 | kind: Function, |
521 | lookup: "foo", | ||
499 | detail: "fn foo(xs: Ve)", | 522 | detail: "fn foo(xs: Ve)", |
500 | }, | 523 | }, |
501 | ] | 524 | ] |
@@ -518,11 +541,12 @@ mod tests { | |||
518 | kind: Struct, | 541 | kind: Struct, |
519 | }, | 542 | }, |
520 | CompletionItem { | 543 | CompletionItem { |
521 | label: "foo", | 544 | label: "foo(…)", |
522 | source_range: [61; 63), | 545 | source_range: [61; 63), |
523 | delete: [61; 63), | 546 | delete: [61; 63), |
524 | insert: "foo($0)", | 547 | insert: "foo($0)", |
525 | kind: Function, | 548 | kind: Function, |
549 | lookup: "foo", | ||
526 | detail: "fn foo(xs: Ve<i128>)", | 550 | detail: "fn foo(xs: Ve<i128>)", |
527 | }, | 551 | }, |
528 | ] | 552 | ] |