Skip to content

Commit d389999

Browse files
committed
fix: show implicit param when it is an apply
1 parent 29dc892 commit d389999

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package dotty.tools.pc
33

44
import java.nio.file.Paths
55

6+
import scala.annotation.tailrec
7+
68
import scala.meta.internal.metals.ReportContext
79
import dotty.tools.pc.utils.InteractiveEnrichments.*
810
import dotty.tools.pc.printer.ShortenedTypePrinter
@@ -194,10 +196,10 @@ object ImplicitConversion:
194196
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context) =
195197
if (params.implicitConversions()) {
196198
tree match
197-
case Apply(fun: Ident, args) if isSynthetic(fun) =>
199+
case Apply(fun: Ident, args) if isSynthetic(fun) && args.exists(!_.span.isZeroExtent) =>
198200
implicitConversion(fun, args)
199201
case Apply(Select(fun, name), args)
200-
if name == nme.apply && isSynthetic(fun) =>
202+
if name == nme.apply && isSynthetic(fun) && args.exists(!_.span.isZeroExtent) =>
201203
implicitConversion(fun, args)
202204
case _ => None
203205
} else None
@@ -218,7 +220,7 @@ object ImplicitParameters:
218220
if (params.implicitParameters()) {
219221
tree match
220222
case Apply(fun, args)
221-
if args.exists(isSyntheticArg) && !tree.sourcePos.span.isZeroExtent =>
223+
if args.exists(isSyntheticArg) && !tree.sourcePos.span.isZeroExtent && !args.exists(isQuotes(_)) =>
222224
val (implicitArgs, providedArgs) = args.partition(isSyntheticArg)
223225
val allImplicit = providedArgs.isEmpty || providedArgs.forall {
224226
case Ident(name) => name == nme.MISSING
@@ -229,10 +231,12 @@ object ImplicitParameters:
229231
case _ => None
230232
} else None
231233

232-
private def isSyntheticArg(tree: Tree)(using Context) = tree match
234+
@tailrec
235+
def isSyntheticArg(tree: Tree)(using Context): Boolean = tree match
233236
case tree: Ident =>
234-
tree.span.isSynthetic && tree.symbol.isOneOf(Flags.GivenOrImplicit) &&
235-
!isQuotes(tree)
237+
tree.span.isSynthetic && tree.symbol.isOneOf(Flags.GivenOrImplicit)
238+
case Apply(fun, _ ) if tree.span.isZeroExtent => isSyntheticArg(fun)
239+
case TypeApply(fun, _ ) if tree.span.isZeroExtent => isSyntheticArg(fun)
236240
case _ => false
237241

238242
// Decorations for Quotes are rarely useful

presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,4 +920,24 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
920920
| case '[field *: fields] => ???
921921
|""".stripMargin
922922
)
923+
924+
@Test def `arg-apply` =
925+
check(
926+
"""|object Main:
927+
| case class A()
928+
| case class B[T]()
929+
| given A = A()
930+
| implicit def bar(using a: A): B[A] = B[A]()
931+
| def foo(using b: B[A]): String = "aaa"
932+
| val g: String = foo
933+
|""".stripMargin,
934+
"""|object Main:
935+
| case class A()
936+
| case class B[T]()
937+
| given A = A()
938+
| implicit def bar(using a: A): B[A] = B[A]()
939+
| def foo(using b: B[A]): String = "aaa"
940+
| val g: String = foo/*(using bar<<(5:15)>>)*/
941+
|""".stripMargin
942+
)
923943
}

0 commit comments

Comments
 (0)