Skip to content

Commit

Permalink
Do not publish Scala 3 parsing errors
Browse files Browse the repository at this point in the history
Let's unify the parsing errors are presented to the user, the Scalameta parser is much better now and it should make it a bit faster.

Also, this would cause issues in sbt files if the build was not imported and the fallback version set to Scala 3.0.0.
  • Loading branch information
tgodzik committed May 19, 2021
1 parent faa73cf commit 8f17ea1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
Expand Up @@ -268,10 +268,7 @@ class MetalsLanguageServer(
def parseTreesAndPublishDiags(paths: Seq[AbsolutePath]): Future[Seq[Unit]] = {
Future.traverse(paths.distinct) { path =>
if (path.isScalaFilename) {
// diagnostics from the compiler are still needed for Scala 3
compilers.didChange(path).map { diags =>
diagnostics.onSyntaxError(path, diags ++ trees.didChange(path))
}
Future(diagnostics.onSyntaxError(path, trees.didChange(path)))
} else {
Future.successful(())
}
Expand Down
11 changes: 3 additions & 8 deletions metals/src/main/scala/scala/meta/internal/parsing/Trees.scala
Expand Up @@ -75,17 +75,14 @@ final class Trees(
}

/**
* Parse file at the given path and return a list of errors if there are any and
* the file belongs to a Scala 2 target.
*
* Parse file at the given path and return a list of errors if there are any.
* @param path file to parse
* @return list of errors if the file failed to parse
*/
def didChange(path: AbsolutePath): List[Diagnostic] = {
val dialect = getDialect(path)
parse(path, dialect) match {
// only publish parser diagnostics for Scala 2, which does not support significant indentation
case Some(parsed) if !dialect.allowSignificantIndentation =>
case Some(parsed) =>
parsed match {
case Parsed.Error(pos, message, _) =>
List(
Expand All @@ -100,9 +97,7 @@ final class Trees(
trees(path) = tree
List()
}
// don't publish diagnostics
case _ =>
List()
case _ => List()
}
}

Expand Down
Expand Up @@ -395,16 +395,8 @@ case class ScalaPresentationCompiler(

override def didChange(
params: VirtualFileParams
): CompletableFuture[ju.List[Diagnostic]] = {
compilerAccess.withNonInterruptableCompiler(
Nil.asJava,
params.token
) { access =>
val driver = access.compiler()
val uri = params.uri
CompilerInterfaces.parseErrors(driver, uri, params.text)
}
}
): CompletableFuture[ju.List[Diagnostic]] =
CompletableFuture.completedFuture(Nil.asJava)

override def didClose(uri: URI): Unit = {
compilerAccess.withNonInterruptableCompiler(
Expand Down

0 comments on commit 8f17ea1

Please sign in to comment.