Skip to content

Commit

Permalink
add symbol fix to scala 3 pc
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed May 24, 2024
1 parent f71b186 commit 886e95d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package scala.meta.internal.pc
import scala.util.control.NonFatal

import scala.meta.internal.mtags.MtagsEnrichments.metalsDealias
import scala.meta.internal.mtags.MtagsEnrichments.stripBackticks
import scala.meta.pc.PcSymbolKind
import scala.meta.pc.PcSymbolProperty

import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Denotations.Denotation
import dotty.tools.dotc.core.Denotations.MultiDenotation
import dotty.tools.dotc.core.Flags
import dotty.tools.dotc.core.Names
import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.StdNames.nme
import dotty.tools.dotc.core.Symbols.*
Expand Down Expand Up @@ -91,10 +93,16 @@ object SymbolProvider:
val newSymbol = symbol.takeWhile(c => c != '.' && c != '#')
val rest = symbol.drop(newSymbol.size)
loop(rest.drop(1), (newSymbol, rest.headOption.exists(_ == '#')) :: acc)
val names =
loop(symbol.drop(index + 1).takeWhile(_ != '('), List.empty)

try toSymbols(pkg, names)
val (toNames, rest) =
val withoutPackage = symbol.drop(index + 1)
val i = withoutPackage.indexOf('(')
if (i < 0) (withoutPackage, "")
else withoutPackage.splitAt(i)
val optParamName = Some(rest.dropWhile(_ != '.').drop(2).dropRight(1)).filter(_.nonEmpty)
val names = loop(toNames, List.empty)

try toSymbols(pkg, names, optParamName)
catch case NonFatal(e) => Nil

private def normalizePackage(pkg: String): String =
Expand All @@ -103,6 +111,7 @@ object SymbolProvider:
private def toSymbols(
pkg: String,
parts: List[(String, Boolean)],
paramName: Option[String]
)(using Context): List[Symbol] =
def collectSymbols(denotation: Denotation): List[Symbol] =
denotation match
Expand All @@ -118,9 +127,10 @@ object SymbolProvider:
case (head, isClass) :: tl =>
val foundSymbols =
owners.flatMap { owner =>
val name = head.stripBackticks
val next =
if isClass then owner.info.member(typeName(head))
else owner.info.member(termName(head))
if isClass then owner.info.member(typeName(name))
else owner.info.member(termName(name))
collectSymbols(next).filter(_.exists)
}
if foundSymbols.nonEmpty then loop(foundSymbols, tl)
Expand All @@ -130,5 +140,8 @@ object SymbolProvider:
val pkgSym =
if pkg == "_empty_" then requiredPackage(nme.EMPTY_PACKAGE)
else requiredPackage(pkg)
loop(List(pkgSym), parts)
val found = loop(List(pkgSym), parts)
paramName match
case Some(name) => found.flatMap(_.paramSymss.flatten.find(_.showName == name))
case _ => found
end toSymbols
15 changes: 15 additions & 0 deletions tests/slow/src/test/scala/tests/feature/PcReferencesLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ class PcReferencesLspSuite
|""".stripMargin,
scalaVersion,
)

check(
s"constructor_$scalaVersion",
"""|/a/src/main/scala/Defn.scala
|package a
|case class Name(<<val@@ue>>: String)
|
|/a/src/main/scala/Main.scala
|package a
|object Main {
| val name2 = new Name(<<value>> = "44")
|}
|""".stripMargin,
scalaVersion,
)
}

def check(
Expand Down
17 changes: 17 additions & 0 deletions tests/slow/src/test/scala/tests/feature/RenameCrossLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,21 @@ class RenameCrossLspSuite extends BaseRenameLspSuite("rename-cross") {
scalaVersion = Some(V.scala3),
)

renamed(
"variable-explicit2",
"""|/a/src/main/scala/a/Main.scala
|package a
|object Main {
| var <<v5>> = false
|
| def f5: Boolean = {
| `<<v@@5>>_=`(true)
| <<v5>> == true
| }
|}
|""".stripMargin,
newName = "NewSymbol",
scalaVersion = Some(V.scala3),
)

}

0 comments on commit 886e95d

Please sign in to comment.