Skip to content

Commit 638feaf

Browse files
authored
Exclude named parameters inlay hints for java defined (scala#23462)
We don't want to show named parameters inlay hints for java defined `(x$0, x$1 ...)`.
1 parent 4b97d25 commit 638feaf

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ object Parameters:
434434
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context): Option[(Boolean, List[(Name, SourcePosition, Boolean)])] =
435435
def shouldSkipFun(fun: Tree)(using Context): Boolean =
436436
fun match
437-
case sel: Select => isForComprehensionMethod(sel) || sel.symbol.name == nme.unapply
437+
case sel: Select => isForComprehensionMethod(sel) || sel.symbol.name == nme.unapply || sel.symbol.is(Flags.JavaDefined)
438438
case _ => false
439439

440440
def isInfixFun(fun: Tree, args: List[Tree])(using Context): Boolean =

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,4 +1261,20 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
12611261
|}
12621262
|""".stripMargin
12631263
)
1264+
1265+
@Test def `java-method-call` =
1266+
check(
1267+
"""|object Main {
1268+
| val str = "hello"
1269+
| val sub = str.substring(1, 3)
1270+
| val replaced = str.replace('l', 'x')
1271+
|}
1272+
|""".stripMargin,
1273+
"""|object Main {
1274+
| val str/*: String<<java/lang/String#>>*/ = "hello"
1275+
| val sub/*: String<<java/lang/String#>>*/ = str.substring(1, 3)
1276+
| val replaced/*: String<<java/lang/String#>>*/ = str.replace('l', 'x')
1277+
|}
1278+
|""".stripMargin
1279+
)
12641280
}

0 commit comments

Comments
 (0)