File tree 2 files changed +118
-4
lines changed
src/main/dotty/tools/pc/completions
test/dotty/tools/pc/tests/completion
2 files changed +118
-4
lines changed Original file line number Diff line number Diff line change @@ -237,15 +237,24 @@ object NamedArgCompletions:
237
237
.getOrElse(baseArgs)
238
238
.filterNot(isUselessLiteral)
239
239
240
+ @ tailrec
241
+ def isDefaultArg (t : Tree ): Boolean = t match
242
+ // default args
243
+ case Ident (name) => name.is(DefaultGetterName )
244
+ // default args for methods defined in object
245
+ case Select (_, name) =>
246
+ name.is(DefaultGetterName )
247
+ // default args in not-first parameter list
248
+ // eg. def m(fst: Int)(snd: Int)(arg1: Int, arg2: Int = 123) = ???
249
+ case Apply (fun, _) => isDefaultArg(fun)
250
+ case _ => false
251
+
240
252
val isNamed : Set [Name ] = args.iterator
241
253
.zip(baseParams.iterator)
242
254
// filter out synthesized args and default arg getters
243
255
.filterNot {
244
256
case (arg, _) if arg.symbol.denot.is(Flags .Synthetic ) => true
245
- case (Ident (name), _) => name.is(DefaultGetterName ) // default args
246
- case (Select (Ident (_), name), _) =>
247
- name.is(DefaultGetterName ) // default args for apply method
248
- case _ => false
257
+ case (arg, _) => isDefaultArg(arg)
249
258
}
250
259
.map {
251
260
case (NamedArg (name, _), _) => name
Original file line number Diff line number Diff line change @@ -238,6 +238,111 @@ class CompletionArgSuite extends BaseCompletionSuite:
238
238
" "
239
239
)
240
240
241
+ @ Test def `default-args` =
242
+ check(
243
+ s """ |object Main {
244
+ | def foo() = {
245
+ | def deployment(
246
+ | fst: Option[String],
247
+ | snd: Int = 1,
248
+ | ): Option[Int] = ???
249
+ | val abc = deployment(@@)
250
+ | }
251
+ |}
252
+ | """ .stripMargin,
253
+ """ |fst = : Option[String]
254
+ |snd = : Int
255
+ |""" .stripMargin,
256
+ topLines = Some (2 ),
257
+ )
258
+ @ Test def `default-args2` =
259
+ check(
260
+ s """ |object Main {
261
+ | def deployment(
262
+ | fst: Option[String],
263
+ | snd: Int = 1,
264
+ | ): Option[Int] = ???
265
+ | val abc = deployment(@@)
266
+ |}
267
+ | """ .stripMargin,
268
+ """ |fst = : Option[String]
269
+ |snd = : Int
270
+ |""" .stripMargin,
271
+ topLines = Some (2 ),
272
+ )
273
+
274
+ @ Test def `default-args3` =
275
+ check(
276
+ s """ |object Main {
277
+ | def deployment(str: String)(
278
+ | fst: Option[String],
279
+ | snd: Int = 1,
280
+ | ): Option[Int] = ???
281
+ | val abc = deployment("str")(
282
+ | @@
283
+ | )
284
+ |}
285
+ | """ .stripMargin,
286
+ """ |fst = : Option[String]
287
+ |snd = : Int
288
+ |""" .stripMargin,
289
+ topLines = Some (2 ),
290
+ )
291
+
292
+ @ Test def `default-args4` =
293
+ check(
294
+ s """ |object Main {
295
+ | def deployment(str: String)(opt: Option[Int])(
296
+ | fst: Option[String],
297
+ | snd: Int = 1,
298
+ | ): Option[Int] = ???
299
+ | val abc = deployment("str")(None)(
300
+ | @@
301
+ | )
302
+ |}
303
+ | """ .stripMargin,
304
+ """ |fst = : Option[String]
305
+ |snd = : Int
306
+ |""" .stripMargin,
307
+ topLines = Some (2 ),
308
+ )
309
+
310
+ @ Test def `default-args5` =
311
+ check(
312
+ s """ |object Main {
313
+ | def deployment(str: String)(opt: Option[Int] = None)(
314
+ | fst: Option[String],
315
+ | snd: Int = 1,
316
+ | ): Option[Int] = ???
317
+ | val abc = deployment("str")(
318
+ | @@
319
+ | )
320
+ |}
321
+ | """ .stripMargin,
322
+ """ |opt = : Option[Int]
323
+ |""" .stripMargin,
324
+ topLines = Some (1 ),
325
+ )
326
+
327
+ @ Test def `default-args6` =
328
+ check(
329
+ s """ |object Main {
330
+ | def deployment(using str: String)(
331
+ | fst: Option[String],
332
+ | snd: Int = 1,
333
+ | ): Option[Int] = ???
334
+ | val abc = deployment(using "str")(
335
+ | @@
336
+ | )
337
+ |}
338
+ | """ .stripMargin,
339
+ """ |fst = : Option[String]
340
+ |snd = : Int
341
+ |""" .stripMargin,
342
+ topLines = Some (2 ),
343
+ )
344
+
345
+
241
346
// @Test def `explicit-dollar` =
242
347
// checkSnippet( // see: https://github.com/scalameta/metals/issues/2400
243
348
// """
You can’t perform that action at this time.
0 commit comments