@@ -75,6 +75,14 @@ final class PcInlayHintsProvider(
75
75
label,
76
76
InlayHintKind .Type
77
77
)
78
+ case ByNameParameters (byNameArgs) =>
79
+ byNameArgs.foldLeft(inlayHints) { case (ih, pos) =>
80
+ ih.add(
81
+ adjustPos(pos.focusStart).toLsp,
82
+ List (LabelPart (" => " )),
83
+ InlayHintKind .Parameter
84
+ )
85
+ }
78
86
case InferredType (tpe, pos) if tpe != null && ! tpe.isError =>
79
87
val adjustedPos = adjustPos(pos).focusEnd
80
88
if (inlayHints.containsDef(adjustedPos.start)) inlayHints
@@ -389,6 +397,62 @@ final class PcInlayHintsProvider(
389
397
}
390
398
}
391
399
400
+ object ByNameParameters {
401
+ // Extract the positions at which `=>` hints should be inserted
402
+ def unapply (tree : Tree ): Option [List [Position ]] =
403
+ if (params.byNameParameters())
404
+ tree match {
405
+ case Apply (sel : Select , _)
406
+ if isForComprehensionMethod(
407
+ sel
408
+ ) || sel.symbol.name == nme.unapply =>
409
+ None
410
+ case Apply (fun, args) =>
411
+ val params = fun.tpe.params
412
+
413
+ /* Special handling for a single block argument:
414
+ *
415
+ * someOption.getOrElse {/* => */
416
+ * fallbackCode
417
+ * }
418
+ *
419
+ * We cannot just match on the `Block` node because the case of a single expression in
420
+ * braces is not represented as a block. Instead, we search for the braces directly in
421
+ * the source code.
422
+ */
423
+ def singleArgBlockCase = (args, params) match {
424
+ case (Seq (_), Seq (param)) if param.isByNameParam =>
425
+ byNamePosForBlockLike(tree.pos.withStart(fun.pos.end))
426
+ .map(List (_))
427
+ case _ => None
428
+ }
429
+
430
+ /* For all other cases, we just insert the label before the argument tree:
431
+ *
432
+ * someOption.getOrElse(/* => */ fallbackCode)
433
+ */
434
+ Some (singleArgBlockCase.getOrElse {
435
+ args
436
+ .zip(params)
437
+ .collect { case (tree, param) if param.isByNameParam => tree }
438
+ .map(tree => tree.pos)
439
+ })
440
+ case _ => None
441
+ }
442
+ else None
443
+
444
+ // If the position passed in wraps a brace-delimited expression, return the position after the opening brace
445
+ private def byNamePosForBlockLike (pos : Position ): Option [Position ] = {
446
+ val start = text.indexWhere(! _.isWhitespace, pos.start)
447
+ val end = text.lastIndexWhere(! _.isWhitespace, pos.end - 1 )
448
+ if (text.lift(start).contains('{' ) && text.lift(end).contains('}' )) {
449
+ Some (pos.withStart(start + 1 ))
450
+ } else {
451
+ None
452
+ }
453
+ }
454
+ }
455
+
392
456
private def syntheticTupleApply (sel : Select ): Boolean = {
393
457
if (
394
458
sel.tpe != null && compiler.definitions.isTupleType(
0 commit comments