Skip to content

Commit d755ed1

Browse files
committed
refactor: Drop GlobalSymbolTable
1 parent c3b94dc commit d755ed1

File tree

19 files changed

+779
-742
lines changed

19 files changed

+779
-742
lines changed

build.sbt

+5-3
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,10 @@ lazy val metals = project
468468
V.lsp4j,
469469
// for DAP
470470
V.dap4j,
471-
("ch.epfl.scala" %% "scala-debug-adapter" % V.debugAdapter)
472-
.cross(CrossVersion.for3Use2_13),
471+
withExcludes(
472+
("ch.epfl.scala" %% "scala-debug-adapter" % V.debugAdapter)
473+
.cross(CrossVersion.for3Use2_13)
474+
),
473475
// for finding paths of global log/cache directories
474476
"dev.dirs" % "directories" % "26",
475477
// ==================
@@ -495,7 +497,7 @@ lazy val metals = project
495497
"com.outr" %% "scribe-file" % V.scribe,
496498
"com.outr" %% "scribe-slf4j2" % V.scribe, // needed for flyway database migrations
497499
// for JSON formatted doctor
498-
"com.lihaoyi" %% "ujson" % "4.0.0",
500+
"com.lihaoyi" %% "ujson" % "3.3.1",
499501
// For fetching projects' templates
500502
"com.lihaoyi" %% "requests" % "0.9.0",
501503
// for producing SemanticDB from Scala source files, to be sure we want the same version of scalameta

dep.txt

+694
Large diffs are not rendered by default.

metals/src/main/scala/scala/meta/internal/implementation/Supermethods.scala

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Supermethods(
8181
filePath,
8282
textDocument,
8383
)
84+
// TODO fallback to compilers
8485
symbolInformation <- findSymbol(symbolOcc.symbol)
8586
gotoSymbol <- {
8687
if (symbolOcc.role.isDefinition) {

metals/src/main/scala/scala/meta/internal/metals/ConnectionProvider.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ class ConnectionProvider(
240240
case _ if !session.canReloadWorkspace =>
241241
connect(CreateSession())
242242
case _ =>
243-
session.workspaceReload
243+
session
244+
.workspaceReload()
244245
.flatMap(_ => connect(new ImportBuildAndIndex(session)))
245246
.map { _ =>
246247
scribe.info("Correctly reloaded workspace")

metals/src/main/scala/scala/meta/internal/metals/Indexer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ case class Indexer(indexProviders: IndexProviders)(implicit rc: ReportContext) {
6262
},
6363
)
6464
tracked.foreach { _ =>
65-
statusBar().addMessage(
65+
statusBar.addMessage(
6666
s"${clientConfig.icons().rocket} Indexing complete!"
6767
)
6868
if (clientConfig.initialConfig.statistics.isMemory) {

metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,8 @@ abstract class MetalsLspService(
15711571
): Future[Unit] = {
15721572
paths
15731573
.find { path =>
1574-
if (clientConfig.isDidFocusProvider() || focusedDocument().isDefined) {
1575-
focusedDocument().contains(path) &&
1574+
if (clientConfig.isDidFocusProvider() || focusedDocument.isDefined) {
1575+
focusedDocument.contains(path) &&
15761576
path.isWorksheet
15771577
} else {
15781578
path.isWorksheet

metals/src/main/scala/scala/meta/internal/metals/ProjectMetalsLspService.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ class ProjectMetalsLspService(
533533
).ignoreValue
534534
case buildTools =>
535535
for {
536-
Some(buildTool) <- bspConfigGenerator.chooseBuildServerProvider(
536+
case Some(buildTool) <- bspConfigGenerator.chooseBuildServerProvider(
537537
buildTools
538538
)
539539
_ <- connect(

metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import scala.util.matching.Regex
1414

1515
import scala.meta.Importee
1616
import scala.meta.internal.metals.MetalsEnrichments.given
17+
import scala.meta.internal.metals.MetalsEnrichments._
1718
import scala.meta.internal.mtags.DefinitionAlternatives.GlobalSymbol
1819
import scala.meta.internal.mtags.Semanticdbs
1920
import scala.meta.internal.mtags.Symbol

metals/src/main/scala/scala/meta/internal/metals/SqlSharedIndices.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ class SqlSharedIndices
1212
migrations = "/shared-db/migration",
1313
) {
1414

15-
val jvmTypeHierarchy: JarTypeHierarchy = new JarTypeHierarchy(() => connect)
15+
val jvmTypeHierarchy: JarTypeHierarchy = new JarTypeHierarchy(() => connect())
1616
}

metals/src/main/scala/scala/meta/internal/metals/codeactions/ConvertToNamedArguments.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class ConvertToNamedArguments(
149149
ServerCommands
150150
.ConvertToNamedArgsRequest(
151151
position,
152-
apply.argIndices.map(Integer.valueOf).asJava,
152+
apply.argIndices.map(Integer.valueOf).toArray,
153153
)
154154
)
155155

metals/src/main/scala/scala/meta/internal/metals/debug/DebugDiscovery.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class DebugDiscovery(
326326
.flatMap(scalaTarget =>
327327
JavaBinary.javaBinaryFromPath(scalaTarget.jvmHome)
328328
)
329-
.orElse(userConfig().usedJavaBinary)
329+
.orElse(userConfig().usedJavaBinary())
330330
buildTargetClasses
331331
.jvmRunEnvironment(params.getTargets().get(0))
332332
.map { envItem =>

metals/src/main/scala/scala/meta/internal/rename/RenameProvider.scala

+60-38
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import org.eclipse.lsp4j.VersionedTextDocumentIdentifier
5050
import org.eclipse.lsp4j.WorkspaceEdit
5151
import org.eclipse.lsp4j.jsonrpc.messages.{Either => LSPEither}
5252
import org.eclipse.lsp4j.{Range => LSPRange}
53+
import scala.meta.internal.pc.PcSymbolInformation
5354

5455
final class RenameProvider(
5556
referenceProvider: ReferenceProvider,
@@ -117,6 +118,7 @@ final class RenameProvider(
117118
token: CancelToken,
118119
): Future[WorkspaceEdit] = {
119120
val source = params.getTextDocument.getUri.toAbsolutePath
121+
// val scalaVersion =
120122
val localRename = compilers
121123
.rename(params, token)
122124
.map(_.asScala.toList)
@@ -164,7 +166,8 @@ final class RenameProvider(
164166
if (suggestedName.isBackticked)
165167
suggestedName.stripBackticks
166168
else suggestedName
167-
val newName = Identifier.backtickWrap(withoutBackticks)
169+
val newName =
170+
KeywordWrapper.Scala3().backtickWrap(withoutBackticks)
168171

169172
def isNotRenamedSymbol(
170173
textDocument: TextDocument,
@@ -179,15 +182,6 @@ final class RenameProvider(
179182
foundName.contains(realName)
180183
}
181184

182-
def shouldCheckImplementation(
183-
symbol: String,
184-
path: AbsolutePath,
185-
textDocument: TextDocument,
186-
) =
187-
!symbol.desc.isType && !(symbol.isLocal && symbolHierarchyOps
188-
.defaultSymbolSearch(path, textDocument)(symbol)
189-
.exists(info => info.isTrait || info.isClass))
190-
191185
val allReferences =
192186
for {
193187
(occurence, semanticDb) <- symbolOccurrence.toIterable
@@ -235,13 +229,14 @@ final class RenameProvider(
235229
source,
236230
newName,
237231
)
232+
shouldCheckImplementationFut = shouldCheckImplementation(
233+
occurence.symbol,
234+
source,
235+
semanticDb,
236+
)
238237
implReferences = implementations(
239238
txtParams,
240-
shouldCheckImplementation(
241-
occurence.symbol,
242-
source,
243-
semanticDb,
244-
),
239+
shouldCheckImplementationFut,
245240
newName,
246241
)
247242
} yield Future
@@ -327,6 +322,32 @@ final class RenameProvider(
327322
Future.sequence(all.map(waiting => waiting())).ignoreValue
328323
}
329324

325+
private def shouldCheckImplementation(
326+
symbol: String,
327+
path: AbsolutePath,
328+
textDocument: TextDocument,
329+
): Future[Boolean] = {
330+
val notLocalAndType = !symbol.desc.isType && !symbol.isLocal
331+
332+
if (notLocalAndType) Future.successful(true)
333+
else if (!symbol.isLocal) Future.successful(false)
334+
else
335+
symbolHierarchyOps
336+
.defaultSymbolSearch(path, textDocument)(symbol)
337+
.match {
338+
case Some(info) =>
339+
Future.successful(info.isTrait || info.isClass)
340+
case None =>
341+
compilers.info(path, symbol).map {
342+
case None => false
343+
case Some(value) =>
344+
value.kind.getValue() == 13 ||
345+
value.kind.getValue() == 14
346+
}
347+
348+
}
349+
}
350+
330351
/**
331352
* In case of import renames, we can only rename the symbol in file.
332353
* Global rename will not return any results, so this method will be used as
@@ -466,31 +487,32 @@ final class RenameProvider(
466487

467488
private def implementations(
468489
textParams: TextDocumentPositionParams,
469-
shouldCheckImplementation: Boolean,
490+
shouldCheckImplementationFut: Future[Boolean],
470491
newName: String,
471-
): Future[Seq[Location]] = {
472-
if (shouldCheckImplementation) {
473-
for {
474-
implLocs <- implementationProvider.implementations(textParams)
475-
result <- {
476-
val result = for {
477-
implLoc <- implLocs
478-
locParams = toReferenceParams(implLoc, includeDeclaration = true)
479-
} yield {
480-
referenceProvider
481-
.references(
482-
locParams,
483-
findRealRange = AdjustRange(findRealRange(newName)),
484-
includeSynthetic,
485-
)
486-
.map(_.flatMap(_.locations))
492+
): Future[Seq[Location]] = shouldCheckImplementationFut.flatMap {
493+
shouldCheckImplementation =>
494+
if (shouldCheckImplementation) {
495+
for {
496+
implLocs <- implementationProvider.implementations(textParams)
497+
result <- {
498+
val result = for {
499+
implLoc <- implLocs
500+
locParams = toReferenceParams(implLoc, includeDeclaration = true)
501+
} yield {
502+
referenceProvider
503+
.references(
504+
locParams,
505+
findRealRange = AdjustRange(findRealRange(newName)),
506+
includeSynthetic,
507+
)
508+
.map(_.flatMap(_.locations))
509+
}
510+
Future.sequence(result)
487511
}
488-
Future.sequence(result)
489-
}
490-
} yield result.flatten
491-
} else {
492-
Future.successful(Nil)
493-
}
512+
} yield result.flatten
513+
} else {
514+
Future.successful(Nil)
515+
}
494516
}
495517

496518
private def canRenameSymbol(

metals/src/main/scala/scala/meta/internal/search/GlobalClassTable.scala

-33
This file was deleted.

metals/src/main/scala/scala/meta/internal/search/SymbolHierarchyOps.scala

+2-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import scala.meta.internal.semanticdb.SymbolOccurrence
2222
import scala.meta.internal.semanticdb.TextDocument
2323
import scala.meta.internal.semanticdb.TypeRef
2424
import scala.meta.internal.semanticdb.XtensionSemanticdbSymbolInformation
25-
import scala.meta.internal.symtab.GlobalSymbolTable
2625
import scala.meta.io.AbsolutePath
2726

2827
import org.eclipse.lsp4j.Location
@@ -36,18 +35,14 @@ class SymbolHierarchyOps(
3635
buffer: Buffers,
3736
trees: Trees,
3837
) {
39-
private val globalTable = new GlobalClassTable(buildTargets)
4038
def defaultSymbolSearch(
4139
anyWorkspacePath: AbsolutePath,
4240
textDocument: TextDocument,
43-
): String => Option[SymbolInformation] = {
44-
lazy val global =
45-
globalTable.globalSymbolTableFor(anyWorkspacePath)
46-
symbol => {
41+
): String => Option[SymbolInformation] = { symbol =>
42+
{
4743
textDocument.symbols
4844
.find(_.symbol == symbol)
4945
.orElse(findSymbolInformation(symbol))
50-
.orElse(global.flatMap(_.safeInfo(symbol)))
5146
}
5247
}
5348

@@ -195,15 +190,6 @@ object SymbolHierarchyOps {
195190
.find(sym => sym.symbol == symbol)
196191
}
197192

198-
implicit class XtensionGlobalSymbolTable(symtab: GlobalSymbolTable) {
199-
def safeInfo(symbol: String): Option[SymbolInformation] =
200-
try {
201-
symtab.info(symbol)
202-
} catch {
203-
case NonFatal(_) => None
204-
}
205-
}
206-
207193
def isClassLike(info: SymbolInformation): Boolean =
208194
info.isObject || info.isClass || info.isTrait || info.isInterface
209195

0 commit comments

Comments
 (0)