From 7d4483776e6eb51b0babc7aa0f6f32d4a8ea3633 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Thu, 26 Oct 2023 11:36:55 +0200 Subject: [PATCH] bugfix: Remove old semanticdb files when not needed Previously, we would try to remove semanticdb files from indexes while we used the actual source file. Now, we properly remove files in all indexes and also from interactive semanticdb --- .../decorations/SyntheticsDecorationProvider.scala | 3 +-- .../internal/implementation/ImplementationProvider.scala | 3 +-- .../meta/internal/metals/InteractiveSemanticdbs.scala | 5 ++++- .../scala/meta/internal/metals/MetalsLspService.scala | 1 + .../scala/meta/internal/metals/ReferenceProvider.scala | 3 +-- .../scala/meta/internal/metals/SemanticdbIndexer.scala | 7 +++++-- .../internal/metals/testProvider/TestSuitesProvider.scala | 3 +-- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/decorations/SyntheticsDecorationProvider.scala b/metals/src/main/scala/scala/meta/internal/decorations/SyntheticsDecorationProvider.scala index feed18b1dad..95e4390050c 100644 --- a/metals/src/main/scala/scala/meta/internal/decorations/SyntheticsDecorationProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/decorations/SyntheticsDecorationProvider.scala @@ -21,7 +21,6 @@ import scala.meta.internal.metals.ServerCommands import scala.meta.internal.metals.UserConfiguration import scala.meta.internal.metap.PrinterSymtab import scala.meta.internal.mtags.Md5Fingerprints -import scala.meta.internal.mtags.SemanticdbPath import scala.meta.internal.mtags.Semanticdbs import scala.meta.internal.parsing.TokenEditDistance import scala.meta.internal.parsing.Trees @@ -80,7 +79,7 @@ final class SyntheticsDecorationProvider( } } - override def onDelete(path: SemanticdbPath): Unit = () + override def onDelete(path: AbsolutePath): Unit = () override def reset(): Unit = () override def onChange( diff --git a/metals/src/main/scala/scala/meta/internal/implementation/ImplementationProvider.scala b/metals/src/main/scala/scala/meta/internal/implementation/ImplementationProvider.scala index 55a624e227d..f36257b9ebb 100644 --- a/metals/src/main/scala/scala/meta/internal/implementation/ImplementationProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/implementation/ImplementationProvider.scala @@ -18,7 +18,6 @@ import scala.meta.internal.metals.ScalaVersionSelector import scala.meta.internal.metals.SemanticdbFeatureProvider import scala.meta.internal.mtags.GlobalSymbolIndex import scala.meta.internal.mtags.Mtags -import scala.meta.internal.mtags.SemanticdbPath import scala.meta.internal.mtags.Semanticdbs import scala.meta.internal.mtags.SymbolDefinition import scala.meta.internal.mtags.{Symbol => MSymbol} @@ -59,7 +58,7 @@ final class ImplementationProvider( implementationsInPath.clear() } - override def onDelete(path: SemanticdbPath): Unit = { + override def onDelete(path: AbsolutePath): Unit = { implementationsInPath.remove(path.toNIO) } diff --git a/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala b/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala index fe8d9a78050..6e2631634f9 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala @@ -62,11 +62,14 @@ final class InteractiveSemanticdbs( source: AbsolutePath ): TextDocumentLookup = textDocument(source, unsavedContents = None) + def onClose(path: AbsolutePath): Unit = { + textDocumentCache.remove(path) + } + def textDocument( source: AbsolutePath, unsavedContents: Option[String], ): TextDocumentLookup = { - def doesNotBelongToBuildTarget = buildTargets.inverseSources(source).isEmpty def shouldTryCalculateInteractiveSemanticdb = { source.isLocalFileSystem(workspace) && ( diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala index 68276e7d2da..82d30f9bdac 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -1168,6 +1168,7 @@ class MetalsLspService( compilers.didClose(path) trees.didClose(path) diagnostics.onClose(path) + interactiveSemanticdbs.onClose(path) } override def didSave( diff --git a/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala index 258830eab23..2e0452f4beb 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala @@ -13,7 +13,6 @@ import scala.meta.Importee import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.metals.ResolvedSymbolOccurrence import scala.meta.internal.mtags.DefinitionAlternatives.GlobalSymbol -import scala.meta.internal.mtags.SemanticdbPath import scala.meta.internal.mtags.Semanticdbs import scala.meta.internal.mtags.Symbol import scala.meta.internal.parsing.TokenEditDistance @@ -56,7 +55,7 @@ final class ReferenceProvider( index.clear() } - override def onDelete(file: SemanticdbPath): Unit = { + override def onDelete(file: AbsolutePath): Unit = { index.remove(file.toNIO) } diff --git a/metals/src/main/scala/scala/meta/internal/metals/SemanticdbIndexer.scala b/metals/src/main/scala/scala/meta/internal/metals/SemanticdbIndexer.scala index ad825ef4a23..9cdf9551cb5 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/SemanticdbIndexer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/SemanticdbIndexer.scala @@ -17,7 +17,7 @@ import com.google.protobuf.InvalidProtocolBufferException trait SemanticdbFeatureProvider { def onChange(docs: TextDocuments, path: AbsolutePath): Unit - def onDelete(path: SemanticdbPath): Unit + def onDelete(path: AbsolutePath): Unit def reset(): Unit } @@ -40,7 +40,10 @@ class SemanticdbIndexer( } def onDelete(semanticdbFile: SemanticdbPath): Unit = { - providers.foreach(_.onDelete(semanticdbFile)) + SemanticdbClasspath.toScala(workspace, semanticdbFile).foreach { + sourceFile => + providers.foreach(_.onDelete(sourceFile)) + } } /** diff --git a/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala index 766764b8241..32a2f738506 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala @@ -32,7 +32,6 @@ import scala.meta.internal.metals.testProvider.frameworks.MunitTestFinder import scala.meta.internal.metals.testProvider.frameworks.ScalatestTestFinder import scala.meta.internal.mtags import scala.meta.internal.mtags.GlobalSymbolIndex -import scala.meta.internal.mtags.SemanticdbPath import scala.meta.internal.mtags.Semanticdbs import scala.meta.internal.parsing.Trees import scala.meta.internal.semanticdb @@ -105,7 +104,7 @@ final class TestSuitesProvider( case _ => () } - override def onDelete(file: SemanticdbPath): Unit = () + override def onDelete(file: AbsolutePath): Unit = () override def reset(): Unit = () def onFileDelete(file: AbsolutePath): Unit = {