Skip to content

Commit

Permalink
refactor: Drop GlobalSymbolTable
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Aug 19, 2024
1 parent c3b94dc commit d755ed1
Show file tree
Hide file tree
Showing 19 changed files with 779 additions and 742 deletions.
8 changes: 5 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,10 @@ lazy val metals = project
V.lsp4j,
// for DAP
V.dap4j,
("ch.epfl.scala" %% "scala-debug-adapter" % V.debugAdapter)
.cross(CrossVersion.for3Use2_13),
withExcludes(
("ch.epfl.scala" %% "scala-debug-adapter" % V.debugAdapter)
.cross(CrossVersion.for3Use2_13)
),
// for finding paths of global log/cache directories
"dev.dirs" % "directories" % "26",
// ==================
Expand All @@ -495,7 +497,7 @@ lazy val metals = project
"com.outr" %% "scribe-file" % V.scribe,
"com.outr" %% "scribe-slf4j2" % V.scribe, // needed for flyway database migrations
// for JSON formatted doctor
"com.lihaoyi" %% "ujson" % "4.0.0",
"com.lihaoyi" %% "ujson" % "3.3.1",
// For fetching projects' templates
"com.lihaoyi" %% "requests" % "0.9.0",
// for producing SemanticDB from Scala source files, to be sure we want the same version of scalameta
Expand Down
694 changes: 694 additions & 0 deletions dep.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Supermethods(
filePath,
textDocument,
)
// TODO fallback to compilers
symbolInformation <- findSymbol(symbolOcc.symbol)
gotoSymbol <- {
if (symbolOcc.role.isDefinition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class ConnectionProvider(
case _ if !session.canReloadWorkspace =>
connect(CreateSession())
case _ =>
session.workspaceReload
session
.workspaceReload()
.flatMap(_ => connect(new ImportBuildAndIndex(session)))
.map { _ =>
scribe.info("Correctly reloaded workspace")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ case class Indexer(indexProviders: IndexProviders)(implicit rc: ReportContext) {
},
)
tracked.foreach { _ =>
statusBar().addMessage(
statusBar.addMessage(
s"${clientConfig.icons().rocket} Indexing complete!"
)
if (clientConfig.initialConfig.statistics.isMemory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,8 @@ abstract class MetalsLspService(
): Future[Unit] = {
paths
.find { path =>
if (clientConfig.isDidFocusProvider() || focusedDocument().isDefined) {
focusedDocument().contains(path) &&
if (clientConfig.isDidFocusProvider() || focusedDocument.isDefined) {
focusedDocument.contains(path) &&
path.isWorksheet
} else {
path.isWorksheet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class ProjectMetalsLspService(
).ignoreValue
case buildTools =>
for {
Some(buildTool) <- bspConfigGenerator.chooseBuildServerProvider(
case Some(buildTool) <- bspConfigGenerator.chooseBuildServerProvider(
buildTools
)
_ <- connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import scala.util.matching.Regex

import scala.meta.Importee
import scala.meta.internal.metals.MetalsEnrichments.given
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.mtags.DefinitionAlternatives.GlobalSymbol
import scala.meta.internal.mtags.Semanticdbs
import scala.meta.internal.mtags.Symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ class SqlSharedIndices
migrations = "/shared-db/migration",
) {

val jvmTypeHierarchy: JarTypeHierarchy = new JarTypeHierarchy(() => connect)
val jvmTypeHierarchy: JarTypeHierarchy = new JarTypeHierarchy(() => connect())
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ConvertToNamedArguments(
ServerCommands
.ConvertToNamedArgsRequest(
position,
apply.argIndices.map(Integer.valueOf).asJava,
apply.argIndices.map(Integer.valueOf).toArray,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class DebugDiscovery(
.flatMap(scalaTarget =>
JavaBinary.javaBinaryFromPath(scalaTarget.jvmHome)
)
.orElse(userConfig().usedJavaBinary)
.orElse(userConfig().usedJavaBinary())
buildTargetClasses
.jvmRunEnvironment(params.getTargets().get(0))
.map { envItem =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.eclipse.lsp4j.VersionedTextDocumentIdentifier
import org.eclipse.lsp4j.WorkspaceEdit
import org.eclipse.lsp4j.jsonrpc.messages.{Either => LSPEither}
import org.eclipse.lsp4j.{Range => LSPRange}
import scala.meta.internal.pc.PcSymbolInformation

final class RenameProvider(
referenceProvider: ReferenceProvider,
Expand Down Expand Up @@ -117,6 +118,7 @@ final class RenameProvider(
token: CancelToken,
): Future[WorkspaceEdit] = {
val source = params.getTextDocument.getUri.toAbsolutePath
// val scalaVersion =
val localRename = compilers
.rename(params, token)
.map(_.asScala.toList)
Expand Down Expand Up @@ -164,7 +166,8 @@ final class RenameProvider(
if (suggestedName.isBackticked)
suggestedName.stripBackticks
else suggestedName
val newName = Identifier.backtickWrap(withoutBackticks)
val newName =
KeywordWrapper.Scala3().backtickWrap(withoutBackticks)

def isNotRenamedSymbol(
textDocument: TextDocument,
Expand All @@ -179,15 +182,6 @@ final class RenameProvider(
foundName.contains(realName)
}

def shouldCheckImplementation(
symbol: String,
path: AbsolutePath,
textDocument: TextDocument,
) =
!symbol.desc.isType && !(symbol.isLocal && symbolHierarchyOps
.defaultSymbolSearch(path, textDocument)(symbol)
.exists(info => info.isTrait || info.isClass))

val allReferences =
for {
(occurence, semanticDb) <- symbolOccurrence.toIterable
Expand Down Expand Up @@ -235,13 +229,14 @@ final class RenameProvider(
source,
newName,
)
shouldCheckImplementationFut = shouldCheckImplementation(
occurence.symbol,
source,
semanticDb,
)
implReferences = implementations(
txtParams,
shouldCheckImplementation(
occurence.symbol,
source,
semanticDb,
),
shouldCheckImplementationFut,
newName,
)
} yield Future
Expand Down Expand Up @@ -327,6 +322,32 @@ final class RenameProvider(
Future.sequence(all.map(waiting => waiting())).ignoreValue
}

private def shouldCheckImplementation(
symbol: String,
path: AbsolutePath,
textDocument: TextDocument,
): Future[Boolean] = {
val notLocalAndType = !symbol.desc.isType && !symbol.isLocal

if (notLocalAndType) Future.successful(true)
else if (!symbol.isLocal) Future.successful(false)
else
symbolHierarchyOps
.defaultSymbolSearch(path, textDocument)(symbol)
.match {
case Some(info) =>
Future.successful(info.isTrait || info.isClass)
case None =>
compilers.info(path, symbol).map {
case None => false
case Some(value) =>
value.kind.getValue() == 13 ||
value.kind.getValue() == 14
}

}
}

/**
* In case of import renames, we can only rename the symbol in file.
* Global rename will not return any results, so this method will be used as
Expand Down Expand Up @@ -466,31 +487,32 @@ final class RenameProvider(

private def implementations(
textParams: TextDocumentPositionParams,
shouldCheckImplementation: Boolean,
shouldCheckImplementationFut: Future[Boolean],
newName: String,
): Future[Seq[Location]] = {
if (shouldCheckImplementation) {
for {
implLocs <- implementationProvider.implementations(textParams)
result <- {
val result = for {
implLoc <- implLocs
locParams = toReferenceParams(implLoc, includeDeclaration = true)
} yield {
referenceProvider
.references(
locParams,
findRealRange = AdjustRange(findRealRange(newName)),
includeSynthetic,
)
.map(_.flatMap(_.locations))
): Future[Seq[Location]] = shouldCheckImplementationFut.flatMap {
shouldCheckImplementation =>
if (shouldCheckImplementation) {
for {
implLocs <- implementationProvider.implementations(textParams)
result <- {
val result = for {
implLoc <- implLocs
locParams = toReferenceParams(implLoc, includeDeclaration = true)
} yield {
referenceProvider
.references(
locParams,
findRealRange = AdjustRange(findRealRange(newName)),
includeSynthetic,
)
.map(_.flatMap(_.locations))
}
Future.sequence(result)
}
Future.sequence(result)
}
} yield result.flatten
} else {
Future.successful(Nil)
}
} yield result.flatten
} else {
Future.successful(Nil)
}
}

private def canRenameSymbol(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import scala.meta.internal.semanticdb.SymbolOccurrence
import scala.meta.internal.semanticdb.TextDocument
import scala.meta.internal.semanticdb.TypeRef
import scala.meta.internal.semanticdb.XtensionSemanticdbSymbolInformation
import scala.meta.internal.symtab.GlobalSymbolTable
import scala.meta.io.AbsolutePath

import org.eclipse.lsp4j.Location
Expand All @@ -36,18 +35,14 @@ class SymbolHierarchyOps(
buffer: Buffers,
trees: Trees,
) {
private val globalTable = new GlobalClassTable(buildTargets)
def defaultSymbolSearch(
anyWorkspacePath: AbsolutePath,
textDocument: TextDocument,
): String => Option[SymbolInformation] = {
lazy val global =
globalTable.globalSymbolTableFor(anyWorkspacePath)
symbol => {
): String => Option[SymbolInformation] = { symbol =>
{
textDocument.symbols
.find(_.symbol == symbol)
.orElse(findSymbolInformation(symbol))
.orElse(global.flatMap(_.safeInfo(symbol)))
}
}

Expand Down Expand Up @@ -195,15 +190,6 @@ object SymbolHierarchyOps {
.find(sym => sym.symbol == symbol)
}

implicit class XtensionGlobalSymbolTable(symtab: GlobalSymbolTable) {
def safeInfo(symbol: String): Option[SymbolInformation] =
try {
symtab.info(symbol)
} catch {
case NonFatal(_) => None
}
}

def isClassLike(info: SymbolInformation): Boolean =
info.isObject || info.isClass || info.isTrait || info.isInterface

Expand Down
Loading

0 comments on commit d755ed1

Please sign in to comment.