From 73fde6a438c0a7868ca6f12800813f35e62aabf6 Mon Sep 17 00:00:00 2001 From: kasiaMarek Date: Wed, 18 Dec 2024 17:07:37 +0100 Subject: [PATCH] small fixes --- .../internal/metals/DefinitionProvider.scala | 19 ++++++++++++------- .../metals/FallbackDefinitionProvider.scala | 4 +++- .../internal/metals/MetalsLspService.scala | 1 - 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala index 4d28927c544..399696c03c8 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala @@ -8,7 +8,6 @@ import scala.util.Try import scala.meta.inputs.Input import scala.meta.inputs.Position.Range -import scala.meta.internal.metals.LoggerReportContext.unsanitized import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.mtags.GlobalSymbolIndex import scala.meta.internal.mtags.Mtags @@ -61,7 +60,6 @@ final class DefinitionProvider( scalaVersionSelector: ScalaVersionSelector, saveDefFileToDisk: Boolean, sourceMapper: SourceMapper, - warnings: () => Warnings, )(implicit ec: ExecutionContext, rc: ReportContext) { private val fallback = new FallbackDefinitionProvider(trees, index) @@ -132,7 +130,7 @@ final class DefinitionProvider( ) .getOrElse(fromCompiler) } - reportBuilder.build().foreach(unsanitized.create(_)) + reportBuilder.build().foreach(rc.unsanitized.create(_)) result } } @@ -592,12 +590,19 @@ class DefinitionProviderReportBuilder( |""".stripMargin, s"empty definition using pc, found symbol in pc: ${compilerDefn.querySymbol}", path = Some(path.toURI), - id = Some( - if (compilerDefn.querySymbol != "") compilerDefn.querySymbol - else - s"${path.toURI}:${params.getPosition().getLine()}:${params.getPosition().getCharacter()}" + id = querySymbol.orElse( + Some(s"${path.toURI}:${params.getPosition().getLine()}") ), error = error, ) } + + private def querySymbol: Option[String] = + compilerDefn.querySymbol match { + case "" => + semanticDBDefn + .map(_.querySymbol) + .orElse(fallbackDefn.map(_.querySymbol)) + case q => Some(q) + } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/FallbackDefinitionProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/FallbackDefinitionProvider.scala index ac6865885f2..ed08dabee00 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/FallbackDefinitionProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/FallbackDefinitionProvider.scala @@ -1,5 +1,7 @@ package scala.meta.internal.metals +import scala.util.control.NonFatal + import scala.meta.Term import scala.meta.Type import scala.meta._ @@ -175,7 +177,7 @@ class FallbackDefinitionProvider( defResult.flatten } catch { - case e: Exception => + case NonFatal(e) => reportBuilder.withError(e) None } diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala index 2c2502fdabe..62c0bf137ba 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -304,7 +304,6 @@ abstract class MetalsLspService( scalaVersionSelector, saveDefFileToDisk = !clientConfig.isVirtualDocumentSupported(), sourceMapper, - () => warnings, ) val stacktraceAnalyzer: StacktraceAnalyzer = new StacktraceAnalyzer(