From 9c9a53b4a9ce4ae78ee52a9a26cd2170c012cc93 Mon Sep 17 00:00:00 2001 From: Karan Ahlawat Date: Fri, 20 Oct 2023 14:15:29 +0530 Subject: [PATCH 1/2] bugfix: fix SymbolNotFound regex This fixes the bug where the user has -explain scalac flag set and executing Code Actions on a missing symbol did not offer to import the symbol, due to extra text the regex previously failed to parse. --- .../scala/scala/meta/internal/metals/ScalacDiagnostic.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/ScalacDiagnostic.scala b/metals/src/main/scala/scala/meta/internal/metals/ScalacDiagnostic.scala index c0cd5350237..db35cda94db 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ScalacDiagnostic.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ScalacDiagnostic.scala @@ -28,10 +28,10 @@ object ScalacDiagnostic { } object SymbolNotFound { - private val regex = """(n|N)ot found: (value|type)?\s?(\w+)""".r + private val regex = """(n|N)ot found: (value|type)?\s?(\w+)(\s|\S)*""".r def unapply(d: l.Diagnostic): Option[String] = d.getMessage().trim() match { - case regex(_, _, name) => Some(name) + case regex(_, _, name, _) => Some(name) case _ => None } } From 75f291c2d5430f2ecf77fefffacde8f1a731cdd8 Mon Sep 17 00:00:00 2001 From: Karan Ahlawat Date: Fri, 20 Oct 2023 14:19:18 +0530 Subject: [PATCH 2/2] test: add test for updated SymbolNotFound regex with -explain flag --- .../ImportMissingSymbolLspSuite.scala | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/unit/src/test/scala/tests/codeactions/ImportMissingSymbolLspSuite.scala b/tests/unit/src/test/scala/tests/codeactions/ImportMissingSymbolLspSuite.scala index eda8c2ab217..91055b0f44f 100644 --- a/tests/unit/src/test/scala/tests/codeactions/ImportMissingSymbolLspSuite.scala +++ b/tests/unit/src/test/scala/tests/codeactions/ImportMissingSymbolLspSuite.scala @@ -261,4 +261,27 @@ class ImportMissingSymbolLspSuite |""".stripMargin, ) + check( + "scalac-explain-flag", + """|package a + | + |object A { + | val f = <>.successful(2) + |} + |""".stripMargin, + s"""|${ImportMissingSymbol.title("Future", "scala.concurrent")} + |${ImportMissingSymbol.title("Future", "java.util.concurrent")} + |${CreateNewSymbol.title("Future")} + |""".stripMargin, + """|package a + | + |import scala.concurrent.Future + | + |object A { + | val f = Future.successful(2) + |} + |""".stripMargin, + scalaVersion = "3.3.1", + scalacOptions = List("-explain"), + ) }