Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,18 @@ object ImplicitParameters:
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context) =
if (params.implicitParameters()) {
tree match
case Apply(fun, args)
if args.exists(isSyntheticArg) && !tree.sourcePos.span.isZeroExtent && !args.exists(isQuotes(_)) =>
val (implicitArgs, providedArgs) = args.partition(isSyntheticArg)
val pos = implicitArgs.head.sourcePos
Some(implicitArgs, pos)
case Apply(_, args) if hasImplicitArgs(tree, args) => implicitArgs(args)
case Inlined(Apply(_, args), _, _) if hasImplicitArgs(tree, args) => implicitArgs(args)
case _ => None
} else None

private def hasImplicitArgs(tree: Tree, args: List[Tree])(using Context): Boolean =
args.exists(isSyntheticArg) && !tree.sourcePos.span.isZeroExtent && !args.exists(isQuotes)

private def implicitArgs(args: List[Tree])(using Context): Option[(List[Tree], SourcePosition)] =
val found = args.filter(isSyntheticArg)
Option.when(found.nonEmpty)(found, found.head.sourcePos)

@tailrec
def isSyntheticArg(tree: Tree)(using Context): Boolean = tree match
case tree: Ident =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1723,4 +1723,38 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
| .sum/*[BigDecimal<<scala/math/BigDecimal#>>]*//*(using BigDecimalIsFractional<<scala/math/Numeric.BigDecimalIsFractional.>>)*//* : BigDecimal<<scala/math/BigDecimal#>>*/
|""".stripMargin
)

@Test def `implicit-params-metals-i8029` =
check(
"""|trait Codec[T]
|object Main {
| given intCodec: Codec[Int] = ???
| val x = summon[Codec[Int]]
|}
|""".stripMargin,
"""|trait Codec[T]
|object Main {
| given intCodec: Codec[Int] = ???
| val x/*: Codec<<(1:6)>>[Int<<scala/Int#>>]*/ = summon[Codec[Int]]/*(using intCodec<<(3:8)>>)*/
|}
|""".stripMargin
)

@Test def `implicit-params-metals-i8029-2` =
check(
"""|trait Codec[T]
|object Main {
| implicit val intCodec: Codec[Int] = ???
| val x = implicitly[Codec[Int]]
| val y = summon[Codec[Int]]
|}
|""".stripMargin,
"""|trait Codec[T]
|object Main {
| implicit val intCodec: Codec[Int] = ???
| val x/*: Codec<<(1:6)>>[Int<<scala/Int#>>]*/ = implicitly[Codec[Int]]/*(using intCodec<<(3:15)>>)*/
| val y/*: Codec<<(1:6)>>[Int<<scala/Int#>>]*/ = summon[Codec[Int]]/*(using intCodec<<(3:15)>>)*/
|}
|""".stripMargin
)
}
Loading