Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Don't read file for InteractiveSemanticdbdb if it doesn't exist #5749

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import scala.util.Success
import scala.util.Try

import scala.meta.internal.builds.SbtBuildTool
import scala.meta.internal.io.FileIO
import scala.meta.internal.metals.Messages._
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.clients.language.MetalsLanguageClient
Expand Down Expand Up @@ -42,6 +41,7 @@ final class InteractiveSemanticdbs(
clientConfig: ClientConfiguration,
semanticdbIndexer: () => SemanticdbIndexer,
javaInteractiveSemanticdb: Option[JavaInteractiveSemanticdb],
buffers: Buffers,
) extends Cancelable
with Semanticdbs {

Expand Down Expand Up @@ -87,18 +87,25 @@ final class InteractiveSemanticdbs(
val result = textDocumentCache.compute(
source,
(path, existingDoc) => {
val text = unsavedContents.getOrElse(FileIO.slurp(source, charset))
val sha = MD5.compute(text)
if (existingDoc == null || existingDoc.md5 != sha) {
Try(compile(path, text)) match {
case Success(doc) if doc != null =>
if (!source.isDependencySource(workspace))
semanticdbIndexer().onChange(source, doc)
doc
case _ => null
}
} else
existingDoc
unsavedContents.orElse(buffers.get(source).orElse {
if (source.exists) Some(source.readText(charset))
else None
}) match {
case None => null
case Some(text) =>
val sha = MD5.compute(text)
if (existingDoc == null || existingDoc.md5 != sha) {
Try(compile(path, text)) match {
case Success(doc) if doc != null =>
if (!source.isDependencySource(workspace))
semanticdbIndexer().onChange(source, doc)
doc
case _ => null
}
} else
existingDoc
}

},
)
TextDocumentLookup.fromOption(source, Option(result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class MetalsLspService(
clientConfig,
() => semanticDBIndexer,
javaInteractiveSemanticdb,
buffers,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.meta.internal.mtags

import java.net.URI
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
Expand Down Expand Up @@ -285,8 +286,12 @@ trait ScalametaCommonEnrichments extends CommonMtagsEnrichments {
}
}

def readText(charset: Charset): String = {
FileIO.slurp(path, charset)
}

def readText: String = {
FileIO.slurp(path, StandardCharsets.UTF_8)
readText(StandardCharsets.UTF_8)
}

def readTextOpt: Option[String] = {
Expand Down
Loading