From b3cfd6f4eb79cf0a019571927e28472bb8dc84d9 Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Tue, 5 Dec 2023 11:18:00 +0100 Subject: [PATCH] bugfix: Inconsistent highlight on class constructor --- .../scala/meta/internal/pc/PcCollector.scala | 11 ++++++++- .../highlight/DocumentHighlightSuite.scala | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/PcCollector.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/PcCollector.scala index e7ed27fa62c..0fb2d6bc09c 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/PcCollector.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/PcCollector.scala @@ -61,11 +61,20 @@ abstract class PcCollector[T]( info.member(sym.getterName), info.member(sym.setterName), info.member(sym.localName) - ) ++ sym.allOverriddenSymbols.toSet + ) ++ constructorParam(sym) ++ sym.allOverriddenSymbols.toSet } else Set(sym) all.filter(s => s != NoSymbol && !s.isError) } + private def constructorParam( + symbol: Symbol + ): Set[Symbol] = { + if (symbol.owner.isClass) { + val info = symbol.owner.info.member(nme.CONSTRUCTOR).info + info.paramss.flatten.find(_.name == symbol.name).toSet + } else Set.empty + } + private lazy val namedArgCache = { val parsedTree = parseTree(unit.source) parsedTree.collect { case arg @ AssignOrNamedArg(_, rhs) => diff --git a/tests/cross/src/test/scala/tests/highlight/DocumentHighlightSuite.scala b/tests/cross/src/test/scala/tests/highlight/DocumentHighlightSuite.scala index 975c746cb4e..4a78e62c4a3 100644 --- a/tests/cross/src/test/scala/tests/highlight/DocumentHighlightSuite.scala +++ b/tests/cross/src/test/scala/tests/highlight/DocumentHighlightSuite.scala @@ -1020,4 +1020,28 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite { |}""".stripMargin ) + check( + "extends", + """ + |abstract class Base(foo: Int, bar: Int) + | + |class Test(<>: Int, bar: Int) extends Base(<>, bar) { + | def transform = <> + bar + | val description = s"$<> & $bar" + |} + |""".stripMargin + ) + + check( + "extends1", + """ + |abstract class Base(foo: Int, bar: Int) + | + |class Test(<>: Int, bar: Int) extends Base(<>, bar) { + | def transform = <> + bar + | val description = s"$<> & $bar" + |} + |""".stripMargin + ) + }