diff --git a/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala index 46b9cf3f4e3b..eb8e14a9cb85 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala @@ -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 => diff --git a/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala index 4f5a593c10e4..6c1e93279686 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala @@ -1723,4 +1723,38 @@ class InlayHintsSuite extends BaseInlayHintsSuite { | .sum/*[BigDecimal<>]*//*(using BigDecimalIsFractional<>)*//* : 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<>]*/ = 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<>]*/ = implicitly[Codec[Int]]/*(using intCodec<<(3:15)>>)*/ + | val y/*: Codec<<(1:6)>>[Int<>]*/ = summon[Codec[Int]]/*(using intCodec<<(3:15)>>)*/ + |} + |""".stripMargin + ) }