From 17b6df462061f68faac5c70e53f939c1584aa0ea Mon Sep 17 00:00:00 2001 From: rochala Date: Tue, 19 Mar 2024 12:11:25 +0100 Subject: [PATCH] Reformat --- build.sbt | 7 ++- .../meta/internal/metals/Compilers.scala | 5 +- .../telemetry/TelemetryReportContext.scala | 7 ++- .../scala/scala/meta/metals/ServerState.scala | 3 +- .../meta/internal/metals/TelemetryLevel.scala | 1 - .../meta/internal/telemetry/Environment.scala | 10 ++-- .../meta/internal/telemetry/Exception.scala | 37 ++++++++++----- .../telemetry/MetalsConfiguration.scala | 46 +++++++++---------- .../PresentationCompilerConfig.scala | 27 ++++++----- .../internal/telemetry/ReporterContext.scala | 18 ++++---- .../meta/internal/telemetry/Reports.scala | 25 +++++----- .../internal/telemetry/TelemetryService.scala | 18 +++++--- .../scala/tests/telemetry/SampleReports.scala | 9 +++- 13 files changed, 119 insertions(+), 94 deletions(-) diff --git a/build.sbt b/build.sbt index 5fc27348277..576c0207d5e 100644 --- a/build.sbt +++ b/build.sbt @@ -198,7 +198,7 @@ val sharedJavacOptions = List( Nil else Seq("--release", "8") - }, + } ) val sharedScalacOptions = List( @@ -267,8 +267,8 @@ lazy val telemetryInterfaces = project }, libraryDependencies := List( "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.27.7", - "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.27.7" % "compile-internal" - ) + "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.27.7" % "compile-internal", + ), ) lazy val mtagsShared = project @@ -642,7 +642,6 @@ lazy val testSettings: Seq[Def.Setting[_]] = List( publish / skip := true, fork := true, testFrameworks := List(TestFrameworks.MUnit), - Test / javaOptions += "-Dmetals.telemetry-level=off", Test / testOptions ++= { if (isCI) { // Enable verbose logging using sbt loggers in CI. diff --git a/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala b/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala index 4e93cad85b7..4cf650072fc 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala @@ -1139,7 +1139,7 @@ class Compilers( sourceMapper.pcMapping(path, scalaVersion) } - private def createTelemetryReporterContext( + private def createPresentationCompilerContext( scalaVersion: String, config: PresentationCompilerConfig, options: List[String], @@ -1192,7 +1192,7 @@ class Compilers( ): PresentationCompiler = { val config = getUserConfiguration() val remoteReportContext = remoteReporting(() => - createTelemetryReporterContext(pc.scalaVersion, config, options) + createPresentationCompilerContext(pc.scalaVersion, config, options) ) pc.withSearch(search) @@ -1245,6 +1245,7 @@ class Compilers( val filteredOptions = plugins.filterSupportedOptions(options) val allOptions = log ++ filteredOptions + configure(pc, search, allOptions) .newInstance( name, diff --git a/metals/src/main/scala/scala/meta/internal/telemetry/TelemetryReportContext.scala b/metals/src/main/scala/scala/meta/internal/telemetry/TelemetryReportContext.scala index 5e2a87318c7..1a88e50a6e6 100644 --- a/metals/src/main/scala/scala/meta/internal/telemetry/TelemetryReportContext.scala +++ b/metals/src/main/scala/scala/meta/internal/telemetry/TelemetryReportContext.scala @@ -51,7 +51,8 @@ class TelemetryReportContext( telemetryClientConfig: TelemetryClient.Config = TelemetryClient.Config.default, logger: LoggerAccess = LoggerAccess.system, -)(implicit ec: ExecutionContext) extends ReportContext { +)(implicit ec: ExecutionContext) + extends ReportContext { // Don't send reports with fragile user data - sources etc override lazy val unsanitized: Reporter = reporter("unsanitized") @@ -86,7 +87,9 @@ private class TelemetryReporter( override def getReports(): ju.List[TimestampedFile] = ju.Collections.emptyList() - override def cleanUpOldReports(maxReportsNumber: Int): ju.List[TimestampedFile] = + override def cleanUpOldReports( + maxReportsNumber: Int + ): ju.List[TimestampedFile] = ju.Collections.emptyList() override def deleteAll(): Unit = () diff --git a/metals/src/main/scala/scala/meta/metals/ServerState.scala b/metals/src/main/scala/scala/meta/metals/ServerState.scala index 85a73b11d7c..8f2605ff226 100644 --- a/metals/src/main/scala/scala/meta/metals/ServerState.scala +++ b/metals/src/main/scala/scala/meta/metals/ServerState.scala @@ -12,5 +12,6 @@ sealed trait ServerState object ServerState { case object Started extends ServerState final case class Initialized(service: WorkspaceLspService) extends ServerState - final case class ShuttingDown(service: WorkspaceLspService) extends ServerState + final case class ShuttingDown(service: WorkspaceLspService) + extends ServerState } diff --git a/mtags-shared/src/main/scala/scala/meta/internal/metals/TelemetryLevel.scala b/mtags-shared/src/main/scala/scala/meta/internal/metals/TelemetryLevel.scala index 2b94e3723b4..45f9ddea6db 100644 --- a/mtags-shared/src/main/scala/scala/meta/internal/metals/TelemetryLevel.scala +++ b/mtags-shared/src/main/scala/scala/meta/internal/metals/TelemetryLevel.scala @@ -38,4 +38,3 @@ object TelemetryLevel { } } } - diff --git a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Environment.scala b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Environment.scala index d40ae39d38a..a80ecaa0978 100644 --- a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Environment.scala +++ b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Environment.scala @@ -1,21 +1,19 @@ package scala.meta.internal.telemetry - - case class Environment(java: JavaInfo, system: SystemInfo) object Environment { val java: JavaInfo = JavaInfo( System.getProperty("java.version", "unknown"), - System.getProperty("java.vendor", "unknown") + System.getProperty("java.vendor", "unknown"), ) val system: SystemInfo = SystemInfo( - System.getProperty("os.arch", "unknown"), + System.getProperty("os.arch", "unknown"), System.getProperty("os.name", "unknown"), - System.getProperty("os.version", "unknown") + System.getProperty("os.version", "unknown"), ) val instance: Environment = Environment(java, system) } case class JavaInfo(version: String, distribution: String) -case class SystemInfo(architecture: String, name: String, version: String) \ No newline at end of file +case class SystemInfo(architecture: String, name: String, version: String) diff --git a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Exception.scala b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Exception.scala index a1d0fd9319e..3afa1006d41 100644 --- a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Exception.scala +++ b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Exception.scala @@ -1,20 +1,35 @@ package scala.meta.internal.telemetry +case class ExceptionSummary( + exception: String, + stacktrace: List[StackTraceElement], +) -case class ExceptionSummary(exception: String, stacktrace: List[StackTraceElement]) - -case class StackTraceElement(fullyQualifiedName: String, methodName: String, errorFile: String, errorLine: Int) +case class StackTraceElement( + fullyQualifiedName: String, + methodName: String, + errorFile: String, + errorLine: Int, +) object ExceptionSummary { def from(e: Throwable, sanitize: String => String): ExceptionSummary = { - val stackTraceElements = e.getStackTrace().toList.flatMap(element => { - for { - className <- Option(element.getClassName) - methodName <- Option(element.getMethodName) - errorLine <- Option(element.getLineNumber) - errorFile <- Option(element.getFileName) - } yield StackTraceElement(sanitize(className), sanitize(methodName), sanitize(errorFile), errorLine) - }) + val stackTraceElements = e + .getStackTrace() + .toList + .flatMap(element => { + for { + className <- Option(element.getClassName) + methodName <- Option(element.getMethodName) + errorLine <- Option(element.getLineNumber) + errorFile <- Option(element.getFileName) + } yield StackTraceElement( + sanitize(className), + sanitize(methodName), + sanitize(errorFile), + errorLine, + ) + }) ExceptionSummary(sanitize(e.getMessage), stackTraceElements) } diff --git a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/MetalsConfiguration.scala b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/MetalsConfiguration.scala index 446387eebb3..5b0034fcbe9 100644 --- a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/MetalsConfiguration.scala +++ b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/MetalsConfiguration.scala @@ -1,31 +1,29 @@ package scala.meta.internal.telemetry - case class MetalsUserConfiguration( - symbolPrefixes: Map[String, String], - bloopSbtAlreadyInstalled: Boolean, - bloopVersion: Option[String], - bloopJvmProperties: List[String], - ammoniteJvmProperties: List[String], - superMethodLensesEnabled: Boolean, - showInferredType: Option[String], - showImplicitArguments: Boolean, - showImplicitConversionsAndClasses: Boolean, - enableStripMarginOnTypeFormatting: Boolean, - enableIndentOnPaste: Boolean, - enableSemanticHighlighting: Boolean, - excludedPackages: List[String], - fallbackScalaVersion: Option[String], - testUserInterface: String + symbolPrefixes: Map[String, String], + bloopSbtAlreadyInstalled: Boolean, + bloopVersion: Option[String], + bloopJvmProperties: List[String], + ammoniteJvmProperties: List[String], + superMethodLensesEnabled: Boolean, + showInferredType: Option[String], + showImplicitArguments: Boolean, + showImplicitConversionsAndClasses: Boolean, + enableStripMarginOnTypeFormatting: Boolean, + enableIndentOnPaste: Boolean, + enableSemanticHighlighting: Boolean, + excludedPackages: List[String], + fallbackScalaVersion: Option[String], + testUserInterface: String, ) case class MetalsServerConfiguration( - executeClientCommand: String, - snippetAutoIndent: Boolean, - isHttpEnabled: Boolean, - isInputBoxEnabled: Boolean, - askToReconnect: Boolean, - allowMultilineStringFormatting: Boolean, - compilers: PresentationCompilerConfig + executeClientCommand: String, + snippetAutoIndent: Boolean, + isHttpEnabled: Boolean, + isInputBoxEnabled: Boolean, + askToReconnect: Boolean, + allowMultilineStringFormatting: Boolean, + compilers: PresentationCompilerConfig, ) - diff --git a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/PresentationCompilerConfig.scala b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/PresentationCompilerConfig.scala index 4900fed86d0..671358d13d8 100644 --- a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/PresentationCompilerConfig.scala +++ b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/PresentationCompilerConfig.scala @@ -1,18 +1,17 @@ package scala.meta.internal.telemetry - case class PresentationCompilerConfig( - symbolPrefixes: Map[String, String], - completionCommand: Option[String], - parameterHintsCommand: Option[String], - overrideDefFormat: String, - isDefaultSymbolPrefixes: Boolean, - isCompletionItemDetailEnabled: Boolean, - isStripMarginOnTypeFormattingEnabled: Boolean, - isCompletionItemDocumentationEnabled: Boolean, - isHoverDocumentationEnabled: Boolean, - snippetAutoIndent: Boolean, - isSignatureHelpDocumentationEnabled: Boolean, - isCompletionSnippetsEnabled: Boolean, - semanticdbCompilerOptions: List[String] + symbolPrefixes: Map[String, String], + completionCommand: Option[String], + parameterHintsCommand: Option[String], + overrideDefFormat: String, + isDefaultSymbolPrefixes: Boolean, + isCompletionItemDetailEnabled: Boolean, + isStripMarginOnTypeFormattingEnabled: Boolean, + isCompletionItemDocumentationEnabled: Boolean, + isHoverDocumentationEnabled: Boolean, + snippetAutoIndent: Boolean, + isSignatureHelpDocumentationEnabled: Boolean, + isCompletionSnippetsEnabled: Boolean, + semanticdbCompilerOptions: List[String], ) diff --git a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/ReporterContext.scala b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/ReporterContext.scala index b0d5d1dbb04..1ba8d388fca 100644 --- a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/ReporterContext.scala +++ b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/ReporterContext.scala @@ -2,18 +2,18 @@ package scala.meta.internal.telemetry sealed trait ReporterContext case class ScalaPresentationCompilerContext( - scalaVersion: String, - options: List[String], - config: PresentationCompilerConfig + scalaVersion: String, + options: List[String], + config: PresentationCompilerConfig, ) extends ReporterContext case class MetalsLspContext( - metalsVersion: String, - userConfig: MetalsUserConfiguration, - serverConfig: MetalsServerConfiguration, - clientInfo: MetalsClientInfo, - buildServerConnections: List[BuildServerConnection] + metalsVersion: String, + userConfig: MetalsUserConfiguration, + serverConfig: MetalsServerConfiguration, + clientInfo: MetalsClientInfo, + buildServerConnections: List[BuildServerConnection], ) extends ReporterContext case class MetalsClientInfo(name: Option[String], version: Option[String]) -case class BuildServerConnection(name: String, version: String, isMain: Boolean) \ No newline at end of file +case class BuildServerConnection(name: String, version: String, isMain: Boolean) diff --git a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Reports.scala b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Reports.scala index c53b66a48aa..459e3446bb0 100644 --- a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Reports.scala +++ b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/Reports.scala @@ -4,11 +4,11 @@ import com.github.plokhotnyuk.jsoniter_scala.core._ import com.github.plokhotnyuk.jsoniter_scala.macros._ case class CrashReport( - error: ExceptionSummary, - componentName: String, - env: Environment = Environment.instance, - componentVersion: Option[String] = None, - reporterContext: Option[ReporterContext] = None + error: ExceptionSummary, + componentName: String, + env: Environment = Environment.instance, + componentVersion: Option[String] = None, + reporterContext: Option[ReporterContext] = None, ) object CrashReport { @@ -16,16 +16,15 @@ object CrashReport { } case class ErrorReport( - name: String, - reporterName: String, - reporterContext: ReporterContext, - env: Environment = Environment.instance, - id: Option[String] = None, - text: Option[String] = None, - error: Option[ExceptionSummary] = None, + name: String, + reporterName: String, + reporterContext: ReporterContext, + env: Environment = Environment.instance, + id: Option[String] = None, + text: Option[String] = None, + error: Option[ExceptionSummary] = None, ) object ErrorReport { implicit val codec: JsonValueCodec[ErrorReport] = JsonCodecMaker.make } - diff --git a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/TelemetryService.scala b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/TelemetryService.scala index 87621928321..c6434f0b043 100644 --- a/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/TelemetryService.scala +++ b/telemetry-interfaces/src/main/scala/scala/meta/internal/telemetry/TelemetryService.scala @@ -3,21 +3,27 @@ package scala.meta.internal.telemetry import com.github.plokhotnyuk.jsoniter_scala.core._ import scala.util.Try -class FireAndForgetEndpoint[In: JsonValueCodec](val method: String, val uri: String) { +class FireAndForgetEndpoint[In: JsonValueCodec]( + val method: String, + val uri: String, +) { def encodeInput(request: In): String = writeToString(request) def decodeInput(request: String): Try[In] = Try { readFromString(request) } } // This will be migrated to tapir endpoints in the next Commit object TelemetryService { - val sendErrorReportEndpoint = new FireAndForgetEndpoint[ErrorReport]("POST", "/v1/telemetry/sendErrorReport") - val sendCrashReportEndpoint = new FireAndForgetEndpoint[CrashReport]("POST", "/v1/telemetry/sendCrashReport") + val sendErrorReportEndpoint = new FireAndForgetEndpoint[ErrorReport]( + "POST", + "/v1/telemetry/sendErrorReport", + ) + val sendCrashReportEndpoint = new FireAndForgetEndpoint[CrashReport]( + "POST", + "/v1/telemetry/sendCrashReport", + ) } trait TelemetryService { def sendErrorReport(errorReport: ErrorReport): Unit def sendCrashReport(crashReport: CrashReport): Unit } - - - diff --git a/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala b/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala index ee2b27dd8c2..ede10dc9966 100644 --- a/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala +++ b/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala @@ -21,7 +21,14 @@ object SampleReports { error = Some( telemetry.ExceptionSummary( "ExceptionType", - List(telemetry.StackTraceElement("fullyQualifiedName", "methodName", "fileName", 0)), + List( + telemetry.StackTraceElement( + "fullyQualifiedName", + "methodName", + "fileName", + 0, + ) + ), ) ), reporterName = "reporterName",