Skip to content

Commit

Permalink
bugfix: Catch possible syntax errors
Browse files Browse the repository at this point in the history
Previously, if we tried to calculate semanticdb for a file with parsing errors we would have an exception thrown.

Now, we just return an empty TextDocument and not reprot that to the user as it will already be reproted as a diagnostic.
  • Loading branch information
tgodzik committed Aug 19, 2024
1 parent aafc7dd commit 275dc3f
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import scala.meta.internal.mtags.MtagsEnrichments._
import scala.meta.internal.semanticdb.scalac.SemanticdbConfig
import scala.meta.internal.{semanticdb => s}
import scala.meta.io.AbsolutePath
import scala.meta.parsers.ParseException
import scala.meta.tokenizers.TokenizeException

class SemanticdbTextDocumentProvider(
val compiler: MetalsGlobal,
Expand Down Expand Up @@ -51,7 +53,13 @@ class SemanticdbTextDocumentProvider(
}
// we recalculate md5, since there seems to be issue with newlines sometimes
val document =
unit.toTextDocument(explicitDialect).withMd5(MD5.compute(code))
try {
unit.toTextDocument(explicitDialect).withMd5(MD5.compute(code))
} catch {
case _: TokenizeException | _: ParseException =>
s.TextDocument.defaultInstance
}

compiler.workspace
.flatMap { workspacePath =>
scala.util.Try(workspacePath.relativize(filePath.toNIO)).toOption
Expand Down

0 comments on commit 275dc3f

Please sign in to comment.