From bc0e95e2c3c5fbb18a3251d8276eeb0ec1847a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zieli=C5=84ski=20Patryk?= <75637004+zielinsky@users.noreply.github.com> Date: Thu, 3 Jul 2025 11:41:10 +0200 Subject: [PATCH] Exclude named parameters inlay hints for java defined (#23462) We don't want to show named parameters inlay hints for java defined `(x$0, x$1 ...)`. [Cherry-picked 638feaf0cdbf538d3480ff47ee0d75c5119e3446] --- .../dotty/tools/pc/PcInlayHintsProvider.scala | 2 +- .../pc/tests/inlayHints/InlayHintsSuite.scala | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala index 0ef7871f7dae..3be5927a7aa0 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala @@ -434,7 +434,7 @@ object Parameters: def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context): Option[(Boolean, List[(Name, SourcePosition, Boolean)])] = def shouldSkipFun(fun: Tree)(using Context): Boolean = fun match - case sel: Select => isForComprehensionMethod(sel) || sel.symbol.name == nme.unapply + case sel: Select => isForComprehensionMethod(sel) || sel.symbol.name == nme.unapply || sel.symbol.is(Flags.JavaDefined) case _ => false def isInfixFun(fun: Tree, args: List[Tree])(using Context): Boolean = 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 f7243ca54d91..bc4443ee5d28 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala @@ -1227,4 +1227,20 @@ class InlayHintsSuite extends BaseInlayHintsSuite { |} |""".stripMargin ) + + @Test def `java-method-call` = + check( + """|object Main { + | val str = "hello" + | val sub = str.substring(1, 3) + | val replaced = str.replace('l', 'x') + |} + |""".stripMargin, + """|object Main { + | val str/*: String<>*/ = "hello" + | val sub/*: String<>*/ = str.substring(1, 3) + | val replaced/*: String<>*/ = str.replace('l', 'x') + |} + |""".stripMargin + ) }