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

Publish scalameta parser diagnostics for Scala 3 #2807

Merged
merged 1 commit into from May 20, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions tests/unit/src/main/scala/tests/BaseWorksheetLspSuite.scala
Expand Up @@ -442,9 +442,9 @@ abstract class BaseWorksheetLspSuite(scalaVersion: String)
|""".stripMargin,
Map(
V.scala3 ->
"""|a/src/main/scala/a/Main.worksheet.sc:1:8: error: expression expected but val found
|def y =
| ^
"""|a/src/main/scala/a/Main.worksheet.sc:2:1: error: illegal start of simple expression
|val x: Int = ""
|^^^
|a/src/main/scala/a/Main.worksheet.sc:2:14: error:
|Found: ("" : String)
|Required: Int
Expand Down