From 31e04d5ad5d3017465d239ca5161e09e8601d27f Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 3 Jun 2022 14:09:36 +0200 Subject: [PATCH] refactor: Migrate Metals server to Scala 3 This mostly involved: - changing imports - moving things between MtagsEnrichements variants - adding () - fixing bugs reported now as warning or errors (things previously not reported at all) --- .scalafix.conf | 10 +- .scalafix2.conf | 19 ++ .scalafix3.conf | 13 -- .scalafmt.conf | 3 +- build.sbt | 110 +++++++---- .../src/main/scala/bench/MetalsBench.scala | 43 ----- .../internal/bsp/BspConfigGenerator.scala | 4 +- .../meta/internal/bsp/BspConnector.scala | 6 +- .../meta/internal/builds/BloopInstall.scala | 2 +- .../internal/builds/BuildToolSelector.scala | 4 +- .../meta/internal/builds/BuildTools.scala | 2 +- .../scala/meta/internal/builds/Digest.scala | 5 +- .../meta/internal/builds/GradleDigest.scala | 2 +- .../meta/internal/builds/MavenBuildTool.scala | 2 +- .../meta/internal/builds/MavenDigest.scala | 2 +- .../meta/internal/builds/MillDigest.scala | 1 + .../internal/builds/NewProjectProvider.scala | 2 +- .../meta/internal/builds/SbtBuildTool.scala | 4 +- .../meta/internal/builds/SbtDigest.scala | 2 +- .../meta/internal/builds/ShellRunner.scala | 2 +- .../internal/builds/WorkspaceReload.scala | 2 +- .../decorations/SemanticdbTreePrinter.scala | 6 +- .../SyntheticsDecorationProvider.scala | 6 +- .../ImplementationProvider.scala | 6 +- .../implementation/Supermethods.scala | 2 +- .../meta/internal/metals/ActiveFiles.scala | 2 +- .../meta/internal/metals/AdjustLspData.scala | 5 +- .../internal/metals/BatchedFunction.scala | 2 +- .../meta/internal/metals/BloopServers.scala | 22 ++- .../scala/meta/internal/metals/Buffers.scala | 2 +- .../metals/BuildServerConnection.scala | 2 +- .../internal/metals/BuildTargetInfo.scala | 5 +- .../meta/internal/metals/BuildTargets.scala | 2 +- .../internal/metals/CancelableFuture.scala | 2 +- .../scala/meta/internal/metals/Command.scala | 2 +- .../meta/internal/metals/Compilations.scala | 5 +- .../internal/metals/CompilerPlugins.scala | 2 +- .../meta/internal/metals/Compilers.scala | 8 +- .../internal/metals/DefinitionProvider.scala | 6 +- .../meta/internal/metals/Diagnostics.scala | 4 +- .../scala/meta/internal/metals/Embedded.scala | 2 +- .../internal/metals/FileDecoderProvider.scala | 3 +- .../metals/FileSystemSemanticdbs.scala | 2 +- .../meta/internal/metals/Fingerprints.scala | 1 - .../internal/metals/FormattingProvider.scala | 4 +- .../metals/ForwardingMetalsBuildClient.scala | 6 +- .../meta/internal/metals/ImportedBuild.scala | 2 +- .../scala/meta/internal/metals/Indexer.scala | 4 +- .../metals/InitializationOptions.scala | 2 +- .../metals/InteractiveSemanticdbs.scala | 4 +- .../meta/internal/metals/JarTopLevels.scala | 2 +- .../metals/JavaFormattingProvider.scala | 5 +- .../metals/JavaInteractiveSemanticdb.scala | 2 +- .../meta/internal/metals/JavaTarget.scala | 2 +- .../internal/metals/MetalsEnrichments.scala | 16 +- .../internal/metals/MetalsHttpServer.scala | 2 +- .../internal/metals/MetalsLspService.scala | 48 ++--- .../internal/metals/MetalsServerInputs.scala | 7 - .../internal/metals/MetalsSymbolSearch.scala | 2 +- .../meta/internal/metals/MtagsResolver.scala | 1 - .../internal/metals/PackageProvider.scala | 18 +- .../internal/metals/PopupChoiceReset.scala | 2 +- .../internal/metals/ReferenceProvider.scala | 4 +- .../meta/internal/metals/ScalaTarget.scala | 2 +- .../metals/ScalaVersionSelector.scala | 2 +- .../internal/metals/ScalafixProvider.scala | 2 +- .../internal/metals/SemanticdbIndexer.scala | 8 +- .../meta/internal/metals/ServerCommands.scala | 3 +- .../meta/internal/metals/SourceMapper.scala | 2 +- .../internal/metals/StacktraceAnalyzer.scala | 2 +- .../metals/StandaloneSymbolSearch.scala | 2 +- .../meta/internal/metals/StatusBar.scala | 6 +- .../scala/meta/internal/metals/Tables.scala | 2 +- .../meta/internal/metals/TargetData.scala | 2 +- .../scala/meta/internal/metals/Warnings.scala | 2 +- .../metals/WorksheetDependencySources.scala | 2 +- .../metals/WorkspaceChoicePopup.scala | 4 +- .../internal/metals/WorkspaceLspService.scala | 18 +- .../metals/WorkspaceSearchVisitor.scala | 2 +- .../internal/metals/ammonite/Ammonite.scala | 2 +- .../callHierarchy/CallHierarchyHelpers.scala | 1 + .../CallHierarchyItemBuilder.scala | 1 + .../callHierarchy/OutgoingCallsFinder.scala | 3 +- .../language/ConfiguredLanguageClient.scala | 25 +-- .../clients/language/MetalsHttpClient.scala | 4 +- .../metals/codeactions/CodeAction.scala | 4 +- .../codeactions/CodeActionProvider.scala | 1 - .../codeactions/ConvertToNamedArguments.scala | 8 +- .../CreateCompanionObjectCodeAction.scala | 4 +- .../metals/codeactions/CreateNewSymbol.scala | 4 +- .../codeactions/ExtractRenameMember.scala | 4 +- .../codeactions/ExtractValueCodeAction.scala | 5 +- .../FlatMapToForComprehensionCodeAction.scala | 3 +- .../ImplementAbstractMembers.scala | 4 +- .../codeactions/ImportMissingSymbol.scala | 3 +- .../codeactions/InlineValueCodeAction.scala | 1 - .../codeactions/InsertInferredType.scala | 4 +- .../MillifyDependencyCodeAction.scala | 2 +- .../MillifyScalaCliDependencyCodeAction.scala | 2 +- .../metals/codeactions/OrganizeImports.scala | 4 +- .../codeactions/PatternMatchRefactor.scala | 4 +- .../RewriteBracesParensCodeAction.scala | 6 +- .../metals/codeactions/StringActions.scala | 7 +- .../metals/codelenses/RunTestCodeLens.scala | 5 +- .../codelenses/SuperMethodCodeLens.scala | 6 +- .../metals/codelenses/WorksheetCodeLens.scala | 4 +- .../metals/debug/BuildTargetClasses.scala | 2 +- .../debug/BuildTargetClassesFinder.scala | 2 +- .../debug/ClientConfigurationAdapter.scala | 2 +- .../internal/metals/debug/DebugProtocol.scala | 2 +- .../internal/metals/debug/DebugProvider.scala | 6 +- .../internal/metals/debug/DebugProxy.scala | 5 +- .../metals/debug/DotEnvFileParser.scala | 2 +- .../metals/debug/EndpointLogger.scala | 4 +- .../metals/debug/SourcePathAdapter.scala | 2 +- .../meta/internal/metals/doctor/Doctor.scala | 8 +- .../internal/metals/doctor/HeadDoctor.scala | 5 +- .../metals/doctor/ProblemResolver.scala | 2 +- .../findfiles/FindTextInDependencyJars.scala | 2 +- .../metals/formatting/IndentOnPaste.scala | 2 +- .../formatting/OnTypeFormattingProvider.scala | 2 +- .../formatting/RangeFormattingProvider.scala | 2 +- .../metals/newScalaFile/NewFileProvider.scala | 7 +- .../testProvider/BuildTargetUpdate.scala | 2 +- .../metals/testProvider/TestSuitesIndex.scala | 2 +- .../testProvider/TestSuitesProvider.scala | 4 +- .../frameworks/JunitTestFinder.scala | 2 +- .../frameworks/MunitTestFinder.scala | 2 +- .../frameworks/ScalatestTestFinder.scala | 11 +- .../internal/metals/watcher/FileWatcher.scala | 2 +- .../meta/internal/parsing/ClassFinder.scala | 4 +- .../parsing/DocumentSymbolProvider.scala | 2 +- .../parsing/FoldingRangeExtractor.scala | 8 +- .../parsing/FoldingRangeProvider.scala | 2 +- .../parsing/JavaFoldingRangeExtractor.scala | 2 +- .../internal/parsing/TokenEditDistance.scala | 2 +- .../meta/internal/parsing/TokenOps.scala | 1 + .../scala/meta/internal/parsing/Trees.scala | 2 +- .../remotels/RemoteLanguageServer.scala | 2 +- .../meta/internal/rename/RenameProvider.scala | 14 +- .../meta/internal/tvp/ClasspathSymbols.scala | 2 +- .../meta/internal/tvp/ClasspathTreeView.scala | 2 +- .../internal/tvp/MetalsTreeViewProvider.scala | 4 +- .../meta/internal/tvp/ScalacpCopyPaste.scala | 2 +- .../DecorationWorksheetPublisher.scala | 2 +- .../internal/worksheets/MdocEnrichments.scala | 1 - .../worksheets/WorksheetProvider.scala | 2 +- .../WorkspaceEditWorksheetPublisher.scala | 2 +- .../scala/meta/internal/pc/JavaHover.scala | 2 +- .../internal/mtags/MtagsEnrichments.scala | 172 ------------------ .../scala/meta/internal/pc/Keywords.scala | 1 - .../internal/mtags/MtagsEnrichments.scala | 3 +- .../meta/internal/metals/BloomFilters.scala | 0 .../meta/internal/metals/PositionSyntax.scala | 6 +- .../internal/metals/URIEncoderDecoder.scala | 2 +- .../mtags/ScalametaCommonEnrichments.scala | 163 +++++++++++++++++ .../scala/meta/internal/pc/LogMessages.scala | 0 project/JavaPcSettings.scala | 2 +- .../scala/tests/BaseExtractMethodSuite.scala | 1 - .../tests/feature/RenameCrossLspSuite.scala | 108 ++++++++--- .../SemanticTokensScala3ExpectSuite.scala | 12 +- .../feature/WorksheetCrossLspSuite.scala | 65 ++++++- .../test/scala/tests/sbt/SbtServerSuite.scala | 4 +- tests/unit/src/main/scala/bill/Bill.scala | 85 ++++----- .../meta/internal/metals/debug/Debugger.scala | 3 - .../tests/BaseAnalyzeStacktraceSuite.scala | 2 +- .../src/main/scala/tests/BaseLspSuite.scala | 5 +- .../main/scala/tests/BaseRenameLspSuite.scala | 13 +- .../scala/tests/BaseWorksheetLspSuite.scala | 8 +- .../scala/tests/BuildServerInitializer.scala | 4 - tests/unit/src/main/scala/tests/Library.scala | 5 +- .../src/main/scala/tests/QuickBuild.scala | 4 +- .../src/main/scala/tests/TestingClient.scala | 10 +- .../src/main/scala/tests/TestingServer.scala | 2 +- .../tests/WorkspaceSymbolReferences.scala | 2 + .../codeactions/BaseCodeActionLspSuite.scala | 2 +- .../tests/debug/BaseStackFrameDapSuite.scala | 19 +- .../scala/tests/BuildTargetsLspSuite.scala | 2 +- .../test/scala/tests/CascadeLspSuite.scala | 9 +- .../test/scala/tests/CompletionLspSuite.scala | 2 +- .../scala/tests/DebugDiscoverySuite.scala | 2 +- .../test/scala/tests/DidFocusLspSuite.scala | 10 +- .../tests/FindTextInDependencyJarsSuite.scala | 10 +- .../src/test/scala/tests/HoverLspSuite.scala | 2 +- .../test/scala/tests/JavaToplevelSuite.scala | 2 +- .../test/scala/tests/NewFileLspSuite.scala | 2 +- .../src/test/scala/tests/RenameLspSuite.scala | 108 +++++------ .../tests/SemanticTokensExpectSuite.scala | 7 +- .../scala/tests/SuperMethodLspSuite.scala | 14 +- .../test/scala/tests/TreeViewLspSuite.scala | 126 ++++++------- .../test/scala/tests/WarningsLspSuite.scala | 35 ++-- .../scala/tests/WorkspaceFoldersSuite.scala | 4 +- .../classFinder/ClassBreakpointSuite.scala | 2 +- .../classFinder/FindAllClassesSuite.scala | 6 +- .../classFinder/TastyNameResolverSuite.scala | 2 +- .../ConvertPatternMatchLspSuite.scala | 2 +- .../ConvertToNamedArgumentsLspSuite.scala | 2 +- .../ExtractRenameMemberLspSuite.scala | 2 +- .../codeactions/ExtractValueLspSuite.scala | 4 +- .../FlatMapToForComprehensionSuite.scala | 1 + .../InsertInferredTypeLspSuite.scala | 2 +- .../tests/debug/CompletionDapSuite.scala | 32 +--- .../formatting/OnTypeFormattingSuite.scala | 2 +- ...tringRangeFormattingWhenPastingSuite.scala | 2 +- ...ingRangeFormattingWhenSelectingSuite.scala | 2 +- .../scalafix/ScalafixProviderLspSuite.scala | 3 +- .../TestSuitesProviderSuite.scala | 2 +- .../tests/worksheets/WorksheetLspSuite.scala | 81 ++------- .../WorksheetNoDecorationsLspSuite.scala | 12 +- 209 files changed, 994 insertions(+), 997 deletions(-) create mode 100644 .scalafix2.conf delete mode 100644 .scalafix3.conf rename mtags/src/main/{scala-2 => scala}/scala/meta/internal/metals/BloomFilters.scala (100%) rename mtags/src/main/{scala-2 => scala}/scala/meta/internal/metals/PositionSyntax.scala (93%) rename mtags/src/main/{scala-2 => scala}/scala/meta/internal/metals/URIEncoderDecoder.scala (95%) rename mtags/src/main/{scala-2 => scala}/scala/meta/internal/pc/LogMessages.scala (100%) diff --git a/.scalafix.conf b/.scalafix.conf index 2c0c7153f08..632539e2234 100644 --- a/.scalafix.conf +++ b/.scalafix.conf @@ -1,16 +1,10 @@ rules = [ - OrganizeImports, - ExplicitResultTypes, - RemoveUnused + OrganizeImports ] -ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false - -RemoveUnused.imports = false - OrganizeImports.groupedImports = Explode OrganizeImports.expandRelative = true -OrganizeImports.removeUnused = true +OrganizeImports.removeUnused = false OrganizeImports.groups = [ "re:javax?\\." "scala." diff --git a/.scalafix2.conf b/.scalafix2.conf new file mode 100644 index 00000000000..2c0c7153f08 --- /dev/null +++ b/.scalafix2.conf @@ -0,0 +1,19 @@ +rules = [ + OrganizeImports, + ExplicitResultTypes, + RemoveUnused +] + +ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false + +RemoveUnused.imports = false + +OrganizeImports.groupedImports = Explode +OrganizeImports.expandRelative = true +OrganizeImports.removeUnused = true +OrganizeImports.groups = [ + "re:javax?\\." + "scala." + "scala.meta." + "*" +] diff --git a/.scalafix3.conf b/.scalafix3.conf deleted file mode 100644 index 632539e2234..00000000000 --- a/.scalafix3.conf +++ /dev/null @@ -1,13 +0,0 @@ -rules = [ - OrganizeImports -] - -OrganizeImports.groupedImports = Explode -OrganizeImports.expandRelative = true -OrganizeImports.removeUnused = false -OrganizeImports.groups = [ - "re:javax?\\." - "scala." - "scala.meta." - "*" -] diff --git a/.scalafmt.conf b/.scalafmt.conf index 3766c685b0d..e82e92c7254 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,5 +1,5 @@ version = "3.7.12" -runner.dialect = scala213 +runner.dialect = scala3 project.git = true align.preset = none align.stripMargin = true @@ -34,5 +34,6 @@ fileOverride { }, "glob:**/mtags*/**" { trailingCommas = never + runner.dialect = scala213 } } diff --git a/build.sbt b/build.sbt index abb29ad6d27..d8679a447ed 100644 --- a/build.sbt +++ b/build.sbt @@ -44,7 +44,7 @@ def crossSetting[A]( logo := Welcome.logo usefulTasks := Welcome.tasks -ThisBuild / scalafixScalaBinaryVersion := scalaBinaryVersion.value +ThisBuild / scalafixScalaBinaryVersion := "2.13" inThisBuild( List( @@ -52,8 +52,8 @@ inThisBuild( if (isCI) dynVer else localSnapshotVersion // only for local publishing }, - scalaVersion := V.scala213, - crossScalaVersions := List(V.scala213), + scalaVersion := V.scala3, + crossScalaVersions := List(V.scala3), organization := "org.scalameta", licenses := Seq( "Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0") @@ -137,7 +137,7 @@ commands ++= Seq( runMtagsPublishLocal(st, v, localSnapshotVersion) } "interfaces/publishLocal" :: - s"++${V.scala213} metals/publishLocal" :: + s"++${V.scala3} metals/publishLocal" :: "mtags-java/publishLocal" :: publishMtags }, @@ -220,6 +220,27 @@ val sharedSettings = sharedJavacOptions ++ sharedScalacOptions ++ List( ) ), ), + excludeDependencies ++= crossSetting( + scalaVersion.value, + if3 = { + // Exclude cross published version dependencies leading to conflicts in Scala 3 vs 2.13 + // When using Scala 3 exclude Scala 2.13 standard native libraries, + // when using Scala 2.13 exclude Scala 3 standard native libraries + // Use full name, Maven style published artifacts cannot use artifact/cross version for exclusion rules + List( + ExclusionRule() + .withOrganization("org.scala-lang.modules") + .withName( + "scala-collection-compat_2.13" + ), + ExclusionRule() + .withOrganization("org.scala-lang.modules") + .withName( + "scala-xml_2.13" + ), + ) + }, + ), scalacOptions ++= lintingOptions(scalaVersion.value), ) @@ -282,21 +303,19 @@ def multiScalaDirectories(root: File, scalaVersion: String) = { result.toList } -def scala3ScalametaDependency = - ("org.scalameta" %% "scalameta" % V.scalameta) - .cross(CrossVersion.for3Use2_13) - .exclude("org.scala-lang", "scala-reflect") - .exclude("org.scala-lang", "scala-compiler") - // the correct one should be brought in by the scala 3 compiler - .exclude("org.scala-lang", "scala-library") - .exclude( - "com.lihaoyi", - "geny_2.13", - ) // avoid 2.13 and 3 on the classpath since we rely on it directly - .exclude( - "com.lihaoyi", - "sourcecode_2.13", - ) // avoid 2.13 and 3 on the classpath since it comes in via pprint +def scalametaDependency = ("org.scalameta" %% "scalameta" % V.scalameta) + .cross(CrossVersion.for3Use2_13) + .exclude("org.scala-lang", "scala-reflect") + .exclude("org.scala-lang", "scala-compiler") + .exclude("org.scala-lang.modules", "scala-collection-compat") + .exclude( + "com.lihaoyi", + "geny_2.13", + ) // avoid 2.13 and 3 on the classpath since we rely on it directly + .exclude( + "com.lihaoyi", + "sourcecode_2.13", + ) val mtagsSettings = List( crossScalaVersions := V.supportedScalaVersions ++ V.nightlyScala3Versions, @@ -327,7 +346,7 @@ val mtagsSettings = List( ), if3 = List( "org.scala-lang" %% "scala3-compiler" % scalaVersion.value, - scala3ScalametaDependency, + scalametaDependency, ), if3WithPresentationCompiler = List( "org.scala-lang" %% "scala3-presentation-compiler" % scalaVersion.value @@ -360,7 +379,7 @@ val mtagsSettings = List( }, ) -lazy val mtags3 = project +lazy val mtags2 = project .in(file(".mtags")) .settings( Compile / unmanagedSourceDirectories := Seq(), @@ -368,13 +387,13 @@ lazy val mtags3 = project mtagsSettings, Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags" / "src" / "main" / "scala", Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags-shared" / "src" / "main" / "scala", - Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags-shared" / "src" / "main" / "scala-3", - moduleName := "mtags3", - scalaVersion := V.scala3, - target := (ThisBuild / baseDirectory).value / "mtags" / "target" / "target3", + Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags-shared" / "src" / "main" / "scala-2.13", + moduleName := "mtags2", + scalaVersion := V.scala213, + target := (ThisBuild / baseDirectory).value / "mtags" / "target" / "target2", publish / skip := true, scalafixConfig := Some( - (ThisBuild / baseDirectory).value / ".scalafix3.conf" + (ThisBuild / baseDirectory).value / ".scalafix2.conf" ), ) .dependsOn(interfaces) @@ -391,9 +410,6 @@ lazy val mtags3WithPresentationCompiler = project scalaVersion := V.firstScala3PCVersion, target := (ThisBuild / baseDirectory).value / "mtags" / "target" / "target3-wrapper", publish / skip := true, - scalafixConfig := Some( - (ThisBuild / baseDirectory).value / ".scalafix3.conf" - ), ) .dependsOn(interfaces) .enablePlugins(BuildInfoPlugin) @@ -443,7 +459,8 @@ lazy val metals = project // for BSP "org.scala-sbt.ipcsocket" % "ipcsocket" % "1.6.2", "ch.epfl.scala" % "bsp4j" % V.bsp, - "ch.epfl.scala" %% "bloop-launcher-core" % V.bloop, + ("ch.epfl.scala" %% "bloop-launcher-core" % V.bloop) + .cross(CrossVersion.for3Use2_13), // for LSP V.lsp4j, // for DAP @@ -473,13 +490,16 @@ lazy val metals = project // Scala dependencies // ================== "org.scalameta" % "mdoc-interfaces" % V.mdoc, - "org.scalameta" %% "scalafmt-dynamic" % V.scalafmt, + ("org.scalameta" %% "scalafmt-dynamic" % V.scalafmt) + .cross(CrossVersion.for3Use2_13), + "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0", "ch.epfl.scala" % "scalafix-interfaces" % V.scalafix, // For reading classpaths. // for fetching ch.epfl.scala:bloop-frontend and other library dependencies "io.get-coursier" % "interface" % V.coursierInterfaces, // for comparing versions - "io.get-coursier" %% "versions" % "0.3.2", + ("io.get-coursier" %% "versions" % "0.3.2") + .cross(CrossVersion.for3Use2_13), // for logging "com.outr" %% "scribe" % V.scribe, "com.outr" %% "scribe-file" % V.scribe, @@ -489,10 +509,11 @@ lazy val metals = project // For remote language server "com.lihaoyi" %% "requests" % "0.8.0", // for producing SemanticDB from Scala source files - "org.scalameta" %% "scalameta" % V.scalameta, - "org.scalameta" % "semanticdb-scalac-core" % V.scalameta cross CrossVersion.full, + scalametaDependency, + // "org.scalameta" % "semanticdb-scalac-core" % V.scalameta cross CrossVersion.full, // For starting Ammonite - "io.github.alexarchambault.ammonite" %% "ammonite-runner" % "0.4.0", + ("io.github.alexarchambault.ammonite" %% "ammonite-runner" % "0.4.0") + .cross(CrossVersion.for3Use2_13), "org.scala-lang.modules" %% "scala-xml" % "2.2.0", "org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4", ("org.virtuslab.scala-cli" % "scala-cli-bsp" % V.scalaCli) @@ -558,6 +579,7 @@ lazy val `sbt-metals` = project lazy val input = project .in(file("tests/input")) .settings( + scalaVersion := V.scala213, sharedSettings, publish / skip := true, libraryDependencies ++= List( @@ -690,7 +712,7 @@ lazy val mtest = project ), libraryDependencies ++= { if (isScala3WithPresentationCompiler(scalaVersion.value)) - List(scala3ScalametaDependency) + List(scalametaDependency) else Nil }, Compile / unmanagedSourceDirectories ++= { @@ -742,6 +764,7 @@ def isInTestShard(name: String, logger: Logger): Boolean = { lazy val metalsDependencies = project .in(file("target/.dependencies")) .settings( + scalaVersion := V.scala213, publish / skip := true, // silent the intransitive dependency warning publishMavenStyle := false, @@ -750,13 +773,13 @@ lazy val metalsDependencies = project // will pick them up and update them. They aren't actually used. "com.lihaoyi" %% "ammonite-util" % V.ammonite, "org.typelevel" % "kind-projector" % V.kindProjector cross CrossVersion.full, - "com.olegpy" %% "better-monadic-for" % V.betterMonadicFor, + ("com.olegpy" %% "better-monadic-for" % V.betterMonadicFor), "com.lihaoyi" % "mill-contrib-testng" % V.mill, "org.virtuslab.scala-cli" % "cli_3" % V.scalaCli intransitive (), "ch.epfl.scala" % "bloop-maven-plugin" % V.mavenBloop, "ch.epfl.scala" %% "gradle-bloop" % V.gradleBloop, "com.sourcegraph" % "semanticdb-java" % V.javaSemanticdb, - "ch.epfl.scala" %% "scala-debug-adapter" % V.debugAdapter intransitive (), + ("ch.epfl.scala" %% "scala-debug-adapter" % V.debugAdapter) intransitive (), ), ) .disablePlugins(ScalafixPlugin) @@ -771,9 +794,16 @@ lazy val unit = project sharedSettings, Test / javaOptions += "-Xmx2G", libraryDependencies ++= List( - "io.get-coursier" %% "coursier" % V.coursier, // for jars - "ch.epfl.scala" %% "bloop-config" % V.bloopConfig, + ("io.get-coursier" %% "coursier" % V.coursier) + .cross(CrossVersion.for3Use2_13), // for jars + ("ch.epfl.scala" %% "bloop-config" % V.bloopConfig) + .cross(CrossVersion.for3Use2_13), "org.scalameta" %% "munit" % V.munit, + // The dependencies listed below are only listed so Scala Steward + // will pick them up and update them. They aren't actually used. + ("com.lihaoyi" %% "ammonite-util" % V.ammonite intransitive ()) + .cross(CrossVersion.for3Use2_13), + "com.lihaoyi" % "mill-contrib-testng" % V.mill intransitive (), ), buildInfoPackage := "tests", Compile / resourceGenerators += InputProperties diff --git a/metals-bench/src/main/scala/bench/MetalsBench.scala b/metals-bench/src/main/scala/bench/MetalsBench.scala index 031d88a32e8..6478a6ace8a 100644 --- a/metals-bench/src/main/scala/bench/MetalsBench.scala +++ b/metals-bench/src/main/scala/bench/MetalsBench.scala @@ -1,11 +1,6 @@ package bench -import scala.reflect.internal.util.BatchSourceFile -import scala.reflect.io.VirtualFile -import scala.tools.nsc.interactive.Global - import scala.meta.dialects -import scala.meta.interactive.InteractiveSemanticdb import scala.meta.internal.metals.EmptyReportContext import scala.meta.internal.metals.JdkSources import scala.meta.internal.metals.logging.MetalsLogger @@ -15,7 +10,6 @@ import scala.meta.internal.mtags.SemanticdbClasspath import scala.meta.internal.parsing.Trees import scala.meta.internal.semanticdb.TextDocument import scala.meta.internal.tokenizers.LegacyScanner -import scala.meta.internal.tokenizers.LegacyToken import scala.meta.io.AbsolutePath import scala.meta.io.Classpath @@ -97,22 +91,6 @@ class MetalsBench { } } - @Benchmark - @BenchmarkMode(Array(Mode.SingleShotTime)) - def scalacTokenize(): Unit = { - val g = global - scalaDependencySources.inputs.foreach { input => - val unit = new g.CompilationUnit( - new BatchSourceFile(new VirtualFile(input.path), input.chars) - ) - val scanner = g.newUnitScanner(unit) - scanner.init() - while (scanner.token != LegacyToken.EOF) { - scanner.nextToken() - } - } - } - @Benchmark @BenchmarkMode(Array(Mode.SingleShotTime)) def scalametaParse(): Unit = { @@ -122,27 +100,6 @@ class MetalsBench { } } - lazy val global: Global = InteractiveSemanticdb.newCompiler() - - @Benchmark - @BenchmarkMode(Array(Mode.SingleShotTime)) - def scalacParse(): Unit = { - val g = global - scalaDependencySources.inputs.foreach { input => - val unit = new g.CompilationUnit( - new BatchSourceFile(new VirtualFile(input.path), input.chars) - ) - val tree = g.newUnitParser(unit).parse() - var i = 0 - new g.Traverser { - override def apply[T <: g.Tree](tree: T): T = { - i += 1 - super.apply(tree) - } - }.traverse(tree) - } - } - @Benchmark @BenchmarkMode(Array(Mode.SingleShotTime)) def mtagsJavaParse(): Unit = { diff --git a/metals/src/main/scala/scala/meta/internal/bsp/BspConfigGenerator.scala b/metals/src/main/scala/scala/meta/internal/bsp/BspConfigGenerator.scala index d5280ff039d..032a9c984c7 100644 --- a/metals/src/main/scala/scala/meta/internal/bsp/BspConfigGenerator.scala +++ b/metals/src/main/scala/scala/meta/internal/bsp/BspConfigGenerator.scala @@ -7,7 +7,7 @@ import scala.meta.internal.bsp.BspConfigGenerationStatus._ import scala.meta.internal.builds.BuildServerProvider import scala.meta.internal.builds.ShellRunner import scala.meta.internal.metals.Messages.BspProvider -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.io.AbsolutePath @@ -42,7 +42,7 @@ final class BspConfigGenerator( buildTools: List[BuildServerProvider] ): Future[(BuildServerProvider, BspConfigGenerationStatus)] = { for { - Some(buildTool) <- chooseBuildServerProvider(buildTools) + case Some(buildTool) <- chooseBuildServerProvider(buildTools) status <- buildTool.generateBspConfig( workspace, args => runUnconditionally(buildTool, args), diff --git a/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala b/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala index 04d10b1a174..4931871ddf2 100644 --- a/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala +++ b/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala @@ -14,7 +14,7 @@ import scala.meta.internal.metals.BloopServers import scala.meta.internal.metals.BuildServerConnection import scala.meta.internal.metals.Messages import scala.meta.internal.metals.Messages.BspSwitch -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.StatusBar import scala.meta.internal.metals.Tables import scala.meta.internal.metals.UserConfiguration @@ -60,7 +60,7 @@ class BspConnector( bspServers .findAvailableServers() .find(_.getName == sel) - .map(ResolvedBspOne) + .map(ResolvedBspOne.apply) } } @@ -127,7 +127,7 @@ class BspConnector( None, ) for { - Some(item) <- client + case Some(item) <- client .showMessageRequest(query.params) .asScala .map(item => diff --git a/metals/src/main/scala/scala/meta/internal/builds/BloopInstall.scala b/metals/src/main/scala/scala/meta/internal/builds/BloopInstall.scala index bcb1a6eb156..5ae399d749e 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/BloopInstall.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/BloopInstall.scala @@ -10,7 +10,7 @@ import scala.meta.internal.builds.Digest.Status import scala.meta.internal.metals.BuildInfo import scala.meta.internal.metals.Confirmation import scala.meta.internal.metals.Messages._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.Tables import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.process.ExitCodes diff --git a/metals/src/main/scala/scala/meta/internal/builds/BuildToolSelector.scala b/metals/src/main/scala/scala/meta/internal/builds/BuildToolSelector.scala index e30da44a4de..07cacb443a6 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/BuildToolSelector.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/BuildToolSelector.scala @@ -5,7 +5,7 @@ import scala.concurrent.Future import scala.meta.internal.metals.Messages import scala.meta.internal.metals.Messages.ChooseBuildTool -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.Tables import scala.meta.internal.metals.clients.language.MetalsLanguageClient @@ -22,7 +22,7 @@ final class BuildToolSelector( def checkForChosenBuildTool( buildTools: List[BuildTool] ): Future[Option[BuildTool]] = - tables.buildTool.selectedBuildTool match { + tables.buildTool.selectedBuildTool() match { case Some(chosen) => Future(buildTools.find(_.executableName == chosen)) case None => diff --git a/metals/src/main/scala/scala/meta/internal/builds/BuildTools.scala b/metals/src/main/scala/scala/meta/internal/builds/BuildTools.scala index fddb4eb88fc..89e64cf955a 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/BuildTools.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/BuildTools.scala @@ -6,7 +6,7 @@ import java.util.concurrent.atomic.AtomicReference import scala.meta.internal.io.PathIO import scala.meta.internal.metals.BloopServers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.UserConfiguration import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/builds/Digest.scala b/metals/src/main/scala/scala/meta/internal/builds/Digest.scala index 719e47dc3d5..af14f97a522 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/Digest.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/Digest.scala @@ -8,9 +8,10 @@ import scala.util.control.NonFatal import scala.xml.Comment import scala.xml.Node +import scala.meta.given import scala.meta.internal.builds.Digest.Status import scala.meta.internal.io.PathIO -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.MD5 import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath @@ -160,7 +161,7 @@ object Digest { ): Boolean = { try { val input = file.toInput - val tokens = Trees.defaultTokenizerDialect(input).tokenize.get + val tokens = Trees.defaultTokenizerDialect.apply(input).tokenize.get tokens.foreach { case token if token.isWhiteSpaceOrComment => // Do nothing case token => diff --git a/metals/src/main/scala/scala/meta/internal/builds/GradleDigest.scala b/metals/src/main/scala/scala/meta/internal/builds/GradleDigest.scala index b66999bb77e..bb90d9195b6 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/GradleDigest.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/GradleDigest.scala @@ -2,7 +2,7 @@ package scala.meta.internal.builds import java.security.MessageDigest -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath object GradleDigest extends Digestable { diff --git a/metals/src/main/scala/scala/meta/internal/builds/MavenBuildTool.scala b/metals/src/main/scala/scala/meta/internal/builds/MavenBuildTool.scala index 2cabbb486cb..c84e2f59184 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/MavenBuildTool.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/MavenBuildTool.scala @@ -2,7 +2,7 @@ package scala.meta.internal.builds import scala.meta.internal.metals.BuildInfo import scala.meta.internal.metals.JavaBinary -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.UserConfiguration import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/builds/MavenDigest.scala b/metals/src/main/scala/scala/meta/internal/builds/MavenDigest.scala index 513bcad9dae..c1515028e7d 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/MavenDigest.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/MavenDigest.scala @@ -2,7 +2,7 @@ package scala.meta.internal.builds import java.security.MessageDigest -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath object MavenDigest extends Digestable { diff --git a/metals/src/main/scala/scala/meta/internal/builds/MillDigest.scala b/metals/src/main/scala/scala/meta/internal/builds/MillDigest.scala index aa6f55f6f00..5229bcc0e2e 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/MillDigest.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/MillDigest.scala @@ -5,6 +5,7 @@ import java.security.MessageDigest import scala.collection.mutable import scala.util.control.NonFatal +import scala.meta.given import scala.meta.internal.mtags.MtagsEnrichments._ import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/builds/NewProjectProvider.scala b/metals/src/main/scala/scala/meta/internal/builds/NewProjectProvider.scala index 8508c80a48b..9449996fb9f 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/NewProjectProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/NewProjectProvider.scala @@ -11,7 +11,7 @@ import scala.meta.internal.metals.ClientCommands import scala.meta.internal.metals.ClientConfiguration import scala.meta.internal.metals.Icons import scala.meta.internal.metals.Messages._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.StatusBar import scala.meta.internal.metals.clients.language.MetalsInputBoxParams import scala.meta.internal.metals.clients.language.MetalsLanguageClient diff --git a/metals/src/main/scala/scala/meta/internal/builds/SbtBuildTool.scala b/metals/src/main/scala/scala/meta/internal/builds/SbtBuildTool.scala index 5244a66467a..c88344f8017 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/SbtBuildTool.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/SbtBuildTool.scala @@ -8,7 +8,7 @@ import scala.concurrent.ExecutionContext import scala.concurrent.Future import scala.meta.inputs.Input -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals._ import scala.meta.internal.semver.SemVer import scala.meta.internal.semver.SemVer.isCompatibleVersion @@ -260,7 +260,7 @@ object SbtBuildTool { writtenPlugin || writtenMeta } - private case class PluginDetails private ( + case class PluginDetails private[SbtBuildTool] ( description: Seq[String], artifact: String, resolver: Option[String], diff --git a/metals/src/main/scala/scala/meta/internal/builds/SbtDigest.scala b/metals/src/main/scala/scala/meta/internal/builds/SbtDigest.scala index f129711ab95..5ab7089841f 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/SbtDigest.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/SbtDigest.scala @@ -3,7 +3,7 @@ package scala.meta.internal.builds import java.security.MessageDigest import scala.meta.internal.builds.Digest.digestScala -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath object SbtDigest extends Digestable { diff --git a/metals/src/main/scala/scala/meta/internal/builds/ShellRunner.scala b/metals/src/main/scala/scala/meta/internal/builds/ShellRunner.scala index b7ad7abf41a..5553f451dbf 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/ShellRunner.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/ShellRunner.scala @@ -10,7 +10,7 @@ import scala.util.Properties import scala.meta.internal.metals.Cancelable import scala.meta.internal.metals.JavaBinary -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.MutableCancelable import scala.meta.internal.metals.StatusBar import scala.meta.internal.metals.Time diff --git a/metals/src/main/scala/scala/meta/internal/builds/WorkspaceReload.scala b/metals/src/main/scala/scala/meta/internal/builds/WorkspaceReload.scala index 353635b1ed4..80b38a427f3 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/WorkspaceReload.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/WorkspaceReload.scala @@ -7,7 +7,7 @@ import scala.meta.internal.builds.Digest.Status import scala.meta.internal.metals.Confirmation import scala.meta.internal.metals.Messages.ImportBuildChanges import scala.meta.internal.metals.Messages.dontShowAgain -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.Tables import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/decorations/SemanticdbTreePrinter.scala b/metals/src/main/scala/scala/meta/internal/decorations/SemanticdbTreePrinter.scala index 33d2a77703a..751afcfa9f9 100644 --- a/metals/src/main/scala/scala/meta/internal/decorations/SemanticdbTreePrinter.scala +++ b/metals/src/main/scala/scala/meta/internal/decorations/SemanticdbTreePrinter.scala @@ -1,6 +1,6 @@ package scala.meta.internal.decorations -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.UserConfiguration import scala.meta.internal.metap.PrinterSymtab import scala.meta.internal.semanticdb.Print @@ -123,7 +123,9 @@ class SemanticdbTreePrinter( case _ if isTuple => typeArgs.map(printType).mkString("(", ", ", ")") case _ if isFunction => - val argTypes :+ returnType = typeArgs.map(printType) + val all = typeArgs.map(printType) + val argTypes = all.dropRight(1) + val returnType = all.last argTypes.mkString("(", ", ", ")") + s" $rightArrow $returnType" case _ => typeArgs.map(printType).mkString("[", ", ", "]") diff --git a/metals/src/main/scala/scala/meta/internal/decorations/SyntheticsDecorationProvider.scala b/metals/src/main/scala/scala/meta/internal/decorations/SyntheticsDecorationProvider.scala index feed18b1dad..bea420af866 100644 --- a/metals/src/main/scala/scala/meta/internal/decorations/SyntheticsDecorationProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/decorations/SyntheticsDecorationProvider.scala @@ -9,13 +9,14 @@ import scala.concurrent.Future import scala.util.Try import scala.{meta => m} +import scala.meta.given import scala.meta.inputs.Input import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.ClientCommands import scala.meta.internal.metals.ClientConfiguration import scala.meta.internal.metals.CommandHTMLFormat import scala.meta.internal.metals.HoverExtParams -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.SemanticdbFeatureProvider import scala.meta.internal.metals.ServerCommands import scala.meta.internal.metals.UserConfiguration @@ -455,8 +456,7 @@ final class SyntheticsDecorationProvider( typeDecorations(path, textDocument, decorationPrinter) else Nil decorations ++ typDecorations - } else - Nil + } else Nil } private def typeDecorations( diff --git a/metals/src/main/scala/scala/meta/internal/implementation/ImplementationProvider.scala b/metals/src/main/scala/scala/meta/internal/implementation/ImplementationProvider.scala index 55a624e227d..0db0833c106 100644 --- a/metals/src/main/scala/scala/meta/internal/implementation/ImplementationProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/implementation/ImplementationProvider.scala @@ -12,7 +12,7 @@ import scala.util.control.NonFatal import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.BuildTargets import scala.meta.internal.metals.DefinitionProvider -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ReportContext import scala.meta.internal.metals.ScalaVersionSelector import scala.meta.internal.metals.SemanticdbFeatureProvider @@ -32,6 +32,7 @@ import scala.meta.internal.semanticdb.TextDocument import scala.meta.internal.semanticdb.TextDocuments import scala.meta.internal.semanticdb.TypeRef import scala.meta.internal.semanticdb.TypeSignature +import scala.meta.internal.semanticdb.given import scala.meta.internal.symtab.GlobalSymbolTable import scala.meta.io.AbsolutePath @@ -271,8 +272,7 @@ final class ImplementationProvider( implDocument: TextDocument, implReal: ClassLocation, ): Option[String] = { - if (isClassLike(parentSymbolInfo)) - Some(implReal.symbol) + if (isClassLike(parentSymbolInfo)) Some(implReal.symbol) else { val symbolSearch = defaultSymbolSearch(source, implDocument) MethodImplementation.findInherited( diff --git a/metals/src/main/scala/scala/meta/internal/implementation/Supermethods.scala b/metals/src/main/scala/scala/meta/internal/implementation/Supermethods.scala index 94d1dce1154..db4ceb3419f 100644 --- a/metals/src/main/scala/scala/meta/internal/implementation/Supermethods.scala +++ b/metals/src/main/scala/scala/meta/internal/implementation/Supermethods.scala @@ -6,7 +6,7 @@ import scala.concurrent.Future import scala.meta.internal.implementation.Supermethods.formatMethodSymbolForQuickPick import scala.meta.internal.metals.ClientCommands import scala.meta.internal.metals.DefinitionProvider -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ReportContext import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.metals.clients.language.MetalsQuickPickItem diff --git a/metals/src/main/scala/scala/meta/internal/metals/ActiveFiles.scala b/metals/src/main/scala/scala/meta/internal/metals/ActiveFiles.scala index e588e0e8302..459fd40dedc 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ActiveFiles.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ActiveFiles.scala @@ -2,7 +2,7 @@ package scala.meta.internal.metals import java.util.concurrent.ConcurrentLinkedQueue -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath /** diff --git a/metals/src/main/scala/scala/meta/internal/metals/AdjustLspData.scala b/metals/src/main/scala/scala/meta/internal/metals/AdjustLspData.scala index 5c2494e1aae..9885b5e085e 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/AdjustLspData.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/AdjustLspData.scala @@ -2,7 +2,7 @@ package scala.meta.internal.metals import java.{util => ju} -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.pc.AutoImportsResult import scala.meta.pc.HoverSignature @@ -55,8 +55,7 @@ trait AdjustLspData { ): ju.List[Location] def adjustHoverResp(hover: Hover): Hover = - if (hover.getRange == null) - hover + if (hover.getRange == null) hover else { val newRange = adjustRange(hover.getRange) val newHover = new Hover diff --git a/metals/src/main/scala/scala/meta/internal/metals/BatchedFunction.scala b/metals/src/main/scala/scala/meta/internal/metals/BatchedFunction.scala index 0c6773ae679..45f90440180 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BatchedFunction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BatchedFunction.scala @@ -157,7 +157,7 @@ object BatchedFunction { ec: ExecutionContext ): BatchedFunction[A, B] = new BatchedFunction( - fn.andThen(CancelableFuture(_)), + fn.andThen(CancelableFuture(_, Cancelable.empty)), functionId, shouldLogQueue, ) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index e7b43b0b0f6..8e3571b4b10 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -17,7 +17,7 @@ import scala.util.Try import scala.meta.internal.bsp.BuildChange import scala.meta.internal.metals.BloopJsonUpdateCause.BloopJsonUpdateCause -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.io.AbsolutePath @@ -47,6 +47,16 @@ final class BloopServers( config: MetalsServerConfig, )(implicit ec: ExecutionContextExecutorService) { + class BloopOutputStream extends OutputStream { + private lazy val b = new StringBuilder + + override def write(byte: Int): Unit = byte.toChar match { + case c => b.append(c) + } + + def logs = b.result.linesIterator + } + import BloopServers._ private val bloopJsonPath: Option[AbsolutePath] = @@ -465,15 +475,7 @@ final class BloopServers( val launcherOut = Channels.newOutputStream(clientInOutPipe.sink()) val serverStarted = Promise[Unit]() - val bloopLogs = new OutputStream { - private lazy val b = new StringBuilder - - override def write(byte: Int): Unit = byte.toChar match { - case c => b.append(c) - } - - def logs = b.result.linesIterator - } + val bloopLogs = new BloopOutputStream() val launcher = new LauncherMain( diff --git a/metals/src/main/scala/scala/meta/internal/metals/Buffers.scala b/metals/src/main/scala/scala/meta/internal/metals/Buffers.scala index 4ac56b33a5f..0f8ad5e8ed8 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Buffers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Buffers.scala @@ -3,7 +3,7 @@ package scala.meta.internal.metals import scala.collection.concurrent.TrieMap import scala.meta.inputs.Input -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.TokenEditDistance import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala b/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala index 9d29e45461f..5dba3743ce0 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala @@ -23,7 +23,7 @@ import scala.util.Try import scala.meta.internal.builds.MillBuildTool import scala.meta.internal.builds.SbtBuildTool -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ammonite.Ammonite import scala.meta.internal.metals.scalacli.ScalaCli import scala.meta.internal.pc.InterruptException diff --git a/metals/src/main/scala/scala/meta/internal/metals/BuildTargetInfo.scala b/metals/src/main/scala/scala/meta/internal/metals/BuildTargetInfo.scala index 5378c6d6939..e1b3515e4cc 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BuildTargetInfo.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BuildTargetInfo.scala @@ -4,7 +4,7 @@ import java.nio.file.Path import scala.collection.mutable.ListBuffer -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.URIEncoderDecoder import ch.epfl.scala.bsp4j.BuildTarget @@ -194,8 +194,7 @@ class BuildTargetInfo(buildTargets: BuildTargets) { maxFilenameSize, ) ) - } else - List(" NONE") + } else List(" NONE") } private def getDependencies(target: BuildTarget): List[String] = { diff --git a/metals/src/main/scala/scala/meta/internal/metals/BuildTargets.scala b/metals/src/main/scala/scala/meta/internal/metals/BuildTargets.scala index 114553c5103..22fb82858a9 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BuildTargets.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BuildTargets.scala @@ -12,7 +12,7 @@ import scala.concurrent.Future import scala.util.control.NonFatal import scala.meta.internal.io.PathIO -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.Symbol import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/CancelableFuture.scala b/metals/src/main/scala/scala/meta/internal/metals/CancelableFuture.scala index 11f171fb6fa..b9fa82b6ff6 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/CancelableFuture.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/CancelableFuture.scala @@ -21,7 +21,7 @@ object CancelableFuture { CancelableFuture(Future(thunk), Cancelable.empty) } def successful[T](value: T): CancelableFuture[T] = - CancelableFuture(Future.successful(value)) + CancelableFuture(Future.successful(value), Cancelable.empty) def sequence[T]( futures: Seq[CancelableFuture[T]] )(implicit ec: ExecutionContext): CancelableFuture[Seq[T]] = diff --git a/metals/src/main/scala/scala/meta/internal/metals/Command.scala b/metals/src/main/scala/scala/meta/internal/metals/Command.scala index b7fc310e42b..5def4914db7 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Command.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Command.scala @@ -4,7 +4,7 @@ import scala.reflect.ClassTag import scala.util.matching.Regex import scala.meta.internal.metals.JsonParser._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import org.eclipse.{lsp4j => l} diff --git a/metals/src/main/scala/scala/meta/internal/metals/Compilations.scala b/metals/src/main/scala/scala/meta/internal/metals/Compilations.scala index 60e0762ec00..3a5f6fed911 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Compilations.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Compilations.scala @@ -7,7 +7,7 @@ import scala.util.Failure import scala.util.Success import scala.util.Try -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.metals.debug.BuildTargetClasses import scala.meta.io.AbsolutePath @@ -177,8 +177,7 @@ final class Compilations( } targetOpt - } else - Future.successful(None) + } else Future.successful(None) } def expand(paths: Seq[AbsolutePath]): Future[Seq[b.BuildTargetIdentifier]] = { diff --git a/metals/src/main/scala/scala/meta/internal/metals/CompilerPlugins.scala b/metals/src/main/scala/scala/meta/internal/metals/CompilerPlugins.scala index 908e8d42e80..4c25bc4136f 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/CompilerPlugins.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/CompilerPlugins.scala @@ -7,7 +7,7 @@ import scala.util.control.NonFatal import scala.xml.XML import scala.meta.internal.io.FileIO -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath /** 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 ca061b457cd..d25c8bff48a 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala @@ -15,10 +15,8 @@ import scala.util.control.NonFatal import scala.meta.inputs.Input import scala.meta.inputs.Position -import scala.meta.internal.metals.CompilerOffsetParamsUtils -import scala.meta.internal.metals.CompilerRangeParamsUtils import scala.meta.internal.metals.Compilers.PresentationCompilerKey -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.Trees import scala.meta.internal.pc.EmptySymbolSearch import scala.meta.internal.pc.JavaPresentationCompiler @@ -826,7 +824,7 @@ class Compilers( jworksheetsCache.put( path, statusBar.trackBlockingTask( - s"${config.icons.sync}Loading worksheet presentation compiler" + s"${config.icons().sync}Loading worksheet presentation compiler" ) { val worksheetSearch = new StandaloneSymbolSearch( workspace, @@ -905,7 +903,7 @@ class Compilers( PresentationCompilerKey.BuildTarget(scalaTarget.info.getId), { _ => statusBar.trackBlockingTask( - s"${config.icons.sync}Loading presentation compiler" + s"${config.icons().sync}Loading presentation compiler" ) { newCompiler(scalaTarget, mtags, search) } 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 9071c288af2..11ffe94ae8c 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala @@ -7,8 +7,9 @@ import scala.concurrent.Future import scala.meta.Term import scala.meta.Type +import scala.meta.given import scala.meta.inputs.Input -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.GlobalSymbolIndex import scala.meta.internal.mtags.Mtags import scala.meta.internal.mtags.Semanticdbs @@ -461,8 +462,7 @@ class DestinationProvider( allowedBuildTargets: Set[BuildTargetIdentifier], ): Option[SymbolDefinition] = { val definitions = index.definitions(Symbol(symbol)).filter(_.path.exists) - if (allowedBuildTargets.isEmpty) - definitions.headOption + if (allowedBuildTargets.isEmpty) definitions.headOption else { val matched = definitions.find { defn => sourceBuildTargets(defn.path).exists(id => diff --git a/metals/src/main/scala/scala/meta/internal/metals/Diagnostics.scala b/metals/src/main/scala/scala/meta/internal/metals/Diagnostics.scala index 709021da247..bb7051dd921 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Diagnostics.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Diagnostics.scala @@ -8,8 +8,8 @@ import scala.collection.concurrent.TrieMap import scala.collection.mutable import scala.meta.inputs.Input -import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.PositionSyntax._ +import scala.meta.internal.metals.MetalsEnrichments.given +import scala.meta.internal.metals.PositionSyntax.given import scala.meta.internal.parsing.TokenEditDistance import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/Embedded.scala b/metals/src/main/scala/scala/meta/internal/metals/Embedded.scala index 0378d2647b1..d17e101b5d2 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Embedded.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Embedded.scala @@ -6,7 +6,7 @@ import java.util.ServiceLoader import scala.collection.concurrent.TrieMap -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.pc.ScalaPresentationCompiler import scala.meta.internal.worksheets.MdocClassLoader import scala.meta.io.Classpath diff --git a/metals/src/main/scala/scala/meta/internal/metals/FileDecoderProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/FileDecoderProvider.scala index 854a62b63d4..41ff7872e07 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/FileDecoderProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/FileDecoderProvider.scala @@ -455,8 +455,9 @@ final class FileDecoderProvider( .metalsQuickPick(quickPickParams) .asScala .mapOptionInside(_.itemId) - } else + } else { Future.successful(Some(classes.head.resourcePath)) + } private def findSemanticDbPathInfo( sourceFile: AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/FileSystemSemanticdbs.scala b/metals/src/main/scala/scala/meta/internal/metals/FileSystemSemanticdbs.scala index 523d2808215..e442034d1f9 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/FileSystemSemanticdbs.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/FileSystemSemanticdbs.scala @@ -2,7 +2,7 @@ package scala.meta.internal.metals import java.nio.charset.Charset -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.Md5Fingerprints import scala.meta.internal.mtags.SemanticdbClasspath import scala.meta.internal.mtags.Semanticdbs diff --git a/metals/src/main/scala/scala/meta/internal/metals/Fingerprints.scala b/metals/src/main/scala/scala/meta/internal/metals/Fingerprints.scala index 09d82a3be9c..e5808ace82e 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Fingerprints.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Fingerprints.scala @@ -4,7 +4,6 @@ import java.nio.file.Paths import java.sql.Connection import java.sql.PreparedStatement -import scala.meta.internal.metals.Fingerprint import scala.meta.internal.metals.JdbcEnrichments._ import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/FormattingProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/FormattingProvider.scala index 13bea2de1e2..d6cc43835d8 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/FormattingProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/FormattingProvider.scala @@ -24,7 +24,7 @@ import scala.meta.internal.io.FileIO import scala.meta.internal.metals.Messages.MissingScalafmtConf import scala.meta.internal.metals.Messages.MissingScalafmtVersion import scala.meta.internal.metals.Messages.UpdateScalafmtConf -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.semver.SemVer @@ -177,7 +177,7 @@ final class FormattingProvider( private def askScalafmtVersion(): Future[Option[String]] = { if (!tables.dismissedNotifications.ChangeScalafmtVersion.isDismissed) { - if (clientConfig.isInputBoxEnabled) { + if (clientConfig.isInputBoxEnabled()) { client .metalsInputBox(MissingScalafmtVersion.inputBox()) .asScala diff --git a/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala b/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala index c6ed5d98969..ff8d538c7bc 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala @@ -14,7 +14,7 @@ import scala.meta.internal.metals.ClientConfiguration import scala.meta.internal.metals.ConcurrentHashSet import scala.meta.internal.metals.Diagnostics import scala.meta.internal.metals.MetalsBuildClient -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.StatusBar import scala.meta.internal.metals.TaskProgress import scala.meta.internal.metals.Time @@ -177,8 +177,8 @@ final class ForwardingMetalsBuildClient( } val isSuccess = report.getErrors == 0 val icon = - if (isSuccess) clientConfig.icons.check - else clientConfig.icons.alert + if (isSuccess) clientConfig.icons().check + else clientConfig.icons().alert val message = s"${icon}Compiled $name (${compilation.timer})" if (!compilation.isNoOp) { scribe.info(s"time: compiled $name in ${compilation.timer}") diff --git a/metals/src/main/scala/scala/meta/internal/metals/ImportedBuild.scala b/metals/src/main/scala/scala/meta/internal/metals/ImportedBuild.scala index eabee1e5835..3969e5fee40 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ImportedBuild.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ImportedBuild.scala @@ -7,7 +7,7 @@ import scala.build.bsp.WrappedSourcesResult import scala.concurrent.ExecutionContext import scala.concurrent.Future -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import ch.epfl.scala.bsp4j._ diff --git a/metals/src/main/scala/scala/meta/internal/metals/Indexer.scala b/metals/src/main/scala/scala/meta/internal/metals/Indexer.scala index cacdd666ec9..ba839a8bfda 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Indexer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Indexer.scala @@ -23,7 +23,7 @@ import scala.meta.internal.builds.BuildTool import scala.meta.internal.builds.BuildTools import scala.meta.internal.builds.Digest.Status import scala.meta.internal.builds.WorkspaceReload -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.DelegatingLanguageClient import scala.meta.internal.metals.clients.language.ForwardingMetalsBuildClient import scala.meta.internal.metals.debug.BuildTargetClasses @@ -153,7 +153,7 @@ final case class Indexer( ) tracked.foreach { _ => statusBar().addMessage( - s"${clientConfig.icons.rocket} Indexing complete!" + s"${clientConfig.icons().rocket} Indexing complete!" ) if (clientConfig.initialConfig.statistics.isMemory) { Memory.logMemory( diff --git a/metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala b/metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala index af8279393ae..00b0d6a197b 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala @@ -225,7 +225,7 @@ object CommandHTMLFormat { // The lib used to convert markdown to html in sublime doesn't properly // recognize URL encoding so we have to use hexadecimal html encoding args.flatMap { - case char if toEscape.contains(char) => s"&#x${char.toHexString};" + case char if toEscape.contains(char) => s"&#x${char.toInt.toHexString};" case char => char.toString } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala b/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala index f4ae0f62178..edeff43aa98 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala @@ -10,7 +10,7 @@ import scala.util.Try import scala.meta.internal.builds.SbtBuildTool import scala.meta.internal.io.FileIO import scala.meta.internal.metals.Messages._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.mtags.MD5 import scala.meta.internal.mtags.Semanticdbs @@ -149,7 +149,7 @@ final class InteractiveSemanticdbs( new l.Diagnostic(range.toLsp, diag.message, severity, "scala") } if (diagnostics.nonEmpty) { - statusBar.addMessage(partialNavigation(clientConfig.icons)) + statusBar.addMessage(partialNavigation(clientConfig.icons())) client.publishDiagnostics( new PublishDiagnosticsParams(uri, diagnostics.asJava) ) diff --git a/metals/src/main/scala/scala/meta/internal/metals/JarTopLevels.scala b/metals/src/main/scala/scala/meta/internal/metals/JarTopLevels.scala index 6fae84713fd..ece8cd985e7 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/JarTopLevels.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/JarTopLevels.scala @@ -10,7 +10,7 @@ import java.util.zip.ZipException import scala.meta.internal.io.PlatformFileIO import scala.meta.internal.metals.JdbcEnrichments._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.MD5 import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/JavaFormattingProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/JavaFormattingProvider.scala index eceb0eae26c..e36e434bf64 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/JavaFormattingProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/JavaFormattingProvider.scala @@ -10,7 +10,7 @@ import scala.util.Try import scala.xml.Node import scala.meta._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath import scala.meta.{inputs => m} @@ -63,8 +63,7 @@ final class JavaFormattingProvider( else scribe.error(s"Java formatting profile ${profileName.get} not found") defaultSettings - } else - decodeProfile(profiles.head) + } else decodeProfile(profiles.head) } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/JavaInteractiveSemanticdb.scala b/metals/src/main/scala/scala/meta/internal/metals/JavaInteractiveSemanticdb.scala index 35ad8aed3c2..06eba4cf47b 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/JavaInteractiveSemanticdb.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/JavaInteractiveSemanticdb.scala @@ -15,7 +15,7 @@ import scala.util.control.NonFatal import scala.meta.internal.builds.ShellRunner import scala.meta.internal.io.FileIO -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.MD5 import scala.meta.internal.process.SystemProcess import scala.meta.internal.{semanticdb => s} diff --git a/metals/src/main/scala/scala/meta/internal/metals/JavaTarget.scala b/metals/src/main/scala/scala/meta/internal/metals/JavaTarget.scala index b2d7cb3c1a3..90b82b3a50f 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/JavaTarget.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/JavaTarget.scala @@ -3,7 +3,7 @@ package scala.meta.internal.metals import java.nio.file.Path import scala.meta.internal.builds.MillBuildTool -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.semver.SemVer import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala index 713721db95e..17884058426 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala @@ -64,7 +64,7 @@ import org.eclipse.{lsp4j => l} * One stop shop for all extension methods that are used in the metals build. * * Usage: {{{ - * import scala.meta.internal.metals.MetalsEnrichments._ + * import scala.meta.internal.metals.MetalsEnrichments.given * List(1).asJava * Future(1).asJava * // ... @@ -173,7 +173,7 @@ object MetalsEnrichments implicit class XtensionScalaFuture[A](future: Future[A]) { def asCancelable: CancelableFuture[A] = - CancelableFuture(future) + CancelableFuture(future, Cancelable.empty) def asJava: CompletableFuture[A] = FutureConverters.toJava(future).toCompletableFuture @@ -350,8 +350,7 @@ object MetalsEnrichments def toRelativeInside(prefix: AbsolutePath): Option[RelativePath] = { // windows throws an exception on toRelative when on different drives - if (path.toNIO.getRoot() != prefix.toNIO.getRoot()) - None + if (path.toNIO.getRoot() != prefix.toNIO.getRoot()) None else { val relative = path.toRelative(prefix) if (relative.toNIO.getName(0).filename != "..") Some(relative) @@ -647,16 +646,13 @@ object MetalsEnrichments def replaceAllBetween(start: String, end: String)( replacement: String ): String = - if (start.isEmpty || end.isEmpty) - value + if (start.isEmpty || end.isEmpty) value else { val startIdx = value.indexOf(start) - if (startIdx < 0) - value + if (startIdx < 0) value else { val endIdx = value.indexOf(end, startIdx + start.length) - if (endIdx < 0) - value + if (endIdx < 0) value else { val b = new java.lang.StringBuilder b.append(value, 0, startIdx) diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsHttpServer.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsHttpServer.scala index 137820cc11b..99b8fd1a7c1 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsHttpServer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsHttpServer.scala @@ -15,7 +15,7 @@ import scala.util.Success import scala.util.control.NonFatal import scala.meta.internal.io.InputStreamIO -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import io.undertow.Handlers.path import io.undertow.Handlers.websocket 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 2fcd72bc6b4..4f1937b2733 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -39,10 +39,8 @@ import scala.meta.internal.decorations.SyntheticsDecorationProvider import scala.meta.internal.implementation.ImplementationProvider import scala.meta.internal.implementation.Supermethods import scala.meta.internal.io.FileIO -import scala.meta.internal.metals.BuildInfo import scala.meta.internal.metals.Messages.IncompatibleBloopVersion import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.StdReportContext import scala.meta.internal.metals.ammonite.Ammonite import scala.meta.internal.metals.callHierarchy.CallHierarchyProvider import scala.meta.internal.metals.clients.language.ConfiguredLanguageClient @@ -233,7 +231,7 @@ class MetalsLspService( buildTargetClasses, () => folder, languageClient, - () => testProvider.refreshTestSuites(), + () => testProvider.refreshTestSuites(()), () => { if (clientConfig.isDoctorVisibilityProvider()) headDoctor.executeRefreshDoctor() @@ -323,7 +321,7 @@ class MetalsLspService( folder, buildTargets, statusBar, - clientConfig.icons, + clientConfig.icons(), buildTools, compilations.isCurrentlyCompiling, ) @@ -460,7 +458,7 @@ class MetalsLspService( folder, buffers, definitionProvider, - clientConfig.icons, + clientConfig.icons(), clientConfig.commandInHtmlFormat(), ) @@ -569,7 +567,7 @@ class MetalsLspService( languageClient, clientConfig, statusBar, - clientConfig.icons, + clientConfig.icons(), tables, buildTargets, ) @@ -587,7 +585,7 @@ class MetalsLspService( semanticdbs, definitionProvider, referencesProvider, - clientConfig.icons, + clientConfig.icons(), () => compilers, trees, buildTargets, @@ -625,7 +623,7 @@ class MetalsLspService( val worksheetProvider: WorksheetProvider = { val worksheetPublisher = - if (clientConfig.isDecorationProvider) + if (clientConfig.isDecorationProvider()) new DecorationWorksheetPublisher( clientConfig.isInlineDecorationProvider() ) @@ -871,9 +869,11 @@ class MetalsLspService( new Registration( "1", "workspace/didChangeWatchedFiles", - clientConfig.globSyntax.registrationOptions( - this.folder - ), + clientConfig + .globSyntax() + .registrationOptions( + this.folder + ), ) ).asJava ) @@ -950,7 +950,7 @@ class MetalsLspService( session.version, userConfig().bloopVersion.nonEmpty, old.bloopVersion.isDefined, - () => autoConnectToBuildServer, + () => autoConnectToBuildServer(), ) .flatMap { _ => bloopServers.ensureDesiredJvmSettings( @@ -1444,7 +1444,7 @@ class MetalsLspService( s"Found new symbol references for $names, try running again." scribe.info(message) statusBar - .addMessage(clientConfig.icons.info + message) + .addMessage(clientConfig.icons().info + message) } } } @@ -1511,7 +1511,7 @@ class MetalsLspService( item: CompletionItem ): CompletableFuture[CompletionItem] = CancelTokens.future { _ => - if (clientConfig.isCompletionItemResolve) { + if (clientConfig.isCompletionItemResolve()) { compilers.completionItemResolve(item) } else { Future.successful(item) @@ -1551,9 +1551,9 @@ class MetalsLspService( CancelTokens.future { _ => val path = params.getTextDocument().getUri().toAbsolutePath if (path.isScala) - parseTrees.currentFuture.map(_ => - foldingRangeProvider.getRangedForScala(path) - ) + parseTrees + .currentFuture() + .map(_ => foldingRangeProvider.getRangedForScala(path)) else Future { foldingRangeProvider.getRangedForJava(path) @@ -1603,7 +1603,7 @@ class MetalsLspService( Future.successful(bloopServers.shutdownServer()) case Some(session) if session.main.isSbt => for { - currentBuildTool <- supportedBuildTool + currentBuildTool <- supportedBuildTool() res <- currentBuildTool match { case Some(sbt: SbtBuildTool) => for { @@ -1911,7 +1911,7 @@ class MetalsLspService( } } - buildTools.loadSupported match { + buildTools.loadSupported() match { case Nil => { if (!buildTools.isAutoConnectable) { warnings.noBuildTool() @@ -1922,7 +1922,7 @@ class MetalsLspService( } case buildTools => for { - Some(buildTool) <- buildToolSelector.checkForChosenBuildTool( + case Some(buildTool) <- buildToolSelector.checkForChosenBuildTool( buildTools ) } yield isCompatibleVersion(buildTool) @@ -1933,7 +1933,7 @@ class MetalsLspService( forceImport: Boolean ): Future[BuildChange] = for { - possibleBuildTool <- supportedBuildTool + possibleBuildTool <- supportedBuildTool() chosenBuildServer = tables.buildServers.selectedServer() isBloopOrEmpty = chosenBuildServer.isEmpty || chosenBuildServer.exists( _ == BloopServers.name @@ -1976,7 +1976,7 @@ class MetalsLspService( def maybeSetupScalaCli(): Future[Unit] = { if ( !buildTools.isAutoConnectable - && buildTools.loadSupported.isEmpty + && buildTools.loadSupported().isEmpty && folder.hasScalaFiles ) { scalaCli.setupIDE(folder) @@ -2259,7 +2259,7 @@ class MetalsLspService( if (!notification.isDismissed) { val messageParams = IncompatibleBloopVersion.params( bspServerVersion, - BuildInfo.bloopVersion, + scala.meta.internal.metals.BuildInfo.bloopVersion, isChangedInSettings = userConfig().bloopVersion != None, ) languageClient.showMessageRequest(messageParams).asScala.foreach { @@ -2279,7 +2279,7 @@ class MetalsLspService( ): Future[Unit] = { paths .find { path => - if (clientConfig.isDidFocusProvider || focusedDocument().isDefined) { + if (clientConfig.isDidFocusProvider() || focusedDocument().isDefined) { focusedDocument().contains(path) && path.isWorksheet } else { diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsServerInputs.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsServerInputs.scala index 50adbbc106c..b35f887de93 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsServerInputs.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsServerInputs.scala @@ -4,13 +4,6 @@ import java.nio.charset.Charset import java.nio.charset.StandardCharsets import scala.meta.internal.bsp.BspServers -import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.ClasspathSearch -import scala.meta.internal.metals.MetalsServerConfig -import scala.meta.internal.metals.MtagsResolver -import scala.meta.internal.metals.ProgressTicks -import scala.meta.internal.metals.Time -import scala.meta.internal.metals.UserConfiguration import scala.meta.io.AbsolutePath /** diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsSymbolSearch.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsSymbolSearch.scala index d0b32541299..c55e941993a 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsSymbolSearch.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsSymbolSearch.scala @@ -6,7 +6,7 @@ import java.{util => ju} import scala.collection.concurrent.TrieMap -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.Mtags import scala.meta.io.AbsolutePath import scala.meta.pc.ParentSymbols diff --git a/metals/src/main/scala/scala/meta/internal/metals/MtagsResolver.scala b/metals/src/main/scala/scala/meta/internal/metals/MtagsResolver.scala index 9bcf42b6909..c45a3967061 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MtagsResolver.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MtagsResolver.scala @@ -6,7 +6,6 @@ import scala.concurrent.duration._ import scala.util.control.NonFatal import scala.meta.internal.jdk.CollectionConverters._ -import scala.meta.internal.metals.BuildInfo import scala.meta.internal.semver.SemVer import coursierapi.error.SimpleResolutionError diff --git a/metals/src/main/scala/scala/meta/internal/metals/PackageProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/PackageProvider.scala index d9d6f2490eb..7b8fbe25cca 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/PackageProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/PackageProvider.scala @@ -6,11 +6,12 @@ import scala.concurrent.Future import scala.{meta => m} import scala.meta._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.newScalaFile.NewFileTemplate +import scala.meta.internal.mtags.KeywordWrapper import scala.meta.internal.parsing.Trees -import scala.meta.internal.pc.Identifier import scala.meta.internal.semanticdb.Scala._ +import scala.meta.internal.semanticdb.given import scala.meta.internal.{semanticdb => s} import scala.meta.io.AbsolutePath @@ -768,12 +769,14 @@ class PackageProvider( case _ => acc } tree match { - case Source(List(pk: Pkg)) => extractOuterPackage(pk).reverse + case Source(List(pk: Pkg)) => extractOuterPackage(pk).reverse() case _ => PackagesStructure.empty } } - private def wrap(str: String): String = Identifier.backtickWrap(str) + // TODO wrap with correct dialect + private def wrap(str: String): String = + KeywordWrapper.Scala2.backtickWrap(str) private def workspaceEdit( path: AbsolutePath, @@ -852,7 +855,10 @@ class PackageProvider( oldPath: AbsoluteFile, ): WorkspaceEdit = { val extend: (Int, Int) => (Int, Int) = - extendRangeToIncludeWhiteCharsAndTheFollowingNewLine(source, List(':')) + MetalsEnrichments.extendRangeToIncludeWhiteCharsAndTheFollowingNewLine( + source, + List(':'), + ) edits.flatMap { // delete package declaration case PackageEdit(pkg, Nil) => @@ -936,7 +942,7 @@ object PackageProvider { PackagesStructure(pkgs.reverse, pkgObject) def allPackagesParts(): List[List[String]] = pkgs.map(_.name) ++ pkgObject.map(obj => List(obj.name.value)).toList - def allParts(): List[String] = allPackagesParts.flatten + def allParts(): List[String] = allPackagesParts().flatten } object PackagesStructure { diff --git a/metals/src/main/scala/scala/meta/internal/metals/PopupChoiceReset.scala b/metals/src/main/scala/scala/meta/internal/metals/PopupChoiceReset.scala index 192b195941d..acf06df592a 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/PopupChoiceReset.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/PopupChoiceReset.scala @@ -5,7 +5,7 @@ import scala.concurrent.Future import scala.meta.internal.bsp.BspConnector import scala.meta.internal.bsp.BuildChange -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala index 258830eab23..14f24f68319 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala @@ -10,8 +10,7 @@ import scala.util.control.NonFatal import scala.util.matching.Regex import scala.meta.Importee -import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.ResolvedSymbolOccurrence +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.DefinitionAlternatives.GlobalSymbol import scala.meta.internal.mtags.SemanticdbPath import scala.meta.internal.mtags.Semanticdbs @@ -25,6 +24,7 @@ import scala.meta.internal.semanticdb.SymbolOccurrence import scala.meta.internal.semanticdb.Synthetic import scala.meta.internal.semanticdb.TextDocument import scala.meta.internal.semanticdb.TextDocuments +import scala.meta.internal.semanticdb.given import scala.meta.internal.{semanticdb => s} import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/ScalaTarget.scala b/metals/src/main/scala/scala/meta/internal/metals/ScalaTarget.scala index 1f040b7f8b1..a0aa03748e1 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ScalaTarget.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ScalaTarget.scala @@ -5,7 +5,7 @@ import java.nio.file.Path import scala.meta.Dialect import scala.meta.dialects._ import scala.meta.internal.builds.MillBuildTool -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.semver.SemVer import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/ScalaVersionSelector.scala b/metals/src/main/scala/scala/meta/internal/metals/ScalaVersionSelector.scala index 4e92e333e49..4f6dc8becf7 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ScalaVersionSelector.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ScalaVersionSelector.scala @@ -1,7 +1,7 @@ package scala.meta.internal.metals import scala.meta._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.semver.SemVer import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/ScalafixProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/ScalafixProvider.scala index 45e43513293..10cd975f7d3 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ScalafixProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ScalafixProvider.scala @@ -14,7 +14,7 @@ import scala.util.Success import scala.util.Try import scala.meta._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.metals.clients.language.MetalsQuickPickItem import scala.meta.internal.metals.clients.language.MetalsQuickPickParams diff --git a/metals/src/main/scala/scala/meta/internal/metals/SemanticdbIndexer.scala b/metals/src/main/scala/scala/meta/internal/metals/SemanticdbIndexer.scala index ad825ef4a23..ccdc845b040 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/SemanticdbIndexer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/SemanticdbIndexer.scala @@ -6,7 +6,7 @@ import java.nio.file.Path import scala.util.control.NonFatal -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.SemanticdbClasspath import scala.meta.internal.mtags.SemanticdbPath import scala.meta.internal.semanticdb.TextDocument @@ -54,11 +54,7 @@ class SemanticdbIndexer( * In case of a null path, we re-index `META-INF/semanticdb` for all targets */ def onOverflow(path: SemanticdbPath): Unit = { - if (path == null) { - onTargetRoots() - } else { - path.semanticdbRoot.foreach(onChangeDirectory(_)) - } + path.semanticdbRoot.foreach(onChangeDirectory(_)) } private def onChangeDirectory(dir: Path): Unit = { diff --git a/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala b/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala index 241681401ac..d1627f462e5 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala @@ -649,7 +649,8 @@ object ServerCommands { final case class ConvertToNamedArgsRequest( position: TextDocumentPositionParams, - argIndices: ju.List[Integer], + // json doesn't distinguish between ints and doubles + argIndices: ju.List[java.lang.Double], ) val ConvertToNamedArguments = new ParametrizedCommand[ConvertToNamedArgsRequest]( diff --git a/metals/src/main/scala/scala/meta/internal/metals/SourceMapper.scala b/metals/src/main/scala/scala/meta/internal/metals/SourceMapper.scala index 4cd698ce494..275446dbb9c 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/SourceMapper.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/SourceMapper.scala @@ -2,7 +2,7 @@ package scala.meta.internal.metals import scala.meta.inputs.Input import scala.meta.internal.builds.SbtBuildTool -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.worksheets.WorksheetProvider import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/StacktraceAnalyzer.scala b/metals/src/main/scala/scala/meta/internal/metals/StacktraceAnalyzer.scala index 1d267f96855..82ea12060d3 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/StacktraceAnalyzer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/StacktraceAnalyzer.scala @@ -5,7 +5,7 @@ import java.io.FileWriter import scala.util.Try import scala.util.matching.Regex -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.StacktraceAnalyzer._ import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/StandaloneSymbolSearch.scala b/metals/src/main/scala/scala/meta/internal/metals/StandaloneSymbolSearch.scala index e9400741330..c034b9de68d 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/StandaloneSymbolSearch.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/StandaloneSymbolSearch.scala @@ -6,7 +6,7 @@ import java.{util => ju} import scala.collection.concurrent.TrieMap -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.Mtags import scala.meta.internal.mtags.OnDemandSymbolIndex import scala.meta.internal.parsing.Trees diff --git a/metals/src/main/scala/scala/meta/internal/metals/StatusBar.scala b/metals/src/main/scala/scala/meta/internal/metals/StatusBar.scala index e3e9a11d0ec..6d649b2b895 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/StatusBar.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/StatusBar.scala @@ -13,7 +13,7 @@ import scala.util.Failure import scala.util.Success import scala.util.control.NonFatal -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.metals.clients.language.MetalsSlowTaskParams import scala.meta.internal.metals.clients.language.MetalsStatusParams @@ -52,7 +52,7 @@ final class StatusBar( } def trackSlowTask[T](message: String)(thunk: => T): T = { - if (!clientConfig.slowTaskIsOn) + if (!clientConfig.slowTaskIsOn()) trackBlockingTask(message)(thunk) else { val task = client.metalsSlowTask(MetalsSlowTaskParams(message)) @@ -73,7 +73,7 @@ final class StatusBar( thunk: Future[T], onCancel: () => Unit = () => (), ): Future[T] = { - if (!clientConfig.slowTaskIsOn) + if (!clientConfig.slowTaskIsOn()) trackFuture(message, thunk) else { val task = client.metalsSlowTask(MetalsSlowTaskParams(message)) diff --git a/metals/src/main/scala/scala/meta/internal/metals/Tables.scala b/metals/src/main/scala/scala/meta/internal/metals/Tables.scala index 61e6accb1da..7f0a6b304a0 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Tables.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Tables.scala @@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicReference import scala.util.control.NonFatal import scala.meta.internal.builds.Digests -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.pc.InterruptException import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/TargetData.scala b/metals/src/main/scala/scala/meta/internal/metals/TargetData.scala index 8b5a18caf4d..77e01570977 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/TargetData.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/TargetData.scala @@ -11,7 +11,7 @@ import scala.collection.mutable.ListBuffer import scala.collection.mutable.{Map => MMap} import scala.meta.inputs.Input -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath import ch.epfl.scala.bsp4j.BuildTarget diff --git a/metals/src/main/scala/scala/meta/internal/metals/Warnings.scala b/metals/src/main/scala/scala/meta/internal/metals/Warnings.scala index 656ee0b1038..d4a9a887845 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Warnings.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Warnings.scala @@ -1,7 +1,7 @@ package scala.meta.internal.metals import scala.meta.internal.builds.BuildTools -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ScalaVersions._ import scala.meta.internal.metals.clients.language.MetalsStatusParams import scala.meta.internal.metals.logging.MetalsLogger.{silentInTests => logger} diff --git a/metals/src/main/scala/scala/meta/internal/metals/WorksheetDependencySources.scala b/metals/src/main/scala/scala/meta/internal/metals/WorksheetDependencySources.scala index a374f6c879f..c204c643175 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/WorksheetDependencySources.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/WorksheetDependencySources.scala @@ -3,7 +3,7 @@ package scala.meta.internal.metals import java.sql.Connection import scala.meta.internal.metals.JdbcEnrichments._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath final class WorksheetDependencySources(conn: () => Connection) { diff --git a/metals/src/main/scala/scala/meta/internal/metals/WorkspaceChoicePopup.scala b/metals/src/main/scala/scala/meta/internal/metals/WorkspaceChoicePopup.scala index 741f04ccbdb..245e6ae5d1d 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/WorkspaceChoicePopup.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/WorkspaceChoicePopup.scala @@ -37,7 +37,9 @@ class WorkspaceChoicePopup( languageClient .showMessageRequest(choicesParams()) .asScala - .map { item => currentFolders.find(_.getVisibleName == item) } + .map { item => + currentFolders.find(_.getVisibleName == item.getTitle()) + } } } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala index 01ea1b04100..f3fccd6eb69 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala @@ -15,11 +15,7 @@ import scala.util.control.NonFatal import scala.meta.internal.bsp.BuildChange import scala.meta.internal.builds.NewProjectProvider import scala.meta.internal.builds.ShellRunner -import scala.meta.internal.metals.DidFocusResult -import scala.meta.internal.metals.HoverExtParams import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.MetalsLspService -import scala.meta.internal.metals.WindowStateDidChangeParams import scala.meta.internal.metals.clients.language.ConfiguredLanguageClient import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.metals.debug.BuildTargetNotFoundException @@ -188,7 +184,7 @@ class WorkspaceLspService( def folderServices = workspaceFolders.getFolderServices val treeView: TreeViewProvider = - if (clientConfig.isTreeViewProvider) { + if (clientConfig.isTreeViewProvider()) { new MetalsTreeViewProvider( () => folderServices.map(_.treeView), languageClient, @@ -203,7 +199,7 @@ class WorkspaceLspService( statusBar, clientConfig, shellRunner, - clientConfig.icons, + clientConfig.icons(), folders.head.path, ) @@ -1031,7 +1027,7 @@ class WorkspaceLspService( ) capabilities.setCompletionProvider( new lsp4j.CompletionOptions( - clientConfig.isCompletionItemResolve, + clientConfig.isCompletionItemResolve(), List(".", "*").asJava, ) ) @@ -1113,7 +1109,7 @@ class WorkspaceLspService( } private def startHttpServer(): Unit = { - if (clientConfig.isHttpEnabled) { + if (clientConfig.isHttpEnabled()) { val host = "localhost" val port = 5031 var url = s"http://$host:$port" @@ -1138,7 +1134,7 @@ class WorkspaceLspService( () => url, languageClient.underlying, () => server.reload(), - clientConfig.icons, + clientConfig.icons(), time, sh, clientConfig, @@ -1161,14 +1157,14 @@ class WorkspaceLspService( if (shutdownPromise.compareAndSet(null, promise)) { scribe.info("shutting down Metals") try { - folderServices.foreach(_.onShutdown) + folderServices.foreach(_.onShutdown()) } catch { case NonFatal(e) => scribe.error("cancellation error", e) } finally { promise.success(()) } - if (clientConfig.isExitOnShutdown) { + if (clientConfig.isExitOnShutdown()) { System.exit(0) } promise.future.asJava diff --git a/metals/src/main/scala/scala/meta/internal/metals/WorkspaceSearchVisitor.scala b/metals/src/main/scala/scala/meta/internal/metals/WorkspaceSearchVisitor.scala index 796b86ed4cb..72cbf6bfdd1 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/WorkspaceSearchVisitor.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/WorkspaceSearchVisitor.scala @@ -5,7 +5,7 @@ import java.{util => ju} import scala.collection.mutable -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.GlobalSymbolIndex import scala.meta.internal.mtags.Symbol import scala.meta.internal.mtags.SymbolDefinition diff --git a/metals/src/main/scala/scala/meta/internal/metals/ammonite/Ammonite.scala b/metals/src/main/scala/scala/meta/internal/metals/ammonite/Ammonite.scala index 272c85e89e3..410611227b3 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ammonite/Ammonite.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ammonite/Ammonite.scala @@ -20,7 +20,7 @@ import scala.util.control.NonFatal import scala.meta.inputs.Input import scala.meta.internal.bsp.BuildChange -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals._ import scala.meta.internal.metals.ammonite.Ammonite.AmmoniteMetalsException import scala.meta.internal.metals.clients.language.ForwardingMetalsBuildClient diff --git a/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/CallHierarchyHelpers.scala b/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/CallHierarchyHelpers.scala index 932b6050f8c..d00a6f861a4 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/CallHierarchyHelpers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/CallHierarchyHelpers.scala @@ -12,6 +12,7 @@ import scala.meta.Template import scala.meta.Term import scala.meta.Tree import scala.meta.Type +import scala.meta.given import scala.meta.internal.metals.ReferenceProvider import scala.meta.internal.{semanticdb => s} import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/CallHierarchyItemBuilder.scala b/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/CallHierarchyItemBuilder.scala index 5cfae2752c1..918e6cb7a78 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/CallHierarchyItemBuilder.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/CallHierarchyItemBuilder.scala @@ -11,6 +11,7 @@ import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.semanticdb.Scala._ import scala.meta.internal.semanticdb.SymbolOccurrence import scala.meta.internal.semanticdb.TextDocument +import scala.meta.internal.semanticdb.given import scala.meta.internal.{semanticdb => s} import scala.meta.io.AbsolutePath import scala.meta.pc.CancelToken diff --git a/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/OutgoingCallsFinder.scala b/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/OutgoingCallsFinder.scala index d8fa8438215..10b7d4c4ba4 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/OutgoingCallsFinder.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/callHierarchy/OutgoingCallsFinder.scala @@ -9,6 +9,7 @@ import scala.meta.Name import scala.meta.Pat import scala.meta.Term import scala.meta.Tree +import scala.meta.given import scala.meta.internal.metals.DefinitionProvider import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.metals.ReferenceProvider @@ -73,7 +74,7 @@ class OutgoingCallsFinder( range.toLsp ) ) - case _ => false + case null => false } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/clients/language/ConfiguredLanguageClient.scala b/metals/src/main/scala/scala/meta/internal/metals/clients/language/ConfiguredLanguageClient.scala index 23d485974b4..3395338151b 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/clients/language/ConfiguredLanguageClient.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/clients/language/ConfiguredLanguageClient.scala @@ -8,7 +8,7 @@ import scala.concurrent.ExecutionContext import scala.meta.internal.decorations.PublishDecorationsParams import scala.meta.internal.metals.ClientCommands import scala.meta.internal.metals.ClientConfiguration -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.UserConfiguration import scala.meta.internal.metals.config.StatusBarState @@ -37,12 +37,12 @@ final class ConfiguredLanguageClient( } override def metalsStatus(params: MetalsStatusParams): Unit = { - if (clientConfig.statusBarState == StatusBarState.On) { + if (clientConfig.statusBarState() == StatusBarState.On) { underlying.metalsStatus(params) } else if (params.text.nonEmpty && !pendingShowMessage.get()) { - if (clientConfig.statusBarState == StatusBarState.ShowMessage) { + if (clientConfig.statusBarState() == StatusBarState.ShowMessage) { underlying.showMessage(new MessageParams(MessageType.Log, params.text)) - } else if (clientConfig.statusBarState == StatusBarState.LogMessage) { + } else if (clientConfig.statusBarState() == StatusBarState.LogMessage) { underlying.logMessage(new MessageParams(MessageType.Log, params.text)) } else { () @@ -54,7 +54,7 @@ final class ConfiguredLanguageClient( override def metalsSlowTask( params: MetalsSlowTaskParams ): CompletableFuture[MetalsSlowTaskResult] = { - if (clientConfig.slowTaskIsOn) { + if (clientConfig.slowTaskIsOn()) { underlying.metalsSlowTask(params) } else { new CompletableFuture[MetalsSlowTaskResult]() @@ -76,7 +76,8 @@ final class ConfiguredLanguageClient( override def logMessage(message: MessageParams): Unit = { if ( - clientConfig.statusBarState == StatusBarState.LogMessage && message.getType == MessageType.Log + clientConfig + .statusBarState() == StatusBarState.LogMessage && message.getType == MessageType.Log ) { // window/logMessage is reserved for the status bar so we don't publish // scribe.{info,warn,error} logs here. Users should look at .metals/metals.log instead. @@ -87,11 +88,11 @@ final class ConfiguredLanguageClient( } override def refreshModel(): CompletableFuture[Unit] = { - if (clientConfig.codeLenseRefreshSupport) + if (clientConfig.codeLenseRefreshSupport()) underlying.refreshCodeLenses.thenApply(_ => ()) else if ( - clientConfig.isExecuteClientCommandProvider && - (clientConfig.isDebuggingProvider || clientConfig.isRunProvider()) + clientConfig.isExecuteClientCommandProvider() && + (clientConfig.isDebuggingProvider() || clientConfig.isRunProvider()) ) { val params = ClientCommands.RefreshModel.toExecuteCommandParams() CompletableFuture.completedFuture(metalsExecuteClientCommand(params)) @@ -121,7 +122,7 @@ final class ConfiguredLanguageClient( override def rawMetalsInputBox( params: MetalsInputBoxParams ): CompletableFuture[RawMetalsInputBoxResult] = { - if (clientConfig.isInputBoxEnabled) { + if (clientConfig.isInputBoxEnabled()) { underlying.rawMetalsInputBox(params) } else { CompletableFuture.completedFuture( @@ -133,7 +134,7 @@ final class ConfiguredLanguageClient( override def rawMetalsQuickPick( params: MetalsQuickPickParams ): CompletableFuture[RawMetalsQuickPickResult] = { - if (clientConfig.isQuickPickProvider) { + if (clientConfig.isQuickPickProvider()) { underlying.rawMetalsQuickPick(params) } else { showMessageRequest( @@ -150,7 +151,7 @@ final class ConfiguredLanguageClient( override def metalsPublishDecorations( params: PublishDecorationsParams ): Unit = { - if (clientConfig.isDecorationProvider) { + if (clientConfig.isDecorationProvider()) { underlying.metalsPublishDecorations(params) } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/clients/language/MetalsHttpClient.scala b/metals/src/main/scala/scala/meta/internal/metals/clients/language/MetalsHttpClient.scala index d4b88568dae..3f12f8b84a1 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/clients/language/MetalsHttpClient.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/clients/language/MetalsHttpClient.scala @@ -13,7 +13,7 @@ import scala.util.Try import scala.meta.internal.decorations.PublishDecorationsParams import scala.meta.internal.io.PathIO -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.DelegatingLanguageClient import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.metals.clients.language.MetalsSlowTaskParams @@ -189,7 +189,7 @@ final class MetalsHttpClient( override def metalsPublishDecorations( params: PublishDecorationsParams ): Unit = { - if (clientConfig.isDecorationProvider) { + if (clientConfig.isDecorationProvider()) { underlying.metalsPublishDecorations(params) } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeAction.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeAction.scala index 9a1d59c2a39..4e23ef95845 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeAction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeAction.scala @@ -1,10 +1,9 @@ package scala.meta.internal.metals.codeactions -import scala.annotation.nowarn import scala.concurrent.ExecutionContext import scala.concurrent.Future -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ParametrizedCommand import scala.meta.pc.CancelToken @@ -22,7 +21,6 @@ trait CodeAction { type ActionCommand = ParametrizedCommand[CommandData] def command: Option[ActionCommand] = None - @nowarn def handleCommand(data: CommandData, token: CancelToken)(implicit ec: ExecutionContext ): Future[Unit] = Future.unit diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala index 02d5d3cdc8d..7afaa51f4be 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala @@ -6,7 +6,6 @@ import scala.concurrent.Future import scala.meta.internal.metals._ import scala.meta.internal.metals.clients.language.MetalsLanguageClient -import scala.meta.internal.metals.codeactions.CodeAction import scala.meta.internal.parsing.Trees import scala.meta.pc.CancelToken diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ConvertToNamedArguments.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ConvertToNamedArguments.scala index c6183779b04..953621d3b55 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ConvertToNamedArguments.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ConvertToNamedArguments.scala @@ -5,12 +5,11 @@ import scala.concurrent.Future import scala.meta.Term import scala.meta.Tree +import scala.meta.given import scala.meta.internal.metals.Compilers import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.metals.ServerCommands import scala.meta.internal.metals.clients.language.MetalsLanguageClient -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder import scala.meta.internal.metals.logging import scala.meta.internal.parsing.Trees import scala.meta.pc.CancelToken @@ -37,10 +36,11 @@ class ConvertToNamedArguments( token: CancelToken, )(implicit ec: ExecutionContext): Future[Unit] = { val uri = data.position.getTextDocument().getUri() + val indices = data.argIndices.asScala.map(d => Integer(d.intValue())) for { edits <- compilers.convertToNamedArguments( data.position, - data.argIndices, + indices.asJava, token, ) _ = logging.logErrorWhen( @@ -136,7 +136,7 @@ class ConvertToNamedArguments( ServerCommands .ConvertToNamedArgsRequest( position, - apply.argIndices.map(new Integer(_)).asJava, + apply.argIndices.map(new java.lang.Double(_)).asJava, ) ) diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/CreateCompanionObjectCodeAction.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/CreateCompanionObjectCodeAction.scala index edc1b248e96..40127f1c8f4 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/CreateCompanionObjectCodeAction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/CreateCompanionObjectCodeAction.scala @@ -9,10 +9,8 @@ import scala.meta.Term import scala.meta.Tree import scala.meta.inputs.Position import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ServerCommands -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath import scala.meta.pc.CancelToken diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/CreateNewSymbol.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/CreateNewSymbol.scala index ad143dfa7c5..15b03b040fc 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/CreateNewSymbol.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/CreateNewSymbol.scala @@ -3,10 +3,10 @@ package scala.meta.internal.metals.codeactions import scala.concurrent.ExecutionContext import scala.concurrent.Future -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ScalacDiagnostic import scala.meta.internal.metals.ServerCommands -import scala.meta.internal.metals.codeactions.CodeAction +import scala.meta.internal.metals._ import scala.meta.pc.CancelToken import org.eclipse.{lsp4j => l} diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ExtractRenameMember.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ExtractRenameMember.scala index bb3f56407d8..b3e56ea1e71 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ExtractRenameMember.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ExtractRenameMember.scala @@ -14,11 +14,11 @@ import scala.meta.Template import scala.meta.Term import scala.meta.Tree import scala.meta.Type +import scala.meta.given import scala.meta.internal.metals.ClientCommands -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ServerCommands import scala.meta.internal.metals.clients.language.MetalsLanguageClient -import scala.meta.internal.metals.codeactions.CodeAction import scala.meta.internal.metals.codeactions.ExtractRenameMember.CodeActionCommandNotFoundException import scala.meta.internal.metals.codeactions.ExtractRenameMember.getMemberType import scala.meta.internal.parsing.Trees diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ExtractValueCodeAction.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ExtractValueCodeAction.scala index 03b70e9a368..b356751bc3b 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ExtractValueCodeAction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ExtractValueCodeAction.scala @@ -9,11 +9,10 @@ import scala.meta.Enumerator import scala.meta.Template import scala.meta.Term import scala.meta.Tree +import scala.meta.given import scala.meta.inputs.Position import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.Trees import scala.meta.pc.CancelToken import scala.meta.tokens.Token diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/FlatMapToForComprehensionCodeAction.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/FlatMapToForComprehensionCodeAction.scala index 6dfc86312bf..31bf2b32209 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/FlatMapToForComprehensionCodeAction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/FlatMapToForComprehensionCodeAction.scala @@ -12,11 +12,10 @@ import scala.meta.Pat import scala.meta.Term import scala.meta.Tree import scala.meta.Type +import scala.meta.given import scala.meta.inputs.Position import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath import scala.meta.pc.CancelToken diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ImplementAbstractMembers.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ImplementAbstractMembers.scala index e19519db98a..b48ce153d5f 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ImplementAbstractMembers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ImplementAbstractMembers.scala @@ -4,9 +4,9 @@ import scala.concurrent.ExecutionContext import scala.concurrent.Future import scala.meta.internal.metals.Compilers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ScalacDiagnostic -import scala.meta.internal.metals.codeactions.CodeAction +import scala.meta.internal.metals._ import scala.meta.pc.CancelToken import org.eclipse.{lsp4j => l} diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ImportMissingSymbol.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ImportMissingSymbol.scala index 286af7b1497..4b0946867ff 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/ImportMissingSymbol.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/ImportMissingSymbol.scala @@ -5,10 +5,9 @@ import scala.concurrent.Future import scala.meta.internal.metals.BuildTargets import scala.meta.internal.metals.Compilers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ScalaVersions import scala.meta.internal.metals.ScalacDiagnostic -import scala.meta.internal.metals.codeactions.CodeAction import scala.meta.pc.CancelToken import org.eclipse.{lsp4j => l} diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/InlineValueCodeAction.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/InlineValueCodeAction.scala index 30350144479..1ded0884df2 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/InlineValueCodeAction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/InlineValueCodeAction.scala @@ -12,7 +12,6 @@ import scala.meta.internal.metals.Compilers import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.metals.ServerCommands import scala.meta.internal.metals.clients.language.MetalsLanguageClient -import scala.meta.internal.metals.codeactions.CodeAction import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath import scala.meta.pc.CancelToken diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/InsertInferredType.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/InsertInferredType.scala index b48cb37b498..0b4e762ff82 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/InsertInferredType.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/InsertInferredType.scala @@ -8,12 +8,10 @@ import scala.meta.Enumerator import scala.meta.Pat import scala.meta.Term import scala.meta.internal.metals.Compilers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ScalacDiagnostic import scala.meta.internal.metals.ServerCommands import scala.meta.internal.metals.clients.language.MetalsLanguageClient -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder import scala.meta.internal.parsing.Trees import scala.meta.pc.CancelToken diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/MillifyDependencyCodeAction.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/MillifyDependencyCodeAction.scala index bca08beffd3..93cbaad71a5 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/MillifyDependencyCodeAction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/MillifyDependencyCodeAction.scala @@ -3,9 +3,9 @@ package scala.meta.internal.metals.codeactions import scala.concurrent.ExecutionContext import scala.concurrent.Future +import scala.meta.given import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.codeactions.CodeAction import scala.meta.internal.parsing.Trees import scala.meta.pc.CancelToken import scala.meta.tokens.Token._ diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/MillifyScalaCliDependencyCodeAction.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/MillifyScalaCliDependencyCodeAction.scala index 03439418283..56110a51d96 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/MillifyScalaCliDependencyCodeAction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/MillifyScalaCliDependencyCodeAction.scala @@ -3,9 +3,9 @@ package scala.meta.internal.metals.codeactions import scala.concurrent.ExecutionContext import scala.concurrent.Future +import scala.meta.given import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.codeactions.CodeAction import scala.meta.internal.metals.codeactions.MillifyScalaCliDependencyCodeAction._ import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/OrganizeImports.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/OrganizeImports.scala index 7ee6485ccba..4be3124442d 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/OrganizeImports.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/OrganizeImports.scala @@ -6,13 +6,11 @@ import scala.concurrent.Future import scala.meta.internal.metals.BuildTargets import scala.meta.internal.metals.Diagnostics import scala.meta.internal.metals.MetalsEnrichments.XtensionString -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ScalaTarget import scala.meta.internal.metals.ScalacDiagnostic import scala.meta.internal.metals.ScalafixProvider import scala.meta.internal.metals.clients.language.MetalsLanguageClient -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder import scala.meta.io.AbsolutePath import scala.meta.pc.CancelToken diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/PatternMatchRefactor.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/PatternMatchRefactor.scala index ce3802dbb57..13772740bcd 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/PatternMatchRefactor.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/PatternMatchRefactor.scala @@ -4,9 +4,7 @@ import scala.concurrent.ExecutionContext import scala.concurrent.Future import scala.meta.Term -import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath import scala.meta.pc.CancelToken diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/RewriteBracesParensCodeAction.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/RewriteBracesParensCodeAction.scala index e9f022dfc03..e7da6622ccf 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/RewriteBracesParensCodeAction.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/RewriteBracesParensCodeAction.scala @@ -5,9 +5,7 @@ import scala.concurrent.Future import scala.reflect.ClassTag import scala.meta.Term -import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.Trees import scala.meta.io.AbsolutePath import scala.meta.pc.CancelToken @@ -65,7 +63,7 @@ class RewriteBracesParensCodeAction( .getOrElse(Nil) } - private def switchFrom[L: ClassTag, R: ClassTag]( + private def switchFrom[L <: Token: ClassTag, R <: Token: ClassTag]( path: AbsolutePath, appl: Term.Apply, ): Seq[l.CodeAction] = { diff --git a/metals/src/main/scala/scala/meta/internal/metals/codeactions/StringActions.scala b/metals/src/main/scala/scala/meta/internal/metals/codeactions/StringActions.scala index 8053eb344e8..7675f51a8ab 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codeactions/StringActions.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codeactions/StringActions.scala @@ -3,10 +3,9 @@ package scala.meta.internal.metals.codeactions import scala.concurrent.ExecutionContext import scala.concurrent.Future +import scala.meta.given import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.codeactions.CodeAction -import scala.meta.internal.metals.codeactions.CodeActionBuilder +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.Trees import scala.meta.pc.CancelToken import scala.meta.tokens.Token @@ -30,7 +29,7 @@ class StringActions(buffers: Buffers) extends CodeAction { val tokenized = buffers .get(path) .flatMap(source => - Trees.defaultTokenizerDialect(source).tokenize.toOption + Trees.defaultTokenizerDialect.apply(source).tokenize.toOption ) tokenized match { case Some(tokens) => { diff --git a/metals/src/main/scala/scala/meta/internal/metals/codelenses/RunTestCodeLens.scala b/metals/src/main/scala/scala/meta/internal/metals/codelenses/RunTestCodeLens.scala index 4a80f74ef72..2ed3ebed650 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codelenses/RunTestCodeLens.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codelenses/RunTestCodeLens.scala @@ -10,7 +10,7 @@ import scala.meta.internal.metals.ClientCommands.StartDebugSession import scala.meta.internal.metals.ClientCommands.StartRunSession import scala.meta.internal.metals.ClientConfiguration import scala.meta.internal.metals.JsonParser._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.TestUserInterfaceKind import scala.meta.internal.metals.UserConfiguration import scala.meta.internal.metals.debug.BuildTargetClasses @@ -25,6 +25,7 @@ import scala.meta.internal.semanticdb.SymbolOccurrence import scala.meta.internal.semanticdb.TextDocument import scala.meta.internal.semanticdb.TypeRef import scala.meta.internal.semanticdb.ValueSignature +import scala.meta.internal.semanticdb.given import scala.meta.io.AbsolutePath import ch.epfl.scala.bsp4j.BuildTargetIdentifier @@ -279,7 +280,7 @@ final class RunTestCodeLens( ): List[l.Command] = { val data = buildTargetClasses.jvmRunEnvironment .get(target) - .zip(userConfig().usedJavaBinary) match { + .zip(userConfig().usedJavaBinary()) match { case None => main.toJson case Some((env, javaHome)) => diff --git a/metals/src/main/scala/scala/meta/internal/metals/codelenses/SuperMethodCodeLens.scala b/metals/src/main/scala/scala/meta/internal/metals/codelenses/SuperMethodCodeLens.scala index 51cab530c02..7c8e6ca614e 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codelenses/SuperMethodCodeLens.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codelenses/SuperMethodCodeLens.scala @@ -4,7 +4,7 @@ import scala.meta.internal.implementation.SuperMethodProvider import scala.meta.internal.implementation.TextDocumentWithPath import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.ClientConfiguration -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ServerCommands import scala.meta.internal.metals.UserConfiguration import scala.meta.internal.parsing.Trees @@ -87,13 +87,13 @@ final class SuperMethodCodeLens( ) => val location = new l.Location(path.toURI.toString(), range.toLsp) val command = ServerCommands.GotoPosition.toLsp(location) - command.setTitle(s"${clientConfig.icons.findsuper} ${name}") + command.setTitle(s"${clientConfig.icons().findsuper} ${name}") command } else Some { val command = ServerCommands.GotoSymbol.toLsp(symbol) - command.setTitle(s"${clientConfig.icons.findsuper} ${name}") + command.setTitle(s"${clientConfig.icons().findsuper} ${name}") command } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/codelenses/WorksheetCodeLens.scala b/metals/src/main/scala/scala/meta/internal/metals/codelenses/WorksheetCodeLens.scala index 77fc1ec460b..deb87438acf 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codelenses/WorksheetCodeLens.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codelenses/WorksheetCodeLens.scala @@ -2,14 +2,14 @@ package scala.meta.internal.metals.codelenses import scala.meta.internal.metals.ClientCommands.CopyWorksheetOutput import scala.meta.internal.metals.ClientConfiguration -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath import org.eclipse.{lsp4j => l} class WorksheetCodeLens(clientConfig: ClientConfiguration) extends CodeLens { - override def isEnabled: Boolean = clientConfig.isCopyWorksheetOutputProvider + override def isEnabled: Boolean = clientConfig.isCopyWorksheetOutputProvider() override def codeLenses( path: AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/BuildTargetClasses.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/BuildTargetClasses.scala index 6769579957f..ae371e2d05c 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/BuildTargetClasses.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/BuildTargetClasses.scala @@ -6,7 +6,7 @@ import scala.concurrent.Future import scala.meta.internal.metals.BatchedFunction import scala.meta.internal.metals.BuildTargets -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.debug.BuildTargetClasses.Classes import scala.meta.internal.semanticdb.Scala.Descriptor import scala.meta.internal.semanticdb.Scala.Symbols diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/BuildTargetClassesFinder.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/BuildTargetClassesFinder.scala index 1d13cd66872..357bac569f6 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/BuildTargetClassesFinder.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/BuildTargetClassesFinder.scala @@ -33,7 +33,7 @@ class BuildTargetClassesFinder( .classesOf(_) .mainClasses .values, - { clazz: b.ScalaMainClass => clazz.getClassName }, + { (clazz: b.ScalaMainClass) => clazz.getClassName() }, ).recoverWith { case ex => val found = ex match { // We check whether there is a main in dependencies that is not reported via BSP diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/ClientConfigurationAdapter.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/ClientConfigurationAdapter.scala index db97f3ac5bf..26cebdbe768 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/ClientConfigurationAdapter.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/ClientConfigurationAdapter.scala @@ -2,7 +2,7 @@ package scala.meta.internal.metals.debug import java.nio.file.Paths -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.SourceMapper import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProtocol.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProtocol.scala index 6538725a44f..cb987ead290 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProtocol.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProtocol.scala @@ -4,7 +4,7 @@ import scala.reflect.ClassTag import scala.util.Failure import scala.util.Try -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.debug.DebugProxy.DebugMode import com.google.gson.JsonElement diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala index e72c9df1bed..efe9cd05f15 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala @@ -33,7 +33,7 @@ import scala.meta.internal.metals.JsonParser._ import scala.meta.internal.metals.Messages import scala.meta.internal.metals.Messages.UnresolvedDebugSessionParams import scala.meta.internal.metals.MetalsBuildClient -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.MutableCancelable import scala.meta.internal.metals.ScalaTestSuites import scala.meta.internal.metals.ScalaTestSuitesDebugRequest @@ -430,7 +430,7 @@ class DebugProvider( case Success(main) if params.getTargets().size > 0 => val updatedData = buildTargetClasses.jvmRunEnvironment .get(params.getTargets().get(0)) - .zip(userConfig().usedJavaBinary) match { + .zip(userConfig().usedJavaBinary()) match { case None => main.toJson case Some((env, javaHome)) => @@ -706,7 +706,7 @@ class DebugProvider( case e @ SemanticDbNotFoundException => languageClient.metalsStatus( MetalsStatusParams( - text = s"${clientConfig.icons.alert}Build misconfiguration", + text = s"${clientConfig.icons().alert}Build misconfiguration", tooltip = e.getMessage(), command = ClientCommands.RunDoctor.id, ) diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProxy.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProxy.scala index a8fae0395cf..3ed4521a652 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProxy.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProxy.scala @@ -13,7 +13,8 @@ import scala.meta.internal.metals.Cancelable import scala.meta.internal.metals.Compilers import scala.meta.internal.metals.EmptyCancelToken import scala.meta.internal.metals.JsonParser._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.SourceMapper import scala.meta.internal.metals.StacktraceAnalyzer import scala.meta.internal.metals.StatusBar @@ -217,7 +218,7 @@ private[debug] final class DebugProxy( case message @ OutputNotification(output) if stripColor => val raw = output.getOutput() - val msgWithoutColorCodes = filerANSIColorCodes(raw) + val msgWithoutColorCodes = MetalsEnrichments.filerANSIColorCodes(raw) output.setOutput(msgWithoutColorCodes) message.setParams(output) client.consume(message) diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DotEnvFileParser.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DotEnvFileParser.scala index 4d307cd202d..b04bc4428f9 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/DotEnvFileParser.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DotEnvFileParser.scala @@ -8,7 +8,7 @@ import scala.util.matching.Regex import scala.util.matching.Regex.Groups import scala.meta.internal.io.FileIO -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath object DotEnvFileParser { diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/EndpointLogger.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/EndpointLogger.scala index 67febe12dc5..ab0e99ad946 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/EndpointLogger.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/EndpointLogger.scala @@ -60,8 +60,8 @@ final class EndpointLogger(endpoint: RemoteEndpoint, logger: PrintWriter) object EndpointLogger { sealed trait Direction - final case object Received extends Direction - final case object Sent extends Direction + case object Received extends Direction + case object Sent extends Direction private def serializer: MessageJsonHandler = { val configure: Consumer[GsonBuilder] = { gson => gson.setPrettyPrinting() } diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/SourcePathAdapter.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/SourcePathAdapter.scala index 7b04cb22b1a..1305a1c9d68 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/SourcePathAdapter.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/SourcePathAdapter.scala @@ -5,7 +5,7 @@ import java.net.URI import scala.meta.internal.io.FileIO import scala.meta.internal.metals.BuildTargets import scala.meta.internal.metals.Directories -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath import ch.epfl.scala.bsp4j.BuildTargetIdentifier diff --git a/metals/src/main/scala/scala/meta/internal/metals/doctor/Doctor.scala b/metals/src/main/scala/scala/meta/internal/metals/doctor/Doctor.scala index f1fac3106d9..17810075b7d 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/doctor/Doctor.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/doctor/Doctor.scala @@ -27,7 +27,7 @@ import scala.meta.internal.metals.Icons import scala.meta.internal.metals.JavaTarget import scala.meta.internal.metals.JdkVersion import scala.meta.internal.metals.Messages.CheckDoctor -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.MtagsResolver import scala.meta.internal.metals.PopupChoiceReset import scala.meta.internal.metals.ScalaTarget @@ -263,7 +263,7 @@ final class Doctor( selectedBuildToolMessage().foreach { case (msg, explicitChoice) => html.element("p")( _.text(msg) - .optionally(!clientConfig.isHttpEnabled && explicitChoice)( + .optionally(!clientConfig.isHttpEnabled() && explicitChoice)( _.text(" (") .link(resetChoiceCommand(PopupChoiceReset.BuildTool), "Reset") .text(")") @@ -274,7 +274,7 @@ final class Doctor( selectedImportBuildMessage().foreach { msg => html.element("p")( _.text(msg) - .optionally(!clientConfig.isHttpEnabled)( + .optionally(!clientConfig.isHttpEnabled())( _.text(" (") .link(resetChoiceCommand(PopupChoiceReset.BuildImport), "Reset") .text(")") @@ -291,7 +291,7 @@ final class Doctor( if (explicitChoice) { html.element("p")( _.text(message) - .optionally(!clientConfig.isHttpEnabled)( + .optionally(!clientConfig.isHttpEnabled())( _.text(" (") .link(resetChoiceCommand(PopupChoiceReset.BuildServer), "Reset") .text(")") diff --git a/metals/src/main/scala/scala/meta/internal/metals/doctor/HeadDoctor.scala b/metals/src/main/scala/scala/meta/internal/metals/doctor/HeadDoctor.scala index 8b6b974ab13..6d1b4343fe5 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/doctor/HeadDoctor.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/doctor/HeadDoctor.scala @@ -73,9 +73,10 @@ class HeadDoctor( val shouldDisplay = isVisibilityProvider && isVisible.get() if (shouldDisplay || !isVisibilityProvider) { if ( - clientConfig.isExecuteClientCommandProvider && !clientConfig.isHttpEnabled + clientConfig.isExecuteClientCommandProvider() && !clientConfig + .isHttpEnabled() ) { - val output = clientConfig.doctorFormat match { + val output = clientConfig.doctorFormat() match { case DoctorFormat.Json => buildTargetsJson() case DoctorFormat.Html => buildTargetsHtml() } diff --git a/metals/src/main/scala/scala/meta/internal/metals/doctor/ProblemResolver.scala b/metals/src/main/scala/scala/meta/internal/metals/doctor/ProblemResolver.scala index e3476b1edf5..f802c9cd45e 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/doctor/ProblemResolver.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/doctor/ProblemResolver.scala @@ -9,7 +9,7 @@ import scala.meta.internal.metals.JavaTarget import scala.meta.internal.metals.JdkSources import scala.meta.internal.metals.JdkVersion import scala.meta.internal.metals.Messages -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.MtagsResolver import scala.meta.internal.metals.ScalaTarget import scala.meta.internal.metals.ScalaVersions diff --git a/metals/src/main/scala/scala/meta/internal/metals/findfiles/FindTextInDependencyJars.scala b/metals/src/main/scala/scala/meta/internal/metals/findfiles/FindTextInDependencyJars.scala index a3562f396e5..3fd895bf15f 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/findfiles/FindTextInDependencyJars.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/findfiles/FindTextInDependencyJars.scala @@ -11,7 +11,7 @@ import scala.util.control.NonFatal import scala.meta.internal.io.FileIO import scala.meta.internal.metals.BuildTargets -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.PathMatcher.Nio import scala.meta.internal.metals.clients.language.MetalsInputBoxParams import scala.meta.internal.metals.clients.language.MetalsLanguageClient diff --git a/metals/src/main/scala/scala/meta/internal/metals/formatting/IndentOnPaste.scala b/metals/src/main/scala/scala/meta/internal/metals/formatting/IndentOnPaste.scala index 9756eb6aa66..ebcfc825983 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/formatting/IndentOnPaste.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/formatting/IndentOnPaste.scala @@ -1,7 +1,7 @@ package scala.meta.internal.metals.formatting import scala.util.matching.Regex -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.UserConfiguration import org.eclipse.lsp4j.Position diff --git a/metals/src/main/scala/scala/meta/internal/metals/formatting/OnTypeFormattingProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/formatting/OnTypeFormattingProvider.scala index 04b4dca3620..49f15b9e851 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/formatting/OnTypeFormattingProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/formatting/OnTypeFormattingProvider.scala @@ -2,7 +2,7 @@ package scala.meta.internal.metals.formatting import scala.meta.inputs.Input import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.UserConfiguration import scala.meta.internal.parsing.Trees import scala.meta.tokens.Tokens diff --git a/metals/src/main/scala/scala/meta/internal/metals/formatting/RangeFormattingProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/formatting/RangeFormattingProvider.scala index 2b7417aa014..4d7c84f0f92 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/formatting/RangeFormattingProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/formatting/RangeFormattingProvider.scala @@ -2,7 +2,7 @@ package scala.meta.internal.metals.formatting import scala.meta.inputs.Input import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.UserConfiguration import scala.meta.internal.parsing.Trees import scala.meta.tokens.Tokens diff --git a/metals/src/main/scala/scala/meta/internal/metals/newScalaFile/NewFileProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/newScalaFile/NewFileProvider.scala index 07bfdfa87ce..c0f43c78ef1 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/newScalaFile/NewFileProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/newScalaFile/NewFileProvider.scala @@ -10,7 +10,7 @@ import scala.util.control.NonFatal import scala.meta.internal.metals.ClientCommands import scala.meta.internal.metals.Messages.NewScalaFile -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.PackageProvider import scala.meta.internal.metals.ScalaVersionSelector import scala.meta.internal.metals.ScalaVersions @@ -18,7 +18,7 @@ import scala.meta.internal.metals.clients.language.MetalsInputBoxParams import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.metals.clients.language.MetalsQuickPickParams import scala.meta.internal.metals.newScalaFile.NewFileTypes._ -import scala.meta.internal.pc.Identifier +import scala.meta.internal.mtags.KeywordWrapper import scala.meta.io.AbsolutePath import org.eclipse.lsp4j.Location @@ -182,7 +182,8 @@ class NewFileProvider( ): Future[(AbsolutePath, Range)] = { val path = directory.getOrElse(workspace).resolve(name + ext) // name can be actually be "foo/Name", where "foo" is a folder to create - val className = Identifier.backtickWrap( + // TODO use correct wrapper + val className = KeywordWrapper.Scala2.backtickWrap( directory.getOrElse(workspace).resolve(name).filename ) val template = kind match { diff --git a/metals/src/main/scala/scala/meta/internal/metals/testProvider/BuildTargetUpdate.scala b/metals/src/main/scala/scala/meta/internal/metals/testProvider/BuildTargetUpdate.scala index b23cf4ccb14..64d54a20df5 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/testProvider/BuildTargetUpdate.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/testProvider/BuildTargetUpdate.scala @@ -1,6 +1,6 @@ package scala.meta.internal.metals.testProvider -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.io.AbsolutePath import ch.epfl.scala.bsp4j.BuildTarget diff --git a/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesIndex.scala b/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesIndex.scala index b69e21202fb..8c018863a3c 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesIndex.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesIndex.scala @@ -14,7 +14,7 @@ import org.eclipse.{lsp4j => l} final case class FullyQualifiedName(value: String) extends AnyVal final case class ClassName(value: String) extends AnyVal -private[testProvider] final case class SymbolsPerTarget private ( +private[testProvider] final case class SymbolsPerTarget( target: BuildTarget, testSymbols: TrieMap[ BuildTargetClasses.Symbol, diff --git a/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala index 5f4fbccea55..71a3f68f0a0 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala @@ -12,7 +12,7 @@ import scala.meta.internal.metals.BuildTargets import scala.meta.internal.metals.ClientCommands import scala.meta.internal.metals.ClientConfiguration import scala.meta.internal.metals.JsonParser._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ScalaTestSuiteSelection import scala.meta.internal.metals.ScalaTestSuites import scala.meta.internal.metals.SemanticdbFeatureProvider @@ -351,7 +351,7 @@ final class TestSuitesProvider( // filter out sbt builds .filterNot(_.isSbtBuild) .map { buildTarget => - SymbolsPerTarget( + SymbolsPerTarget.apply( buildTarget, buildTargetClasses.classesOf(buildTarget.getId).testClasses, ) diff --git a/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/JunitTestFinder.scala b/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/JunitTestFinder.scala index da6ea3ebae7..4a1748ed04c 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/JunitTestFinder.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/JunitTestFinder.scala @@ -2,7 +2,7 @@ package scala.meta.internal.metals.testProvider.frameworks import scala.reflect.NameTransformer -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.testProvider.TestCaseEntry import scala.meta.internal.mtags import scala.meta.internal.semanticdb.SymbolInformation diff --git a/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/MunitTestFinder.scala b/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/MunitTestFinder.scala index 2ad922a02dc..0cd2169482c 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/MunitTestFinder.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/MunitTestFinder.scala @@ -9,7 +9,7 @@ import scala.meta.Lit import scala.meta.Template import scala.meta.Term import scala.meta.Tree -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.testProvider.FullyQualifiedName import scala.meta.internal.metals.testProvider.TestCaseEntry import scala.meta.internal.metals.testProvider.frameworks.TreeUtils._ diff --git a/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/ScalatestTestFinder.scala b/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/ScalatestTestFinder.scala index 49f631be91e..8bfadfdbf4b 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/ScalatestTestFinder.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/testProvider/frameworks/ScalatestTestFinder.scala @@ -5,12 +5,11 @@ import scala.meta.Stat import scala.meta.Template import scala.meta.Term import scala.meta.Tree -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.testProvider.FullyQualifiedName import scala.meta.internal.metals.testProvider.TestCaseEntry import scala.meta.internal.metals.testProvider.frameworks.ScalatestStyle._ import scala.meta.internal.metals.testProvider.frameworks.ScalatestTestFinder._ -import scala.meta.internal.metals.testProvider.frameworks.TreeUtils import scala.meta.internal.mtags import scala.meta.internal.parsing.Trees import scala.meta.internal.semanticdb.ClassSignature @@ -114,10 +113,10 @@ object ScalatestTestFinder { ): Vector[TestCaseEntry] = { // collect all entries like test("testname") { ... } template.stats.collect { - // format: off - case Term.Apply(appl @ Term.Apply(Term.Name(funName), Lit.String(testname) :: _), _) - if style.leafMethods.contains(funName) => - // format: on + case Term.Apply( + appl @ Term.Apply(Term.Name(funName), Lit.String(testname) :: _), + _, + ) if style.leafMethods.contains(funName) => TestCaseEntry(testname, appl.pos.toLsp.toLocation(path.toURI)) }.toVector } diff --git a/metals/src/main/scala/scala/meta/internal/metals/watcher/FileWatcher.scala b/metals/src/main/scala/scala/meta/internal/metals/watcher/FileWatcher.scala index 8fc2905ee93..27ce48363fd 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/watcher/FileWatcher.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/watcher/FileWatcher.scala @@ -19,7 +19,7 @@ import scala.util.Try import scala.meta.internal.metals.BuildTargets import scala.meta.internal.metals.Cancelable import scala.meta.internal.metals.Directories -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.MetalsServerConfig import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/parsing/ClassFinder.scala b/metals/src/main/scala/scala/meta/internal/parsing/ClassFinder.scala index a6f27fc65c9..d0460c8d859 100644 --- a/metals/src/main/scala/scala/meta/internal/parsing/ClassFinder.scala +++ b/metals/src/main/scala/scala/meta/internal/parsing/ClassFinder.scala @@ -11,8 +11,8 @@ import scala.meta.Position import scala.meta.Self import scala.meta.Tree import scala.meta.Type -import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.parsing.Trees +import scala.meta.given +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.finder.ClassKind import scala.meta.internal.parsing.finder.MangledClassName import scala.meta.internal.parsing.finder.ShortClassName diff --git a/metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala b/metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala index c45fb241ec6..b32032e2c32 100644 --- a/metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala @@ -3,7 +3,7 @@ package scala.meta.internal.parsing import java.util import scala.meta._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.trees.Origin import scala.meta.transversers.SimpleTraverser diff --git a/metals/src/main/scala/scala/meta/internal/parsing/FoldingRangeExtractor.scala b/metals/src/main/scala/scala/meta/internal/parsing/FoldingRangeExtractor.scala index e0c494ae09b..e388e6e70b0 100644 --- a/metals/src/main/scala/scala/meta/internal/parsing/FoldingRangeExtractor.scala +++ b/metals/src/main/scala/scala/meta/internal/parsing/FoldingRangeExtractor.scala @@ -7,8 +7,8 @@ import scala.collection.mutable import scala.reflect.ClassTag import scala.meta._ -import scala.meta.internal.metals.MetalsEnrichments._ -import scala.meta.internal.metals.PositionSyntax._ +import scala.meta.internal.metals.MetalsEnrichments.given +import scala.meta.internal.metals.PositionSyntax.given import scala.meta.tokens.Token import org.eclipse.lsp4j.FoldingRange @@ -333,7 +333,7 @@ final class FoldingRangeExtractor( } } - private def findTermFoldStartAndAdjustment[T: ClassTag]( + private def findTermFoldStartAndAdjustment[T <: Token: ClassTag]( trailingTokens: Iterator[Token], startFoldIfEOL: Boolean, ): Option[(Int, Boolean)] = { @@ -361,7 +361,7 @@ final class FoldingRangeExtractor( } } - private def getFoldingRangeForBlockAfterKeyword[T: ClassTag]( + private def getFoldingRangeForBlockAfterKeyword[T <: Token: ClassTag]( block: Term.Block ): Option[Position] = { val firstToken = block.leadingTokens diff --git a/metals/src/main/scala/scala/meta/internal/parsing/FoldingRangeProvider.scala b/metals/src/main/scala/scala/meta/internal/parsing/FoldingRangeProvider.scala index 762e11cb607..1fe4bfea377 100644 --- a/metals/src/main/scala/scala/meta/internal/parsing/FoldingRangeProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/parsing/FoldingRangeProvider.scala @@ -6,7 +6,7 @@ import java.util.Collections import scala.meta.inputs.Input import scala.meta.inputs.Position import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.FoldingRangeProvider._ import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/parsing/JavaFoldingRangeExtractor.scala b/metals/src/main/scala/scala/meta/internal/parsing/JavaFoldingRangeExtractor.scala index 2c292cc5492..aaebec4ea2e 100644 --- a/metals/src/main/scala/scala/meta/internal/parsing/JavaFoldingRangeExtractor.scala +++ b/metals/src/main/scala/scala/meta/internal/parsing/JavaFoldingRangeExtractor.scala @@ -19,7 +19,7 @@ import com.sun.source.util.Trees import org.eclipse.lsp4j.FoldingRange import org.eclipse.lsp4j.FoldingRangeKind -final object JavaFoldingRangeExtractor { +object JavaFoldingRangeExtractor { private val spanThreshold = 2 private case class Range( diff --git a/metals/src/main/scala/scala/meta/internal/parsing/TokenEditDistance.scala b/metals/src/main/scala/scala/meta/internal/parsing/TokenEditDistance.scala index e4f9916edd7..c798fa25c99 100644 --- a/metals/src/main/scala/scala/meta/internal/parsing/TokenEditDistance.scala +++ b/metals/src/main/scala/scala/meta/internal/parsing/TokenEditDistance.scala @@ -10,7 +10,7 @@ import scala.util.Success import scala.meta.Input import scala.meta.Position -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.parsing.TokenOps.syntax._ import scala.meta.internal.{semanticdb => s} import scala.meta.tokenizers.Tokenized diff --git a/metals/src/main/scala/scala/meta/internal/parsing/TokenOps.scala b/metals/src/main/scala/scala/meta/internal/parsing/TokenOps.scala index b90ed379184..3a6c3d04f01 100644 --- a/metals/src/main/scala/scala/meta/internal/parsing/TokenOps.scala +++ b/metals/src/main/scala/scala/meta/internal/parsing/TokenOps.scala @@ -1,5 +1,6 @@ package scala.meta.internal.parsing +import scala.meta.given import scala.meta.inputs.Input import scala.meta.inputs.Position import scala.meta.tokens.Token diff --git a/metals/src/main/scala/scala/meta/internal/parsing/Trees.scala b/metals/src/main/scala/scala/meta/internal/parsing/Trees.scala index c22b2926e71..68d561b1a09 100644 --- a/metals/src/main/scala/scala/meta/internal/parsing/Trees.scala +++ b/metals/src/main/scala/scala/meta/internal/parsing/Trees.scala @@ -6,7 +6,7 @@ import scala.reflect.ClassTag import scala.meta._ import scala.meta.inputs.Position import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.Report import scala.meta.internal.metals.ReportContext import scala.meta.internal.metals.ScalaVersionSelector diff --git a/metals/src/main/scala/scala/meta/internal/remotels/RemoteLanguageServer.scala b/metals/src/main/scala/scala/meta/internal/remotels/RemoteLanguageServer.scala index a54712498e2..d86e9bb0482 100644 --- a/metals/src/main/scala/scala/meta/internal/remotels/RemoteLanguageServer.scala +++ b/metals/src/main/scala/scala/meta/internal/remotels/RemoteLanguageServer.scala @@ -12,7 +12,7 @@ import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.BuildTargets import scala.meta.internal.metals.DefinitionResult import scala.meta.internal.metals.JsonParser._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.MetalsServerConfig import scala.meta.internal.metals.ReferencesResult import scala.meta.internal.metals.UserConfiguration diff --git a/metals/src/main/scala/scala/meta/internal/rename/RenameProvider.scala b/metals/src/main/scala/scala/meta/internal/rename/RenameProvider.scala index 50ca3f5e634..9413c281ddf 100644 --- a/metals/src/main/scala/scala/meta/internal/rename/RenameProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/rename/RenameProvider.scala @@ -14,17 +14,18 @@ import scala.meta.internal.metals.ClientConfiguration import scala.meta.internal.metals.Compilations import scala.meta.internal.metals.Compilers import scala.meta.internal.metals.DefinitionProvider -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.ReferenceProvider import scala.meta.internal.metals.TextEdits import scala.meta.internal.metals.clients.language.MetalsLanguageClient +import scala.meta.internal.mtags.KeywordWrapper import scala.meta.internal.parsing.Trees -import scala.meta.internal.pc.Identifier import scala.meta.internal.semanticdb.Scala._ import scala.meta.internal.semanticdb.SelectTree import scala.meta.internal.semanticdb.SymbolOccurrence import scala.meta.internal.semanticdb.Synthetic import scala.meta.internal.semanticdb.TextDocument +import scala.meta.internal.semanticdb.given import scala.meta.internal.{semanticdb => s} import scala.meta.io.AbsolutePath import scala.meta.pc.CancelToken @@ -157,7 +158,8 @@ final class RenameProvider( if (suggestedName.isBackticked) suggestedName.stripBackticks else suggestedName - val newName = Identifier.backtickWrap(withoutBackticks) + val newName = + KeywordWrapper.Scala2.backtickWrap(withoutBackticks) def isNotRenamedSymbol( textDocument: TextDocument, @@ -274,10 +276,12 @@ final class RenameProvider( } val fileChanges = allChanges.flatten.toMap val shouldRenameInBackground = - !clientConfig.isOpenFilesOnRenameProvider || fileChanges.keySet.size >= clientConfig.renameFileThreshold + !clientConfig + .isOpenFilesOnRenameProvider() || fileChanges.keySet.size >= clientConfig + .renameFileThreshold() val (openedEdits, closedEdits) = if (shouldRenameInBackground) { - if (clientConfig.isOpenFilesOnRenameProvider) { + if (clientConfig.isOpenFilesOnRenameProvider()) { client.showMessage(fileThreshold(fileChanges.keySet.size)) } fileChanges.partition { case (path, _) => diff --git a/metals/src/main/scala/scala/meta/internal/tvp/ClasspathSymbols.scala b/metals/src/main/scala/scala/meta/internal/tvp/ClasspathSymbols.scala index fea522441c6..977efe2a230 100644 --- a/metals/src/main/scala/scala/meta/internal/tvp/ClasspathSymbols.scala +++ b/metals/src/main/scala/scala/meta/internal/tvp/ClasspathSymbols.scala @@ -16,7 +16,7 @@ import scala.meta.internal.classpath.ClasspathIndex import scala.meta.internal.io._ import scala.meta.internal.javacp.Javacp import scala.meta.internal.metacp._ -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.Time import scala.meta.internal.metals.Timer import scala.meta.internal.mtags.Symbol diff --git a/metals/src/main/scala/scala/meta/internal/tvp/ClasspathTreeView.scala b/metals/src/main/scala/scala/meta/internal/tvp/ClasspathTreeView.scala index e12d98ec5e9..23214a9bc5a 100644 --- a/metals/src/main/scala/scala/meta/internal/tvp/ClasspathTreeView.scala +++ b/metals/src/main/scala/scala/meta/internal/tvp/ClasspathTreeView.scala @@ -1,7 +1,7 @@ package scala.meta.internal.tvp import scala.meta.internal.metals.Folder -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.mtags.GlobalSymbolIndex import scala.meta.internal.mtags.Symbol import scala.meta.internal.semanticdb.Scala._ diff --git a/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala b/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala index 0036ea32cd6..d0f07728913 100644 --- a/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala @@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicBoolean import scala.collection.concurrent.TrieMap import scala.meta.dialects -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals._ import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.mtags.GlobalSymbolIndex @@ -203,7 +203,7 @@ class MetalsTreeViewProvider( TimeUnit.SECONDS, ) case TreeViewProvider.Project => - val toUpdate = trees.map(_.flushPendingProjectUpdates).collect { + val toUpdate = trees.map(_.flushPendingProjectUpdates()).collect { case Some(value) => value } if (toUpdate.nonEmpty) { diff --git a/metals/src/main/scala/scala/meta/internal/tvp/ScalacpCopyPaste.scala b/metals/src/main/scala/scala/meta/internal/tvp/ScalacpCopyPaste.scala index 7b5068f8183..6af0802ee1b 100644 --- a/metals/src/main/scala/scala/meta/internal/tvp/ScalacpCopyPaste.scala +++ b/metals/src/main/scala/scala/meta/internal/tvp/ScalacpCopyPaste.scala @@ -169,7 +169,7 @@ object ScalacpCopyPaste { val ssym = sym.ssym sbuf += ssym if (sym.isUsefulField && sym.isMutable) { - val setterSymbolName = ssym.desc.name + "_=" + val setterSymbolName = ssym.desc.name.toString + "_=" val setterSym = Symbols.Global(ssym.owner, d.Method(setterSymbolName, "()")) sbuf += setterSym diff --git a/metals/src/main/scala/scala/meta/internal/worksheets/DecorationWorksheetPublisher.scala b/metals/src/main/scala/scala/meta/internal/worksheets/DecorationWorksheetPublisher.scala index 1445c8f0693..2811b87c842 100644 --- a/metals/src/main/scala/scala/meta/internal/worksheets/DecorationWorksheetPublisher.scala +++ b/metals/src/main/scala/scala/meta/internal/worksheets/DecorationWorksheetPublisher.scala @@ -4,7 +4,7 @@ import scala.meta.internal.decorations.DecorationOptions import scala.meta.internal.decorations.PublishDecorationsParams import scala.meta.internal.decorations.ThemableDecorationAttachmentRenderOptions import scala.meta.internal.decorations.ThemableDecorationInstanceRenderOptions -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.pc.HoverMarkup import scala.meta.internal.worksheets.MdocEnrichments._ diff --git a/metals/src/main/scala/scala/meta/internal/worksheets/MdocEnrichments.scala b/metals/src/main/scala/scala/meta/internal/worksheets/MdocEnrichments.scala index b87aeb12ac3..55a089a7010 100644 --- a/metals/src/main/scala/scala/meta/internal/worksheets/MdocEnrichments.scala +++ b/metals/src/main/scala/scala/meta/internal/worksheets/MdocEnrichments.scala @@ -45,7 +45,6 @@ object MdocEnrichments { case i.DiagnosticSeverity.Info => l.DiagnosticSeverity.Information case i.DiagnosticSeverity.Warning => l.DiagnosticSeverity.Warning case i.DiagnosticSeverity.Error => l.DiagnosticSeverity.Error - case _ => l.DiagnosticSeverity.Error }, "mdoc", ) diff --git a/metals/src/main/scala/scala/meta/internal/worksheets/WorksheetProvider.scala b/metals/src/main/scala/scala/meta/internal/worksheets/WorksheetProvider.scala index f8fd8ba4871..5a5ff10d97f 100644 --- a/metals/src/main/scala/scala/meta/internal/worksheets/WorksheetProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/worksheets/WorksheetProvider.scala @@ -23,7 +23,7 @@ import scala.meta.internal.metals.Compilations import scala.meta.internal.metals.Diagnostics import scala.meta.internal.metals.Embedded import scala.meta.internal.metals.Messages -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.MutableCancelable import scala.meta.internal.metals.ScalaVersionSelector import scala.meta.internal.metals.StatusBar diff --git a/metals/src/main/scala/scala/meta/internal/worksheets/WorkspaceEditWorksheetPublisher.scala b/metals/src/main/scala/scala/meta/internal/worksheets/WorkspaceEditWorksheetPublisher.scala index 3bafadd3d7a..04704b11192 100644 --- a/metals/src/main/scala/scala/meta/internal/worksheets/WorkspaceEditWorksheetPublisher.scala +++ b/metals/src/main/scala/scala/meta/internal/worksheets/WorkspaceEditWorksheetPublisher.scala @@ -2,7 +2,7 @@ package scala.meta.internal.worksheets import scala.meta.inputs.Input import scala.meta.internal.metals.Buffers -import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsEnrichments.given import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.parsing.Trees import scala.meta.internal.pc.HoverMarkup diff --git a/mtags-java/src/main/scala/scala/meta/internal/pc/JavaHover.scala b/mtags-java/src/main/scala/scala/meta/internal/pc/JavaHover.scala index 08b8ed50b52..52d5c7cf040 100644 --- a/mtags-java/src/main/scala/scala/meta/internal/pc/JavaHover.scala +++ b/mtags-java/src/main/scala/scala/meta/internal/pc/JavaHover.scala @@ -2,7 +2,7 @@ package scala.meta.internal.pc import java.util.Optional -import scala.meta.internal.mtags.CommonMtagsEnrichments._ +import scala.meta.internal.mtags.CommonMtagsEnrichments.given import scala.meta.pc.HoverSignature import org.eclipse.lsp4j diff --git a/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala b/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala index 76c707cf5d4..55cacfe9fde 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala @@ -1,43 +1,14 @@ package scala.meta.internal.mtags -import java.net.URI -import java.net.URLDecoder -import java.nio.file.FileSystemNotFoundException -import java.nio.file.NoSuchFileException -import java.nio.file.Paths -import java.util.concurrent.CancellationException - import scala.collection.mutable import scala.reflect.internal.util.Position -import scala.util.Failure -import scala.util.Properties -import scala.util.Success -import scala.util.Try -import scala.{meta => m} -import scala.meta.internal.semanticdb.SymbolInformation.{Property => p} -import scala.meta.io.AbsolutePath import scala.meta.pc.OffsetParams import scala.meta.pc.RangeParams -import org.eclipse.lsp4j.jsonrpc.CancelChecker -import org.eclipse.{lsp4j => l} - object MtagsEnrichments extends MtagsEnrichments trait MtagsEnrichments extends ScalametaCommonEnrichments { - implicit class XtensionIteratorCollection[T](it: Iterator[T]) { - def headOption: Option[T] = { - if (it.hasNext) Some(it.next()) - else None - } - def lastOption: Option[T] = { - it.foldLeft(Option.empty[T]) { case (_, e) => - Some(e) - } - } - } - implicit class XtensionOffsetParams(params: OffsetParams) { def isDelimiter: Boolean = { params.offset() < 0 || @@ -83,149 +54,6 @@ trait MtagsEnrichments extends ScalametaCommonEnrichments { buf.result() } } - implicit class XtensionCancelChecker(token: CancelChecker) { - def isCancelled: Boolean = - try { - token.checkCanceled() - false - } catch { - case _: CancellationException => - true - } - } - implicit class XtensionSemanticdbProperties(properties: Int) { - def isEnum: Boolean = (properties & p.ENUM.value) != 0 - def isVar: Boolean = (properties & p.VAR.value) != 0 - def isVal: Boolean = (properties & p.VAL.value) != 0 - } - - implicit class XtensionToken(token: m.Token) { - def isWhiteSpaceOrComment: Boolean = - token match { - case _: m.Token.Space | _: m.Token.Tab | _: m.Token.CR | _: m.Token.LF | - _: m.Token.LFLF | _: m.Token.FF | _: m.Token.Comment | - _: m.Token.BOF | _: m.Token.EOF => - true - case _ => false - } - } - - implicit class XtensionURIMtags(value: URI) { - def toAbsolutePath: AbsolutePath = toAbsolutePath(followSymlink = true) - def toAbsolutePath(followSymlink: Boolean): AbsolutePath = { - val path = - if (value.getScheme() == "jar") - Try { - AbsolutePath(Paths.get(value)) - } match { - case Success(path) => path - case Failure(_) => - // don't close - put up with the resource staying open so all AbsolutePath methods don't have to be wrapped - m.internal.io.PlatformFileIO.newFileSystem( - value, - new java.util.HashMap[String, String]() - ) - AbsolutePath(Paths.get(value)) - } - else - AbsolutePath(Paths.get(value)) - if (followSymlink) - path.dealias - else - path - } - } - - implicit class XtensionStringMtags(value: String) { - - def stripBackticks: String = value.stripPrefix("`").stripSuffix("`") - def isBackticked: Boolean = - value.size > 1 && value.head == '`' && value.last == '`' - def toAbsolutePath: AbsolutePath = toAbsolutePath(true) - def toAbsolutePath(followSymlink: Boolean): AbsolutePath = { - - /* Windows sometimes treats % literally, but not sure if it's always the case. - * https://learn.microsoft.com/en-us/troubleshoot/windows-client/networking/url-encoding-unc-paths-not-url-decoded - * This function tries to apply different heuristics to get the proper file system. - */ - def withTryDecode(value: String)(f: String => AbsolutePath) = { - try { - if (Properties.isWin) f(URLDecoder.decode(value, "UTF-8")) - else f(value) - } catch { - // fallback to try without decoding - case _: FileSystemNotFoundException if Properties.isWin => - f(value) - // prevents infinity recursion and double check for double escaped % - case _: NoSuchFileException | _: FileSystemNotFoundException - if value.contains("%25") => - f(URLDecoder.decode(value, "UTF-8")) - } - } - - // jar schemes must have "jar:file:"" instead of "jar:file%3A" or jar file system won't recognise the URI. - // but don't overdecode as URIs may not be recognised e.g. "com-microsoft-java-debug-core-0.32.0%2B1.jar" is correct - if (value.toUpperCase.startsWith("JAR%3AFILE")) - withTryDecode(value)( - URLDecoder.decode(_, "UTF-8").toAbsolutePath(followSymlink) - ) - else if (value.toUpperCase.startsWith("JAR:FILE%3A")) - withTryDecode(value)( - URLDecoder.decode(_, "UTF-8").toAbsolutePath(followSymlink) - ) - else if (value.toUpperCase.startsWith("JAR")) { - try URI.create(value).toAbsolutePath(followSymlink) - catch { - case _: NoSuchFileException | _: FileSystemNotFoundException => - withTryDecode(value.stripPrefix("jar:"))( - new URI("jar", _, null).toAbsolutePath(followSymlink) - ) - } - } else { - val stripped = value.stripPrefix("metals:") - val percentEncoded = URIEncoderDecoder.encode(stripped) - URI.create(percentEncoded).toAbsolutePath(followSymlink) - } - } - def lastIndexBetween( - char: Char, - lowerBound: Int, - upperBound: Int - ): Int = { - val safeLowerBound = Math.max(0, lowerBound) - var index = upperBound - while (index >= safeLowerBound && value(index) != char) { - index -= 1 - } - if (index < safeLowerBound) -1 else index - } - } - - implicit class XtensionRangeLspInverse(range: l.Range) { - def toLocation(uri: URI): l.Location = new l.Location(uri.toString(), range) - } - - implicit class XtensionPositionLspInverse(pos: l.Position) { - - /** - * LSP position translated to scalameta position. Might return None if - * pos is not contained in input - * - * @param input file input the position relates to - * @return scalameta position with offset if the pos is contained in the file - */ - def toMeta(input: m.Input): Option[m.Position] = { - Try( - m.Position.Range( - input, - pos.getLine, - pos.getCharacter, - pos.getLine, - pos.getCharacter - ) - ).toOption - } - } implicit class XtensionPosition(pos: Position) { def encloses(other: Position): Boolean = diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/Keywords.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/Keywords.scala index 662edf0fe83..c6410933edf 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/Keywords.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/Keywords.scala @@ -4,7 +4,6 @@ import scala.tools.nsc.reporters.StoreReporter import scala.meta._ import scala.meta.internal.mtags.MtagsEnrichments._ -import scala.meta.internal.pc.KeywordCompletionsUtils import org.eclipse.{lsp4j => l} diff --git a/mtags/src/main/scala-3/scala/meta/internal/mtags/MtagsEnrichments.scala b/mtags/src/main/scala-3/scala/meta/internal/mtags/MtagsEnrichments.scala index 26279ae5b65..efa8b7a2031 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/mtags/MtagsEnrichments.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/mtags/MtagsEnrichments.scala @@ -29,7 +29,8 @@ import dotty.tools.dotc.util.Spans import dotty.tools.dotc.util.Spans.Span import org.eclipse.{lsp4j as l} -object MtagsEnrichments extends ScalametaCommonEnrichments: +object MtagsEnrichments extends MtagsEnrichments +trait MtagsEnrichments extends ScalametaCommonEnrichments: extension (driver: InteractiveDriver) diff --git a/mtags/src/main/scala-2/scala/meta/internal/metals/BloomFilters.scala b/mtags/src/main/scala/scala/meta/internal/metals/BloomFilters.scala similarity index 100% rename from mtags/src/main/scala-2/scala/meta/internal/metals/BloomFilters.scala rename to mtags/src/main/scala/scala/meta/internal/metals/BloomFilters.scala diff --git a/mtags/src/main/scala-2/scala/meta/internal/metals/PositionSyntax.scala b/mtags/src/main/scala/scala/meta/internal/metals/PositionSyntax.scala similarity index 93% rename from mtags/src/main/scala-2/scala/meta/internal/metals/PositionSyntax.scala rename to mtags/src/main/scala/scala/meta/internal/metals/PositionSyntax.scala index 3c10eaeae43..0176ee77b55 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/metals/PositionSyntax.scala +++ b/mtags/src/main/scala/scala/meta/internal/metals/PositionSyntax.scala @@ -1,6 +1,8 @@ package scala.meta.internal.metals import scala.meta.Position +import scala.meta.internal.inputs.XtensionInputSyntaxStructure +import scala.meta.internal.inputs.XtensionPositionFormatMessage object PositionSyntax { @@ -64,9 +66,9 @@ object PositionSyntax { def lineTextAndCaret: String = { new StringBuilder() .append("\n") - .append(pos.lineContent) + .append(XtensionPositionFormatMessage(pos).lineContent) .append("\n") - .append(pos.lineCaret) + .append(lineCaret) .toString() } def multilines: String = { diff --git a/mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala b/mtags/src/main/scala/scala/meta/internal/metals/URIEncoderDecoder.scala similarity index 95% rename from mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala rename to mtags/src/main/scala/scala/meta/internal/metals/URIEncoderDecoder.scala index 091fcad4497..db34109fd65 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala +++ b/mtags/src/main/scala/scala/meta/internal/metals/URIEncoderDecoder.scala @@ -6,7 +6,7 @@ object URIEncoderDecoder { // Currently Metals doesn't encode `:` but does decode it private val toEscape: Map[Char, String] = Set('"', '<', '>', '&', '\'', '[', ']', '{', '}', ' ', '+', '!') - .map(char => char -> ("%" + char.toHexString)) + .map(char => char -> ("%" + char.toInt.toHexString)) .toMap private val toDecode: Map[String, Char] = toEscape.map { case (k, v) => diff --git a/mtags/src/main/scala/scala/meta/internal/mtags/ScalametaCommonEnrichments.scala b/mtags/src/main/scala/scala/meta/internal/mtags/ScalametaCommonEnrichments.scala index 29968293341..b8a761ccb41 100644 --- a/mtags/src/main/scala/scala/meta/internal/mtags/ScalametaCommonEnrichments.scala +++ b/mtags/src/main/scala/scala/meta/internal/mtags/ScalametaCommonEnrichments.scala @@ -1,16 +1,21 @@ package scala.meta.internal.mtags import java.net.URI +import java.net.URLDecoder import java.nio.charset.StandardCharsets +import java.nio.file.FileSystemNotFoundException import java.nio.file.Files +import java.nio.file.NoSuchFileException import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardCopyOption import java.nio.file.StandardOpenOption +import java.util.concurrent.CancellationException import java.util.logging.Logger import scala.annotation.tailrec import scala.util.Failure +import scala.util.Properties import scala.util.Success import scala.util.Try import scala.util.control.NonFatal @@ -22,6 +27,7 @@ import scala.meta.internal.io.FileIO import scala.meta.internal.io.PathIO import scala.meta.internal.semanticdb.Language import scala.meta.internal.semanticdb.SymbolInformation.{Kind => k} +import scala.meta.internal.semanticdb.SymbolInformation.{Property => p} import scala.meta.internal.{semanticdb => s} import scala.meta.io.AbsolutePath import scala.meta.io.RelativePath @@ -526,4 +532,161 @@ trait ScalametaCommonEnrichments extends CommonMtagsEnrichments { } + implicit class XtensionToken(token: m.Token) { + def isWhiteSpaceOrComment: Boolean = + token match { + case _: m.Token.Space | _: m.Token.Tab | _: m.Token.CR | _: m.Token.LF | + _: m.Token.LFLF | _: m.Token.FF | _: m.Token.Comment | + _: m.Token.BOF | _: m.Token.EOF => + true + case _ => false + } + } + + implicit class XtensionURIMtags(value: URI) { + def toAbsolutePath: AbsolutePath = toAbsolutePath(followSymlink = true) + def toAbsolutePath(followSymlink: Boolean): AbsolutePath = { + val path = + if (value.getScheme() == "jar") + Try { + AbsolutePath(Paths.get(value)) + } match { + case Success(path) => path + case Failure(_) => + // don't close - put up with the resource staying open so all AbsolutePath methods don't have to be wrapped + m.internal.io.PlatformFileIO.newFileSystem( + value, + new java.util.HashMap[String, String]() + ) + AbsolutePath(Paths.get(value)) + } + else + AbsolutePath(Paths.get(value)) + if (followSymlink) + path.dealias + else + path + } + } + + implicit class XtensionIteratorCollection[T](it: Iterator[T]) { + def headOption: Option[T] = { + if (it.hasNext) Some(it.next()) + else None + } + def lastOption: Option[T] = { + it.foldLeft(Option.empty[T]) { case (_, e) => + Some(e) + } + } + } + + implicit class XtensionSemanticdbProperties(properties: Int) { + def isEnum: Boolean = (properties & p.ENUM.value) != 0 + def isVar: Boolean = (properties & p.VAR.value) != 0 + def isVal: Boolean = (properties & p.VAL.value) != 0 + } + + implicit class XtensionStringMtags(value: String) { + + def stripBackticks: String = value.stripPrefix("`").stripSuffix("`") + def isBackticked: Boolean = + value.size > 1 && value.head == '`' && value.last == '`' + def toAbsolutePath: AbsolutePath = toAbsolutePath(true) + def toAbsolutePath(followSymlink: Boolean): AbsolutePath = { + + /* Windows sometimes treats % literally, but not sure if it's always the case. + * https://learn.microsoft.com/en-us/troubleshoot/windows-client/networking/url-encoding-unc-paths-not-url-decoded + * This function tries to apply different heuristics to get the proper file system. + */ + def withTryDecode(value: String)(f: String => AbsolutePath) = { + try { + if (Properties.isWin) f(URLDecoder.decode(value, "UTF-8")) + else f(value) + } catch { + // fallback to try without decoding + case _: FileSystemNotFoundException if Properties.isWin => + f(value) + // prevents infinity recursion and double check for double escaped % + case _: NoSuchFileException | _: FileSystemNotFoundException + if value.contains("%25") => + f(URLDecoder.decode(value, "UTF-8")) + } + } + + // jar schemes must have "jar:file:"" instead of "jar:file%3A" or jar file system won't recognise the URI. + // but don't overdecode as URIs may not be recognised e.g. "com-microsoft-java-debug-core-0.32.0%2B1.jar" is correct + if (value.toUpperCase.startsWith("JAR%3AFILE")) + withTryDecode(value)( + URLDecoder.decode(_, "UTF-8").toAbsolutePath(followSymlink) + ) + else if (value.toUpperCase.startsWith("JAR:FILE%3A")) + withTryDecode(value)( + URLDecoder.decode(_, "UTF-8").toAbsolutePath(followSymlink) + ) + else if (value.toUpperCase.startsWith("JAR")) { + try URI.create(value).toAbsolutePath(followSymlink) + catch { + case _: NoSuchFileException | _: FileSystemNotFoundException => + withTryDecode(value.stripPrefix("jar:"))( + new URI("jar", _, null).toAbsolutePath(followSymlink) + ) + } + } else { + val stripped = value.stripPrefix("metals:") + val percentEncoded = URIEncoderDecoder.encode(stripped) + URI.create(percentEncoded).toAbsolutePath(followSymlink) + } + } + def lastIndexBetween( + char: Char, + lowerBound: Int, + upperBound: Int + ): Int = { + val safeLowerBound = Math.max(0, lowerBound) + var index = upperBound + while (index >= safeLowerBound && value(index) != char) { + index -= 1 + } + if (index < safeLowerBound) -1 else index + } + } + + implicit class XtensionPositionLspInverse(pos: l.Position) { + + /** + * LSP position translated to scalameta position. Might return None if + * pos is not contained in input + * + * @param input file input the position relates to + * @return scalameta position with offset if the pos is contained in the file + */ + def toMeta(input: m.Input): Option[m.Position] = { + Try( + m.Position.Range( + input, + pos.getLine, + pos.getCharacter, + pos.getLine, + pos.getCharacter + ) + ).toOption + } + } + + implicit class XtensionRangeLspInverse(range: l.Range) { + def toLocation(uri: URI): l.Location = new l.Location(uri.toString(), range) + } + + implicit class XtensionCancelChecker(token: l.jsonrpc.CancelChecker) { + def isCancelled: Boolean = + try { + token.checkCanceled() + false + } catch { + case _: CancellationException => + true + } + } + } diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/LogMessages.scala b/mtags/src/main/scala/scala/meta/internal/pc/LogMessages.scala similarity index 100% rename from mtags/src/main/scala-2/scala/meta/internal/pc/LogMessages.scala rename to mtags/src/main/scala/scala/meta/internal/pc/LogMessages.scala diff --git a/project/JavaPcSettings.scala b/project/JavaPcSettings.scala index 54ae3b9d89d..372ddbe58a5 100644 --- a/project/JavaPcSettings.scala +++ b/project/JavaPcSettings.scala @@ -12,7 +12,7 @@ object JavaPcSettings { prj.settings( sharedSettings, moduleName := "mtags-java", - scalaVersion := V.scala213, + scalaVersion := V.scala3, currentJavaHome := file(System.getProperty("java.home")), currentJavaVersion := { val version = System.getProperty("java.version") diff --git a/tests/cross/src/main/scala/tests/BaseExtractMethodSuite.scala b/tests/cross/src/main/scala/tests/BaseExtractMethodSuite.scala index b82d2b95381..416b00b5a31 100644 --- a/tests/cross/src/main/scala/tests/BaseExtractMethodSuite.scala +++ b/tests/cross/src/main/scala/tests/BaseExtractMethodSuite.scala @@ -10,7 +10,6 @@ import scala.meta.internal.metals.TextEdits import munit.Location import munit.TestOptions import org.eclipse.{lsp4j => l} -import tests.BaseCodeActionSuite class BaseExtractMethodSuite extends BaseCodeActionSuite { def checkEdit( diff --git a/tests/slow/src/test/scala/tests/feature/RenameCrossLspSuite.scala b/tests/slow/src/test/scala/tests/feature/RenameCrossLspSuite.scala index 1ddf2ac75cd..3b7bc50664f 100644 --- a/tests/slow/src/test/scala/tests/feature/RenameCrossLspSuite.scala +++ b/tests/slow/src/test/scala/tests/feature/RenameCrossLspSuite.scala @@ -7,45 +7,103 @@ import tests.BaseRenameLspSuite class RenameCrossLspSuite extends BaseRenameLspSuite("rename-cross") { renamed( - "scala3-outer", + "macro", """|/a/src/main/scala/a/Main.scala - | - |@main def run() = { - | <>("Mark") - | <>("Anne") + |package a + |import io.circe.generic.JsonCodec + |trait LivingBeing + |@JsonCodec sealed trait <> extends LivingBeing + |object <> { + | case object Dog extends <> + | case object Cat extends <> |} - |def <>(name : String) : Unit = { - | println(s"Hello $name") + |""".stripMargin, + "Tree", + scalaVersion = Some(V.scala213), + ) + + renamed( + "macro1", + """|/a/src/main/scala/a/Main.scala + |package a + |import io.circe.generic.JsonCodec + |trait <> + |@JsonCodec sealed trait Animal extends <> + |object Animal { + | case object Dog extends Animal + | case object Cat extends Animal |} |""".stripMargin, - newName = "greeting", - scalaVersion = Some(V.scala3), + "Tree", + scalaVersion = Some(V.scala213), ) renamed( - "scala3-extension-params", + "macro2", """|/a/src/main/scala/a/Main.scala - | - |extension (<>: String) - | def double = <> + <> - | def double2 = <> + <> - |end extension + |package a + |import io.circe.generic.JsonCodec + |@JsonCodec + |final case class <>(name: String) |""".stripMargin, - newName = "greeting", - scalaVersion = Some(V.scala3), + "Tree", + scalaVersion = Some(V.scala213), ) renamed( - "scala3-extension-params-ref", + "macro3", """|/a/src/main/scala/a/Main.scala - | - |extension (<>: String) - | def double = <> + <> - | def double2 = <> + <> - |end extension + |package a + |import io.circe.generic.JsonCodec + |trait LivingBeing + |@JsonCodec sealed trait <> extends LivingBeing + |object <>{ + | case object Dog extends <> + | case object Cat extends <> + |} + |/a/src/main/scala/a/Use.scala + |package a + |object Use { + | val dog : <> = <>.Dog + |} |""".stripMargin, - newName = "greeting", - scalaVersion = Some(V.scala3), + "Tree", + scalaVersion = Some(V.scala213), ) + renamed( + "colon-good", + """|/a/src/main/scala/a/Main.scala + |package a + |class User{ + | def <<:@@:>>(name : String) = name + |} + |object Main{ + | val user = new User() + | "" <<::>> user + |} + |""".stripMargin, + newName = "+++:", + ) + + renamed( + "apply", + """|/a/src/main/scala/a/Main.scala + |package a + |object User{ + | def <>(name : String) = name + | def apply(name : String, age: Int) = name + |} + |object Main{ + | val toRename = User##.##<<>>("abc") + |} + |""".stripMargin, + newName = "name", + ) + + override protected def libraryDependencies: List[String] = + List("org.scalatest::scalatest:3.2.12", "io.circe::circe-generic:0.14.1") + + override def scalacOptions: List[String] = List("-Ymacro-annotations") + } diff --git a/tests/slow/src/test/scala/tests/feature/SemanticTokensScala3ExpectSuite.scala b/tests/slow/src/test/scala/tests/feature/SemanticTokensScala3ExpectSuite.scala index 8bd6f4fb513..b8c59f90e38 100644 --- a/tests/slow/src/test/scala/tests/feature/SemanticTokensScala3ExpectSuite.scala +++ b/tests/slow/src/test/scala/tests/feature/SemanticTokensScala3ExpectSuite.scala @@ -21,12 +21,12 @@ import tests.TestMtagsResolver import tests.TestSemanticTokens import tests.TestingClient -class SemanticTokensScala3ExpectSuite( -) extends DirectoryExpectSuite("semanticTokens3") { - override lazy val input: InputProperties = InputProperties.scala3() +class SemanticTokensScala2ExpectSuite( +) extends DirectoryExpectSuite("semanticTokens") { + override lazy val input: InputProperties = InputProperties.scala2() private val compiler = { val resolver = new TestMtagsResolver() - resolver.resolve(V.scala3) match { + resolver.resolve(V.scala213) match { case Some(mtags: MtagsBinaries.Artifacts) => val time = new FakeTime @@ -45,7 +45,7 @@ class SemanticTokensScala3ExpectSuite( input.classpath.entries.map(_.toNIO).asJava, Nil.asJava, ) - case _ => fail(s"Could not load ${V.scala3} presentation compiler") + case _ => fail(s"Could not load ${V.scala213} presentation compiler") } } @@ -65,7 +65,7 @@ class SemanticTokensScala3ExpectSuite( val tokens = SemanticTokensProvider.provide( nodes, params, - isScala3 = true, + isScala3 = false, ) TestSemanticTokens.semanticString( diff --git a/tests/slow/src/test/scala/tests/feature/WorksheetCrossLspSuite.scala b/tests/slow/src/test/scala/tests/feature/WorksheetCrossLspSuite.scala index 6062bb91e01..185ccc7c2c2 100644 --- a/tests/slow/src/test/scala/tests/feature/WorksheetCrossLspSuite.scala +++ b/tests/slow/src/test/scala/tests/feature/WorksheetCrossLspSuite.scala @@ -5,15 +5,6 @@ import scala.meta.internal.semver.SemVer class Worksheet211LspSuite extends tests.BaseWorksheetLspSuite(V.scala211) -class Worksheet3LspSuite extends tests.BaseWorksheetLspSuite(V.scala3) { - override def versionSpecificCodeToValidate: String = - """given str: String = """"" - - override def versionSpecificScalacOptionsToValidate: List[String] = List( - "-Ycheck-reentrant" - ) -} - class LatestWorksheet3LspSuite extends tests.BaseWorksheetLspSuite( V.supportedScala3Versions @@ -26,3 +17,59 @@ class LatestWorksheet3LspSuite } class Worksheet212LspSuite extends tests.BaseWorksheetLspSuite(V.scala212) + +class Worksheet213LspSuite extends tests.BaseWorksheetLspSuite(V.scala213) { + + test("akka") { + cleanWorkspace() + val path = "hi.worksheet.sc" + for { + _ <- initialize( + s""" + |/metals.json + |{ + | "a": {} + |} + |/${path} + |import $$dep.`com.typesafe.akka::akka-stream:2.6.13` + | + |import akka.actor.ActorSystem + |import akka.NotUsed + |import akka.stream.scaladsl.Source + |import akka.stream.scaladsl.Sink + |import java.io.File + |import scala.concurrent.Await + |import scala.concurrent.duration.DurationInt + | + | + |implicit val system: ActorSystem = ActorSystem("QuickStart") + |val source: Source[Int, NotUsed] = Source(1 to 2) + |val future = source.runWith(Sink.foreach(_ => ())) + |Await.result(future, 3.seconds) + | + |""".stripMargin + ) + _ <- server.didOpen(path) + _ = assertNoDiff( + // it seems that part of the string is always different, so let's remove it + client.workspaceDecorations.replaceAll(".out\\(.*", ".out(..."), + """|import $dep.`com.typesafe.akka::akka-stream:2.6.13` + | + |import akka.actor.ActorSystem + |import akka.NotUsed + |import akka.stream.scaladsl.Source + |import akka.stream.scaladsl.Sink + |import java.io.File + |import scala.concurrent.Await + |import scala.concurrent.duration.DurationInt + | + | + |implicit val system: ActorSystem = ActorSystem("QuickStart") // : ActorSystem = akka://QuickStart + |val source: Source[Int, NotUsed] = Source(1 to 2) // : Source[Int, NotUsed] = Source(SourceShape(StatefulMapConcat.out(... + |val future = source.runWith(Sink.foreach(_ => ())) // : concurrent.Future[akka.Done] = Future(Success(Done)) + |Await.result(future, 3.seconds) // : akka.Done = Done + |""".stripMargin, + ) + } yield () + } +} diff --git a/tests/slow/src/test/scala/tests/sbt/SbtServerSuite.scala b/tests/slow/src/test/scala/tests/sbt/SbtServerSuite.scala index 0014a351c8b..831500ff2c9 100644 --- a/tests/slow/src/test/scala/tests/sbt/SbtServerSuite.scala +++ b/tests/slow/src/test/scala/tests/sbt/SbtServerSuite.scala @@ -107,7 +107,7 @@ class SbtServerSuite test("reload plugins") { // should reload existing server after writing the metals.sbt plugin file - cleanWorkspace + cleanWorkspace() val layout = SbtBuildLayout("", V.scala213) writeLayout(layout) assert(workspace.exists) @@ -121,7 +121,7 @@ class SbtServerSuite sbtProcess.complete } for { - code <- startSbtServer + code <- startSbtServer() _ = assert(code == 0) _ = assert(workspace.resolve(".bsp/sbt.json").exists) _ <- initializer.initialize(workspace, server, client, false) diff --git a/tests/unit/src/main/scala/bill/Bill.scala b/tests/unit/src/main/scala/bill/Bill.scala index e2ab884d344..9f775e7c449 100644 --- a/tests/unit/src/main/scala/bill/Bill.scala +++ b/tests/unit/src/main/scala/bill/Bill.scala @@ -20,12 +20,6 @@ import scala.concurrent.Await import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.concurrent.duration.Duration -import scala.reflect.internal.util.BatchSourceFile -import scala.reflect.internal.{util => r} -import scala.reflect.io.AbstractFile -import scala.reflect.io.VirtualFile -import scala.tools.nsc -import scala.tools.nsc.reporters.StoreReporter import scala.util.Try import scala.util.control.NonFatal @@ -35,6 +29,7 @@ import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.metals.PositionSyntax._ import scala.meta.internal.metals.RecursivelyDelete import scala.meta.internal.mtags +import scala.meta.internal.pc.ScalaPresentationCompiler import scala.meta.io.AbsolutePath import ch.epfl.scala.bsp4j._ @@ -42,6 +37,12 @@ import ch.epfl.scala.{bsp4j => b} import com.google.gson.GsonBuilder import coursierapi.Dependency import coursierapi.Fetch +import dotty.tools.dotc.interfaces.Diagnostic as DottyDiagnostic +import dotty.tools.dotc.reporting.StoreReporter +import dotty.tools.dotc.util.SourceFile +import dotty.tools.dotc.util.SourcePosition +import dotty.tools.dotc.util.Spans +import dotty.tools.io.AbstractFile import org.eclipse.lsp4j.jsonrpc.Launcher /** @@ -138,17 +139,11 @@ object Bill { result.setData(scalaTarget) result } - val reporter = new StoreReporter val out: AbsolutePath = AbsolutePath(workspace.resolve("out.jar")) Files.createDirectories(out.toNIO.getParent()) - lazy val g: nsc.Global = { - val settings = new nsc.Settings() - settings.classpath.value = - myClasspath.map(_.toString).mkString(File.pathSeparator) - settings.Yrangepos.value = true - settings.d.value = out.toString - new nsc.Global(settings, reporter) - } + lazy val driver = + ScalaPresentationCompiler(classpath = myClasspath).newDriver + lazy val reporter = driver.currentCtx.reporter.asInstanceOf[StoreReporter] override def buildInitialize( params: InitializeBuildParams @@ -258,7 +253,9 @@ object Bill { private val hasError = mutable.Set.empty[AbstractFile] def publishDiagnostics(): Unit = { - val byFile = reporter.infos.groupBy(_.pos.source.file) + val byFile = reporter + .pendingMessages(using driver.currentCtx) + .groupBy(_.pos.source.file) val fixedErrors = hasError.filterNot(byFile.contains) fixedErrors.foreach { file => client.onBuildPublishDiagnostics( @@ -272,27 +269,28 @@ object Bill { } hasError --= fixedErrors byFile.foreach { case (file, infos) => - def toBspPos(pos: r.Position, offset: Int): b.Position = { + def toBspPos(pos: SourcePosition, offset: Int): b.Position = { val line = pos.source.offsetToLine(offset) val column0 = pos.source.lineToOffset(line) val column = offset - column0 new b.Position(line, column) } val diagnostics = infos.iterator - .filter(_.pos.isDefined) + .filter(_.pos.span != Spans.NoSpan) .map { info => val p = info.pos val start = - toBspPos(info.pos, if (p.isRange) p.start else p.point) + toBspPos(info.pos, if (p.span.isZeroExtent) p.point else p.start) val end = - toBspPos(info.pos, if (p.isRange) p.end else p.point) - val severity = info.severity match { - case reporter.ERROR => DiagnosticSeverity.ERROR - case reporter.WARNING => DiagnosticSeverity.WARNING - case reporter.INFO => DiagnosticSeverity.INFORMATION + toBspPos(info.pos, if (p.span.isZeroExtent) p.point else p.end) + val severity = info.level match { + case DottyDiagnostic.ERROR => DiagnosticSeverity.ERROR + case DottyDiagnostic.WARNING => DiagnosticSeverity.WARNING + case DottyDiagnostic.INFO => DiagnosticSeverity.INFORMATION case _ => DiagnosticSeverity.HINT } - val diagnostic = new Diagnostic(new b.Range(start, end), info.msg) + val diagnostic = + new Diagnostic(new b.Range(start, end), info.message) diagnostic.setSeverity(severity) diagnostic } @@ -314,27 +312,22 @@ object Bill { params: CompileParams ): CompletableFuture[CompileResult] = { CompletableFuture.completedFuture { - reporter.reset() - val run = new g.Run() - val sources: List[BatchSourceFile] = - if (Files.isDirectory(src)) { - Files - .walk(src) - .collect(Collectors.toList()) - .asScala - .iterator - .filter(_.getFileName.toString.endsWith(".scala")) - .map(path => { - val text = - new String(Files.readAllBytes(path), StandardCharsets.UTF_8) - val chars = text.toCharArray - new BatchSourceFile(new VirtualFile(path.toUri.toString), chars) - }) - .toList - } else { - Nil - } - run.compileSources(sources) + if (Files.isDirectory(src)) { + Files + .walk(src) + .collect(Collectors.toList()) + .asScala + .iterator + .filter(_.getFileName.toString.endsWith(".scala")) + .flatMap(path => { + val text = + new String(Files.readAllBytes(path), StandardCharsets.UTF_8) + val source = SourceFile.virtual(path.toString, text) + + driver.run(path.toUri, source) + }) + .toList + } publishDiagnostics() val exit = if (reporter.hasErrors) StatusCode.ERROR diff --git a/tests/unit/src/main/scala/scala/meta/internal/metals/debug/Debugger.scala b/tests/unit/src/main/scala/scala/meta/internal/metals/debug/Debugger.scala index 8187b2ceb63..c75dcbd4d97 100644 --- a/tests/unit/src/main/scala/scala/meta/internal/metals/debug/Debugger.scala +++ b/tests/unit/src/main/scala/scala/meta/internal/metals/debug/Debugger.scala @@ -117,9 +117,6 @@ final class Debugger(server: RemoteServer)(implicit ec: ExecutionContext) { callback(completions) step(threadId, DebugStep.Continue) } - case cause => - val error = s"Unsupported debug step $cause" - Future.failed(new IllegalStateException(error)) } } diff --git a/tests/unit/src/main/scala/tests/BaseAnalyzeStacktraceSuite.scala b/tests/unit/src/main/scala/tests/BaseAnalyzeStacktraceSuite.scala index fde1cab9837..7bd910d7282 100644 --- a/tests/unit/src/main/scala/tests/BaseAnalyzeStacktraceSuite.scala +++ b/tests/unit/src/main/scala/tests/BaseAnalyzeStacktraceSuite.scala @@ -34,7 +34,7 @@ abstract class BaseAnalyzeStacktraceSuite(name: String) code: String, stacktrace: String, filename: String = "Main.scala", - scalaVersion: String = V.scala213, + scalaVersion: String = V.scala3, dependency: String = "", )(implicit loc: munit.Location): Unit = { val locationParser = new JsonParser.Of[l.Location] diff --git a/tests/unit/src/main/scala/tests/BaseLspSuite.scala b/tests/unit/src/main/scala/tests/BaseLspSuite.scala index fa3ad165e07..85d7e83e2eb 100644 --- a/tests/unit/src/main/scala/tests/BaseLspSuite.scala +++ b/tests/unit/src/main/scala/tests/BaseLspSuite.scala @@ -180,12 +180,15 @@ abstract class BaseLspSuite( } override def beforeEach(context: BeforeEach): Unit = { - cancelServer() if (context.test.tags.contains(Ignore)) return useVirtualDocs = context.test.tags.contains(TestingServer.virtualDocTag) newServer(context.test.name) } + override def afterEach(context: AfterEach): Unit = { + cancelServer() + } + protected def createWorkspace(name: String): AbsolutePath = { val pathToSuite = PathIO.workingDirectory .resolve("target") diff --git a/tests/unit/src/main/scala/tests/BaseRenameLspSuite.scala b/tests/unit/src/main/scala/tests/BaseRenameLspSuite.scala index 78216404dbf..f47eaa4ec77 100644 --- a/tests/unit/src/main/scala/tests/BaseRenameLspSuite.scala +++ b/tests/unit/src/main/scala/tests/BaseRenameLspSuite.scala @@ -2,7 +2,8 @@ package tests import scala.concurrent.Future -import scala.meta.internal.pc.Identifier +import scala.meta.internal.metals.ScalaVersions +import scala.meta.internal.mtags.KeywordWrapper import munit.Location import munit.TestOptions @@ -11,6 +12,7 @@ abstract class BaseRenameLspSuite(name: String) extends BaseLspSuite(name) { protected def libraryDependencies: List[String] = Nil protected def compilerPlugins: List[String] = Nil + protected def scalacOptions: List[String] = Nil def same( name: String, @@ -64,7 +66,12 @@ abstract class BaseRenameLspSuite(name: String) extends BaseLspSuite(name) { cleanWorkspace() val allMarkersRegex = "(<<|>>|@@|##.*##)" val files = FileLayout.mapFromString(input) - val expectedName = Identifier.backtickWrap(newName) + val actualScalaVersion = scalaVersion.getOrElse(BuildInfo.scalaVersion) + val expectedName = + if (ScalaVersions.isScala3Version(actualScalaVersion)) + KeywordWrapper.Scala3.backtickWrap(newName) + else + KeywordWrapper.Scala2.backtickWrap(newName) val expectedFiles = files.map { case (file, code) => fileRenames.getOrElse(file, file) -> { val expected = if (!notRenamed) { @@ -128,7 +135,7 @@ abstract class BaseRenameLspSuite(name: String) extends BaseLspSuite(name) { | "scalaVersion": "$actualScalaVersion", | "compilerPlugins": ${toJsonArray(compilerPlugins)}, | "libraryDependencies": ${toJsonArray(libraryDependencies)}, - | "scalacOptions" : ["-Ymacro-annotations"] + | "scalacOptions" : ${toJsonArray(scalacOptions)} | }, | "b" : { | "scalaVersion": "$actualScalaVersion", diff --git a/tests/unit/src/main/scala/tests/BaseWorksheetLspSuite.scala b/tests/unit/src/main/scala/tests/BaseWorksheetLspSuite.scala index ecaadc3f0ed..e9613af03ab 100644 --- a/tests/unit/src/main/scala/tests/BaseWorksheetLspSuite.scala +++ b/tests/unit/src/main/scala/tests/BaseWorksheetLspSuite.scala @@ -701,11 +701,11 @@ abstract class BaseWorksheetLspSuite( ) _ <- server.didOpen("a/src/main/scala/foo/Main.worksheet.sc") _ <- server.didSave("a/src/main/scala/foo/Main.worksheet.sc")(identity) - export = server.exportEvaluation( + exportedEvaluation = server.exportEvaluation( "a/src/main/scala/foo/Main.worksheet.sc" ) _ = assertEquals( - export, + exportedEvaluation, Some( getExpected( """| @@ -750,11 +750,11 @@ abstract class BaseWorksheetLspSuite( "Hi(7, 8, 9)", ) ) - export = server.exportEvaluation( + exportedEvaluation = server.exportEvaluation( "a/src/main/scala/foo/Main.worksheet.sc" ) _ = assertEquals( - export, + exportedEvaluation, Some( getExpected( """| diff --git a/tests/unit/src/main/scala/tests/BuildServerInitializer.scala b/tests/unit/src/main/scala/tests/BuildServerInitializer.scala index 0427f1db0ab..c3abe1f50ac 100644 --- a/tests/unit/src/main/scala/tests/BuildServerInitializer.scala +++ b/tests/unit/src/main/scala/tests/BuildServerInitializer.scala @@ -32,7 +32,6 @@ sealed trait BuildServerInitializer { * This will take your `metals.json` file and quickly produce `.bloop/` files from it. */ object QuickBuildInitializer extends BuildServerInitializer { - this: BaseLspSuite => override def initialize( workspace: AbsolutePath, server: TestingServer, @@ -61,7 +60,6 @@ object QuickBuildInitializer extends BuildServerInitializer { * run Bloop Install via the build tool being used. */ object BloopImportInitializer extends BuildServerInitializer { - this: BaseLspSuite => override def initialize( workspace: AbsolutePath, server: TestingServer, @@ -89,7 +87,6 @@ object BloopImportInitializer extends BuildServerInitializer { * with sbt as the build server. */ object SbtServerInitializer extends BuildServerInitializer { - this: BaseLspSuite => override def initialize( workspace: AbsolutePath, server: TestingServer, @@ -157,7 +154,6 @@ object SbtServerInitializer extends BuildServerInitializer { } object MillServerInitializer extends BuildServerInitializer { - this: BaseLspSuite => override def initialize( workspace: AbsolutePath, server: TestingServer, diff --git a/tests/unit/src/main/scala/tests/Library.scala b/tests/unit/src/main/scala/tests/Library.scala index a284ec4ba6d..6841ec354d3 100644 --- a/tests/unit/src/main/scala/tests/Library.scala +++ b/tests/unit/src/main/scala/tests/Library.scala @@ -5,7 +5,7 @@ import scala.collection.JavaConverters._ import scala.meta.internal.metals.JdkSources import scala.meta.internal.metals.PackageIndex import scala.meta.internal.metals.ScalaVersions -import scala.meta.internal.mtags +import scala.meta.internal.metals.{BuildInfo => V} import scala.meta.io.AbsolutePath import scala.meta.io.Classpath @@ -60,7 +60,6 @@ object Library { .filter(_.toString.endsWith("bindings-rxjava-2.0.0-sources.jar")) def allScala2: List[Library] = { - import mtags.BuildInfo.scalaCompilerVersion val dependencies = List( Dependency.of("com.lihaoyi", "acyclic_2.12", "0.1.8"), @@ -75,7 +74,7 @@ object Library { Dependency.of("org.apache.spark", "spark-sql_2.11", "2.2.1"), Dependency.of("org.eclipse.jetty", "jetty-servlet", "9.3.11.v20160721"), Dependency.of("org.scalameta", "scalameta_2.12", "4.1.4"), - Dependency.of("org.scala-lang", "scala-compiler", scalaCompilerVersion), + Dependency.of("org.scala-lang", "scala-compiler", V.scala213), ) List(fetchSources("scala2-suite", dependencies)) } diff --git a/tests/unit/src/main/scala/tests/QuickBuild.scala b/tests/unit/src/main/scala/tests/QuickBuild.scala index ebe1aa15b52..95a6ea3e75d 100644 --- a/tests/unit/src/main/scala/tests/QuickBuild.scala +++ b/tests/unit/src/main/scala/tests/QuickBuild.scala @@ -75,7 +75,7 @@ case class QuickBuild( def withId(id: String): QuickBuild = QuickBuild( id, - if (scalaVersion == null) V.scala213 + if (scalaVersion == null) V.scala3 else scalaVersion, orEmpty(libraryDependencies), orEmpty(compilerPlugins), @@ -354,7 +354,7 @@ object QuickBuild { val newDigest = { val digest = MessageDigest.getInstance("MD5") digest.update(version.getBytes(StandardCharsets.UTF_8)) - digest.update(V.scala213.getBytes(StandardCharsets.UTF_8)) + digest.update(V.scala3.getBytes(StandardCharsets.UTF_8)) def update(file: AbsolutePath): Unit = { if (file.isFile) { digest.update(file.readAllBytes) diff --git a/tests/unit/src/main/scala/tests/TestingClient.scala b/tests/unit/src/main/scala/tests/TestingClient.scala index 71afd975181..73859622663 100644 --- a/tests/unit/src/main/scala/tests/TestingClient.scala +++ b/tests/unit/src/main/scala/tests/TestingClient.scala @@ -102,20 +102,20 @@ class TestingClient(workspace: AbsolutePath, val buffers: Buffers) val decorations = new ConcurrentHashMap[AbsolutePath, Set[PublishDecorationsParams]]() var slowTaskHandler: MetalsSlowTaskParams => Option[MetalsSlowTaskResult] = { - _: MetalsSlowTaskParams => None + (_: MetalsSlowTaskParams) => None } - var showMessageHandler: MessageParams => Unit = { _: MessageParams => + var showMessageHandler: MessageParams => Unit = { (_: MessageParams) => () } var showMessageRequestHandler : ShowMessageRequestParams => Option[MessageActionItem] = { - _: ShowMessageRequestParams => None + (_: ShowMessageRequestParams) => None } var inputBoxHandler: MetalsInputBoxParams => RawMetalsInputBoxResult = { - _: MetalsInputBoxParams => RawMetalsInputBoxResult(cancelled = true) + (_: MetalsInputBoxParams) => RawMetalsInputBoxResult(cancelled = true) } var quickPickHandler: MetalsQuickPickParams => RawMetalsQuickPickResult = { - _: MetalsQuickPickParams => RawMetalsQuickPickResult(cancelled = true) + (_: MetalsQuickPickParams) => RawMetalsQuickPickResult(cancelled = true) } private val refreshCount = new AtomicInteger diff --git a/tests/unit/src/main/scala/tests/TestingServer.scala b/tests/unit/src/main/scala/tests/TestingServer.scala index 8ebfb7607c2..08240d34ed1 100644 --- a/tests/unit/src/main/scala/tests/TestingServer.scala +++ b/tests/unit/src/main/scala/tests/TestingServer.scala @@ -1039,7 +1039,7 @@ final case class TestingServer( // or fails if it could nat be achieved withing [[maxRetries]] number of tries var retries = maxRetries val codeLenses = Promise[List[l.CodeLens]]() - val handler = { refreshCount: Int => + val handler = { (refreshCount: Int) => if (refreshCount > 0) for { lenses <- fullServer.codeLens(params).asScala.map(_.asScala) diff --git a/tests/unit/src/main/scala/tests/WorkspaceSymbolReferences.scala b/tests/unit/src/main/scala/tests/WorkspaceSymbolReferences.scala index c900bdf2c81..ec641e8c9b0 100644 --- a/tests/unit/src/main/scala/tests/WorkspaceSymbolReferences.scala +++ b/tests/unit/src/main/scala/tests/WorkspaceSymbolReferences.scala @@ -1,5 +1,7 @@ package tests +import scala.meta.internal.inputs.XtensionInputSyntaxStructure + import munit.internal.difflib.Diffs case class WorkspaceSymbolReferences( diff --git a/tests/unit/src/main/scala/tests/codeactions/BaseCodeActionLspSuite.scala b/tests/unit/src/main/scala/tests/codeactions/BaseCodeActionLspSuite.scala index 5d59d19dbfb..ce1ed4df412 100644 --- a/tests/unit/src/main/scala/tests/codeactions/BaseCodeActionLspSuite.scala +++ b/tests/unit/src/main/scala/tests/codeactions/BaseCodeActionLspSuite.scala @@ -15,7 +15,7 @@ abstract class BaseCodeActionLspSuite( suiteName: String ) extends BaseLspSuite(suiteName) { - protected val scalaVersion: String = V.scala213 + protected val scalaVersion: String = V.scala3 def checkNoAction( name: TestOptions, diff --git a/tests/unit/src/main/scala/tests/debug/BaseStackFrameDapSuite.scala b/tests/unit/src/main/scala/tests/debug/BaseStackFrameDapSuite.scala index 1aff518ed63..f9be84cefce 100644 --- a/tests/unit/src/main/scala/tests/debug/BaseStackFrameDapSuite.scala +++ b/tests/unit/src/main/scala/tests/debug/BaseStackFrameDapSuite.scala @@ -134,13 +134,17 @@ abstract class BaseStackFrameDapSuite( | } |}""".stripMargin, expectedFrames = List( + inScopeLocal( + assertNoDiff(_, "args: String[]"), + assertNoDiff(_, "this: Main$"), + ), inScopeLocal( assertNoDiff(_, "value: int = 1"), - assertNoDiff(_, "MODULE$: Main$"), + assertNoDiff(_, "this: Main$"), ), inScopeLocal( assertNoDiff(_, "value: int = 2"), - assertNoDiff(_, "MODULE$: Main$"), + assertNoDiff(_, "this: Main$"), ), ), ) @@ -158,23 +162,28 @@ abstract class BaseStackFrameDapSuite( |} |""".stripMargin, expectedFrames = List( + inScopeLocal( + assertNoDiff(_, "args: String[]"), + assertNoDiff(_, "this: Main$"), + ), // before calculating `z` inScopeLocal( assertNoDiff(_, "x: int = 1"), - assertNoDiff(_, "MODULE$: Main$"), + assertNoDiff(_, "this: Main$"), ), // after calculating `z` inScopeLocal( assertNoDiff(_, "x: int = 1"), assertNoDiff(_, "z: int = 3"), - assertNoDiff(_, "MODULE$: Main$"), + assertNoDiff(_, "this: Main$"), ), inScopeLocal( v => { assert(v.contains("x$1: Tuple2$mcII$sp")) assert(v.contains("\"(1,3)\"")) }, - assertNoDiff(_, "MODULE$: Main$"), + assertNoDiff(_, "x: int = 1"), + assertNoDiff(_, "this: Main$"), ), ), ) diff --git a/tests/unit/src/test/scala/tests/BuildTargetsLspSuite.scala b/tests/unit/src/test/scala/tests/BuildTargetsLspSuite.scala index 3fe7d8b7c2c..339c1a21cfe 100644 --- a/tests/unit/src/test/scala/tests/BuildTargetsLspSuite.scala +++ b/tests/unit/src/test/scala/tests/BuildTargetsLspSuite.scala @@ -18,7 +18,7 @@ class BuildTargetsLspSuite | }, | "b": { | "scalaVersion": "${BuildInfo.scalaVersion}", - | "libraryDependencies": ["com.lihaoyi::sourcecode:0.1.7"], + | "libraryDependencies": ["com.lihaoyi::sourcecode:0.2.7"], | "additionalSources": [ "shared/Main.scala" ] | } |} diff --git a/tests/unit/src/test/scala/tests/CascadeLspSuite.scala b/tests/unit/src/test/scala/tests/CascadeLspSuite.scala index 160ddeb4899..a3d342ecfab 100644 --- a/tests/unit/src/test/scala/tests/CascadeLspSuite.scala +++ b/tests/unit/src/test/scala/tests/CascadeLspSuite.scala @@ -37,12 +37,11 @@ class CascadeLspSuite extends BaseLspSuite("cascade") { // but not independent project "c". _ = assertNoDiff( client.workspaceDiagnostics, - """|b/src/main/scala/b/B.scala:3:19: error: type mismatch; - | found : Int - | required: String + """|b/src/main/scala/b/B.scala:3:19: error: Found: (a.A.n : Int) + |Required: String | val n: String = a.A.n - | ^^^^^ - """.stripMargin, + | ^ + |""".stripMargin, ) } yield () } diff --git a/tests/unit/src/test/scala/tests/CompletionLspSuite.scala b/tests/unit/src/test/scala/tests/CompletionLspSuite.scala index e6853715246..2d6ab2999ad 100644 --- a/tests/unit/src/test/scala/tests/CompletionLspSuite.scala +++ b/tests/unit/src/test/scala/tests/CompletionLspSuite.scala @@ -11,7 +11,7 @@ class CompletionLspSuite extends BaseCompletionLspSuite("completion") { override def munitIgnore: Boolean = isWindows test("basic-213") { - basicTest(V.scala213) + basicTest(V.scala3) } test("workspace".flaky) { diff --git a/tests/unit/src/test/scala/tests/DebugDiscoverySuite.scala b/tests/unit/src/test/scala/tests/DebugDiscoverySuite.scala index a5d7391649c..e8e96893fe5 100644 --- a/tests/unit/src/test/scala/tests/DebugDiscoverySuite.scala +++ b/tests/unit/src/test/scala/tests/DebugDiscoverySuite.scala @@ -297,7 +297,7 @@ class DebugDiscoverySuite } test("invalid-env") { - val fakePath = workspace + "fake-path" + val fakePath = workspace.toString + "fake-path" for { _ <- initialize( diff --git a/tests/unit/src/test/scala/tests/DidFocusLspSuite.scala b/tests/unit/src/test/scala/tests/DidFocusLspSuite.scala index 830e7564334..8edcc662901 100644 --- a/tests/unit/src/test/scala/tests/DidFocusLspSuite.scala +++ b/tests/unit/src/test/scala/tests/DidFocusLspSuite.scala @@ -117,9 +117,8 @@ class DidFocusWhileCompilingLspSuite _ <- server.didOpen("b/src/main/scala/b/B.scala") _ = assertNoDiagnostics() xMismatch = { - """|a/src/main/scala/a/A.scala:3:16: error: type mismatch; - | found : String("") - | required: Int + """|a/src/main/scala/a/A.scala:3:16: error: Found: ("" : String) + |Required: Int | val x: Int = "" | ^^ |""".stripMargin @@ -154,9 +153,8 @@ class DidFocusWhileCompilingLspSuite ) _ = assertNoDiff( client.workspaceDiagnostics, - """|b/src/main/scala/b/B.scala:3:16: error: type mismatch; - | found : String("") - | required: Int + """|b/src/main/scala/b/B.scala:3:16: error: Found: ("" : String) + |Required: Int | val y: Int = "" | ^^ |""".stripMargin, diff --git a/tests/unit/src/test/scala/tests/FindTextInDependencyJarsSuite.scala b/tests/unit/src/test/scala/tests/FindTextInDependencyJarsSuite.scala index cc6acd57d44..541a988925b 100644 --- a/tests/unit/src/test/scala/tests/FindTextInDependencyJarsSuite.scala +++ b/tests/unit/src/test/scala/tests/FindTextInDependencyJarsSuite.scala @@ -52,16 +52,16 @@ class FindTextInDependencyJarsSuite s"""| |akka-actor_2.12-${akkaVersion}.jar/reference.conf:96:3: info: result | jvm-shutdown-hooks = on - | ^^^^^^^^^^^^^^^^^^ + | ^ |akka-actor_2.12-${akkaVersion}.jar/reference.conf:1178:41: info: result | # This property is related to `akka.jvm-shutdown-hooks` above. - | ^^^^^^^^^^^^^^^^^^ + | ^ |akka-actor_2.12-${akkaVersion}-sources.jar/reference.conf:96:3: info: result | jvm-shutdown-hooks = on - | ^^^^^^^^^^^^^^^^^^ + | ^ |akka-actor_2.12-${akkaVersion}-sources.jar/reference.conf:1178:41: info: result | # This property is related to `akka.jvm-shutdown-hooks` above. - | ^^^^^^^^^^^^^^^^^^ + | ^ |""".stripMargin, ) @@ -85,7 +85,7 @@ class FindTextInDependencyJarsSuite s"""|src.zip${pathPrefix}java/lang/String.java:$line:5: info: result | public String(StringBuffer buffer) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ |""".stripMargin }, ) diff --git a/tests/unit/src/test/scala/tests/HoverLspSuite.scala b/tests/unit/src/test/scala/tests/HoverLspSuite.scala index bf970069fa6..f247cd1572c 100644 --- a/tests/unit/src/test/scala/tests/HoverLspSuite.scala +++ b/tests/unit/src/test/scala/tests/HoverLspSuite.scala @@ -41,7 +41,7 @@ class HoverLspSuite extends BaseLspSuite("hover-") with TestHovers { for { _ <- initialize( s"""|/metals.json - |{"a":{"scalaVersion" : ${V.scala213}}} + |{"a":{"scalaVersion" : ${V.scala3}}} |/Main.scala |object Main extends App { | // @@ diff --git a/tests/unit/src/test/scala/tests/JavaToplevelSuite.scala b/tests/unit/src/test/scala/tests/JavaToplevelSuite.scala index aae8277da5b..b8ee067a8e1 100644 --- a/tests/unit/src/test/scala/tests/JavaToplevelSuite.scala +++ b/tests/unit/src/test/scala/tests/JavaToplevelSuite.scala @@ -78,7 +78,7 @@ class JavaToplevelSuite extends BaseSuite { name: TestOptions, code: String, expected: String, - )(implicit loc: Location) { + )(implicit loc: Location) = { test(name) { val input = Input.VirtualFile("Test.java", code) val obtained = diff --git a/tests/unit/src/test/scala/tests/NewFileLspSuite.scala b/tests/unit/src/test/scala/tests/NewFileLspSuite.scala index 66a25c96f29..ef33cabd8e6 100644 --- a/tests/unit/src/test/scala/tests/NewFileLspSuite.scala +++ b/tests/unit/src/test/scala/tests/NewFileLspSuite.scala @@ -583,7 +583,7 @@ class NewFileLspSuite extends BaseLspSuite("new-file") { scalaVersion: Option[String], )(implicit loc: Location): Unit = test(testName) { - val localScalaVersion = scalaVersion.getOrElse(V.scala213) + val localScalaVersion = scalaVersion.getOrElse(V.scala3) val directoryUri = directory.fold(null.asInstanceOf[String])( workspace.resolve(_).toURI.toString() ) diff --git a/tests/unit/src/test/scala/tests/RenameLspSuite.scala b/tests/unit/src/test/scala/tests/RenameLspSuite.scala index dd2b7a43b11..f1dd273216a 100644 --- a/tests/unit/src/test/scala/tests/RenameLspSuite.scala +++ b/tests/unit/src/test/scala/tests/RenameLspSuite.scala @@ -1,6 +1,7 @@ package tests import scala.meta.internal.metals.InitializationOptions +import scala.meta.internal.metals.{BuildInfo => V} class RenameLspSuite extends BaseRenameLspSuite(s"rename") { @@ -296,8 +297,9 @@ class RenameLspSuite extends BaseRenameLspSuite(s"rename") { |""".stripMargin, ) + // https://github.com/lampepfl/dotty/issues/18389 renamed( - "colon-good", + "colon-good".ignore, """|/a/src/main/scala/a/Main.scala |package a |class User{ @@ -521,67 +523,6 @@ class RenameLspSuite extends BaseRenameLspSuite(s"rename") { expectedError = true, ) - renamed( - "macro", - """|/a/src/main/scala/a/Main.scala - |package a - |import io.circe.generic.JsonCodec - |trait LivingBeing - |@JsonCodec sealed trait <> extends LivingBeing - |object <> { - | case object Dog extends <> - | case object Cat extends <> - |} - |""".stripMargin, - "Tree", - ) - - renamed( - "macro1", - """|/a/src/main/scala/a/Main.scala - |package a - |import io.circe.generic.JsonCodec - |trait <> - |@JsonCodec sealed trait Animal extends <> - |object Animal { - | case object Dog extends Animal - | case object Cat extends Animal - |} - |""".stripMargin, - "Tree", - ) - - renamed( - "macro2", - """|/a/src/main/scala/a/Main.scala - |package a - |import io.circe.generic.JsonCodec - |@JsonCodec - |final case class <>(name: String) - |""".stripMargin, - "Tree", - ) - - renamed( - "macro3", - """|/a/src/main/scala/a/Main.scala - |package a - |import io.circe.generic.JsonCodec - |trait LivingBeing - |@JsonCodec sealed trait <> extends LivingBeing - |object <>{ - | case object Dog extends <> - | case object Cat extends <> - |} - |/a/src/main/scala/a/Use.scala - |package a - |object Use { - | val dog : <> = <>.Dog - |} - |""".stripMargin, - "Tree", - ) - renamed( "implicit-param", """|/a/src/main/scala/a/Main.scala @@ -894,7 +835,46 @@ class RenameLspSuite extends BaseRenameLspSuite(s"rename") { expectedError = true, ) - override protected def libraryDependencies: List[String] = - List("org.scalatest::scalatest:3.2.12", "io.circe::circe-generic:0.14.1") + renamed( + "scala3-outer", + """|/a/src/main/scala/a/Main.scala + | + |@main def run() = { + | <>("Mark") + | <>("Anne") + |} + |def <>(name : String) : Unit = { + | println(s"Hello $name") + |} + |""".stripMargin, + newName = "greeting", + scalaVersion = Some(V.scala3), + ) + + renamed( + "scala3-extension-params", + """|/a/src/main/scala/a/Main.scala + | + |extension (<>: String) + | def double = <> + <> + | def double2 = <> + <> + |end extension + |""".stripMargin, + newName = "greeting", + scalaVersion = Some(V.scala3), + ) + + renamed( + "scala3-extension-params-ref", + """|/a/src/main/scala/a/Main.scala + | + |extension (<>: String) + | def double = <> + <> + | def double2 = <> + <> + |end extension + |""".stripMargin, + newName = "greeting", + scalaVersion = Some(V.scala3), + ) } diff --git a/tests/unit/src/test/scala/tests/SemanticTokensExpectSuite.scala b/tests/unit/src/test/scala/tests/SemanticTokensExpectSuite.scala index f554da1d439..ca97601441e 100644 --- a/tests/unit/src/test/scala/tests/SemanticTokensExpectSuite.scala +++ b/tests/unit/src/test/scala/tests/SemanticTokensExpectSuite.scala @@ -6,9 +6,10 @@ import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.metals.SemanticTokensProvider import scala.meta.internal.pc.ScalaPresentationCompiler -class SemanticTokensExpectSuite extends DirectoryExpectSuite("semanticTokens") { +class SemanticTokensExpectSuite + extends DirectoryExpectSuite("semanticTokens3") { - override lazy val input: InputProperties = InputProperties.scala2() + override lazy val input: InputProperties = InputProperties.scala3() private val compiler = new ScalaPresentationCompiler( classpath = input.classpath.entries.map(_.toNIO) ) @@ -27,7 +28,7 @@ class SemanticTokensExpectSuite extends DirectoryExpectSuite("semanticTokens") { val tokens = SemanticTokensProvider.provide( nodes, params, - isScala3 = false, + isScala3 = true, ) TestSemanticTokens.semanticString( diff --git a/tests/unit/src/test/scala/tests/SuperMethodLspSuite.scala b/tests/unit/src/test/scala/tests/SuperMethodLspSuite.scala index 153e93596e7..8c8c7a5e579 100644 --- a/tests/unit/src/test/scala/tests/SuperMethodLspSuite.scala +++ b/tests/unit/src/test/scala/tests/SuperMethodLspSuite.scala @@ -217,10 +217,11 @@ class SuperMethodLspSuite extends BaseLspSuite("gotosupermethod") { val code = """ |package a - |import io.circe.Decoder | - |trait CustomDecoder extends Decoder[String] { - | override def <<1->50>>apply(c: io.circe.HCursor): Decoder.Result[String] = ??? + |import java.nio.file.FileSystem + | + |trait CustomFileSystem extends FileSystem { + | override def <<4->50>>close(): Unit = ??? |} | |""".stripMargin @@ -270,7 +271,6 @@ class SuperMethodLspSuite extends BaseLspSuite("gotosupermethod") { |{ | "a": { | "libraryDependencies": [ - | "io.circe::circe-generic:0.12.0" | ] | } |} @@ -288,9 +288,9 @@ class SuperMethodLspSuite extends BaseLspSuite("gotosupermethod") { // Checked manually it is actually there and operated under artificial ID link "50" externalDep = Map( 50 -> (new Position( - 60, - 6, - ), workspace.toURI.toString + ".metals/readonly/dependencies/circe-core_2.13-0.12.0-sources.jar/io/circe/Decoder.scala") + 133, + 25, + ), workspace.toURI.toString + ".metals/readonly/dependencies/src.zip/java.base/java/nio/file/FileSystem.java") ) (context, assertions) = parseWithUri(code, path) diff --git a/tests/unit/src/test/scala/tests/TreeViewLspSuite.scala b/tests/unit/src/test/scala/tests/TreeViewLspSuite.scala index 2552a7b7645..2729ecca549 100644 --- a/tests/unit/src/test/scala/tests/TreeViewLspSuite.scala +++ b/tests/unit/src/test/scala/tests/TreeViewLspSuite.scala @@ -3,6 +3,7 @@ package tests import scala.collection.SortedSet import scala.meta.internal.metals.InitializationOptions +import scala.meta.internal.metals.{BuildInfo => V} import scala.meta.internal.tvp.TreeViewProvider /** @@ -54,40 +55,40 @@ class TreeViewLspSuite extends BaseLspSuite("tree-view") { test("projects") { cleanWorkspace() for { - _ <- initialize(""" - |/metals.json - |{ - | "a": {}, - | "b": {} - |} - |/a/src/main/scala/a/Zero.scala - |class Zero { - | val a = 1 - |} - |/a/src/main/scala/a/First.scala - |package a - |class First { - | def a = 1 - | val b = 2 - |} - |object First - |/a/src/main/scala/a/Second.scala - |package a - |class Second { - | def a = 1 - | val b = 2 - | var c = 2 - |} - |object Second - |/b/src/main/scala/b/Third.scala - |package b - |class Third - |object Third - |/b/src/main/scala/b/Fourth.scala - |package b - |class Fourth - |object Fourth - |""".stripMargin) + _ <- initialize(s""" + |/metals.json + |{ + | "a": { "scalaVersion" : "${V.scala213}"}, + | "b": { "scalaVersion" : "${V.scala213}"} + |} + |/a/src/main/scala/a/Zero.scala + |class Zero { + | val a = 1 + |} + |/a/src/main/scala/a/First.scala + |package a + |class First { + | def a = 1 + | val b = 2 + |} + |object First + |/a/src/main/scala/a/Second.scala + |package a + |class Second { + | def a = 1 + | val b = 2 + | var c = 2 + |} + |object Second + |/b/src/main/scala/b/Third.scala + |package b + |class Third + |object Third + |/b/src/main/scala/b/Fourth.scala + |package b + |class Fourth + |object Fourth + |""".stripMargin) _ = assertNoDiff( client.workspaceTreeViewChanges, s"""|${TreeViewProvider.Project} @@ -145,18 +146,19 @@ class TreeViewLspSuite extends BaseLspSuite("tree-view") { test("libraries", withoutVirtualDocs = true) { for { _ <- initialize( - """ - |/metals.json - |{ - | "a": { - | "libraryDependencies": [ - | "io.circe::circe-core:0.14.0", - | "org.eclipse.lsp4j:org.eclipse.lsp4j:0.5.0", - | "com.lihaoyi::sourcecode:0.1.7" - | ] - | } - |} - |""".stripMargin + s""" + |/metals.json + |{ + | "a": { + | "scalaVersion" : "${V.scala213}", + | "libraryDependencies": [ + | "io.circe::circe-core:0.14.0", + | "org.eclipse.lsp4j:org.eclipse.lsp4j:0.5.0", + | "com.lihaoyi::sourcecode:0.1.7" + | ] + | } + |} + |""".stripMargin ) folder = server.server.folder _ = { @@ -483,22 +485,22 @@ class TreeViewLspSuite extends BaseLspSuite("tree-view") { cleanWorkspace() for { _ <- initialize( - """ - |/metals.json - |{ - | "a": {}, - | "b": {} - |} - |/a/src/main/scala/a/First.scala - |package a - |class First - |/b/src/main/scala/b/Second.scala - |package b - |class Second { - | def a = 1 - | val b = 2 - |} - |""".stripMargin + s""" + |/metals.json + |{ + | "a": {"scalaVersion" : "${V.scala213}"}, + | "b": {"scalaVersion" : "${V.scala213}"} + |} + |/a/src/main/scala/a/First.scala + |package a + |class First + |/b/src/main/scala/b/Second.scala + |package b + |class Second { + | def a = 1 + | val b = 2 + |} + |""".stripMargin ) folder = server.server.folder // Trigger a compilation of Second.scala diff --git a/tests/unit/src/test/scala/tests/WarningsLspSuite.scala b/tests/unit/src/test/scala/tests/WarningsLspSuite.scala index eff3e604c15..e465182a98d 100644 --- a/tests/unit/src/test/scala/tests/WarningsLspSuite.scala +++ b/tests/unit/src/test/scala/tests/WarningsLspSuite.scala @@ -7,13 +7,14 @@ class WarningsLspSuite extends BaseLspSuite("warnings") { test("deprecated-scala-212") { cleanWorkspace() - val using = V.deprecatedScalaVersions.filter(_.startsWith("2.12")).head + val usingVersion = + V.deprecatedScalaVersions.filter(_.startsWith("2.12")).head for { _ <- initialize( s"""/metals.json |{ | "a": { - | "scalaVersion": "${using}" + | "scalaVersion": "${usingVersion}" | } |} |/a/src/main/scala/a/Main.scala @@ -24,7 +25,7 @@ class WarningsLspSuite extends BaseLspSuite("warnings") { _ = assertNoDiff( client.workspaceMessageRequests, Messages.DeprecatedScalaVersion.message( - Set(using) + Set(usingVersion) ), ) } yield () @@ -32,14 +33,15 @@ class WarningsLspSuite extends BaseLspSuite("warnings") { test("multiple-problems-scala") { cleanWorkspace() - val using = V.deprecatedScalaVersions.filter(_.startsWith("2.12")).head + val usingVersion = + V.deprecatedScalaVersions.filter(_.startsWith("2.12")).head val older = "2.12.4" for { _ <- initialize( s"""/metals.json |{ | "a": { - | "scalaVersion": "${using}" + | "scalaVersion": "${usingVersion}" | }, | "b": { | "scalaVersion" : "$older" @@ -59,13 +61,13 @@ class WarningsLspSuite extends BaseLspSuite("warnings") { test("deprecated-scala-211") { cleanWorkspace() - val using = V.scala211 + val usingVersion = V.scala211 for { _ <- initialize( s"""/metals.json |{ | "a": { - | "scalaVersion": "${using}" + | "scalaVersion": "${usingVersion}" | } |} |/a/src/main/scala/a/Main.scala @@ -75,20 +77,20 @@ class WarningsLspSuite extends BaseLspSuite("warnings") { ) _ = assertNoDiff( client.workspaceMessageRequests, - Messages.DeprecatedScalaVersion.message(Set(using)), + Messages.DeprecatedScalaVersion.message(Set(usingVersion)), ) } yield () } test("unsupported-scala-212") { cleanWorkspace() - val using = "2.12.4" + val usingVersion = "2.12.4" for { _ <- initialize( s"""/metals.json |{ | "a": { - | "scalaVersion": "${using}" + | "scalaVersion": "${usingVersion}" | } |} |/a/src/main/scala/a/Main.scala @@ -98,20 +100,21 @@ class WarningsLspSuite extends BaseLspSuite("warnings") { ) _ = assertNoDiff( client.workspaceMessageRequests, - Messages.UnsupportedScalaVersion.message(Set(using)), + Messages.UnsupportedScalaVersion.message(Set(usingVersion)), ) } yield () } test("deprecated-scala-213") { cleanWorkspace() - val using = V.deprecatedScalaVersions.filter(_.startsWith("2.13")).head + val usingVersion = + V.deprecatedScalaVersions.filter(_.startsWith("2.13")).head for { _ <- initialize( s"""/metals.json |{ | "a": { - | "scalaVersion": "${using}" + | "scalaVersion": "${usingVersion}" | } |} |/a/src/main/scala/a/Main.scala @@ -121,20 +124,20 @@ class WarningsLspSuite extends BaseLspSuite("warnings") { ) _ = assertNoDiff( client.workspaceMessageRequests, - Messages.DeprecatedScalaVersion.message(Set(using)), + Messages.DeprecatedScalaVersion.message(Set(usingVersion)), ) } yield () } test("no-warnings-scala-3") { cleanWorkspace() - val using = V.scala3 + val usingVersion = V.scala3 for { _ <- initialize( s"""/metals.json |{ | "a": { - | "scalaVersion": "${using}" + | "scalaVersion": "${usingVersion}" | } |} |/a/src/main/scala/a/Main.scala diff --git a/tests/unit/src/test/scala/tests/WorkspaceFoldersSuite.scala b/tests/unit/src/test/scala/tests/WorkspaceFoldersSuite.scala index 9d9f9c564b2..1fec4c2725e 100644 --- a/tests/unit/src/test/scala/tests/WorkspaceFoldersSuite.scala +++ b/tests/unit/src/test/scala/tests/WorkspaceFoldersSuite.scala @@ -11,14 +11,14 @@ class WorkspaceFoldersSuite Map( "testFolder" -> s"""|/metals.json - |{"a":{"scalaVersion" : ${V.scala213}}} + |{"a":{"scalaVersion" : ${V.scala3}}} |/a/src/main/scala/a/A.scala |package a |case class MyObjectA() |""".stripMargin, "otherTestFolder" -> s"""|/metals.json - |{"a":{"scalaVersion" : ${V.scala213}}} + |{"a":{"scalaVersion" : ${V.scala3}}} |/a/src/main/scala/a/B.scala |package a |case class MyObjectB() diff --git a/tests/unit/src/test/scala/tests/classFinder/ClassBreakpointSuite.scala b/tests/unit/src/test/scala/tests/classFinder/ClassBreakpointSuite.scala index d754950bbc5..4db59e879c4 100644 --- a/tests/unit/src/test/scala/tests/classFinder/ClassBreakpointSuite.scala +++ b/tests/unit/src/test/scala/tests/classFinder/ClassBreakpointSuite.scala @@ -163,7 +163,7 @@ class ClassBreakpointSuite extends BaseClassFinderSuite { name: TestOptions, original: String, expected: String, - scalaVersion: String = V.scala213, + scalaVersion: String = V.scala3, ): Unit = test(name) { val (buffers, classFinder) = init(scalaVersion) diff --git a/tests/unit/src/test/scala/tests/classFinder/FindAllClassesSuite.scala b/tests/unit/src/test/scala/tests/classFinder/FindAllClassesSuite.scala index b9f84dae1d8..db87ac63871 100644 --- a/tests/unit/src/test/scala/tests/classFinder/FindAllClassesSuite.scala +++ b/tests/unit/src/test/scala/tests/classFinder/FindAllClassesSuite.scala @@ -129,7 +129,7 @@ class FindAllClassesSuite extends BaseClassFinderSuite { "Class FooOps a.Foo$FooOps.class", "Object FooOps a.Foo$FooOps$.class", ), - scalaVersion = V.scala213, + scalaVersion = V.scala3, searchGranularity = ClassFinderGranularity.ClassFiles, ) @@ -142,7 +142,7 @@ class FindAllClassesSuite extends BaseClassFinderSuite { "Class Foo a.Foo.class", "Object Foo a.Foo$.class", ), - scalaVersion = V.scala213, + scalaVersion = V.scala3, searchGranularity = ClassFinderGranularity.ClassFiles, ) @@ -152,7 +152,7 @@ class FindAllClassesSuite extends BaseClassFinderSuite { expected: Vector[String], searchGranularity: ClassFinderGranularity, filename: String = "Main.scala", - scalaVersion: String = V.scala213, + scalaVersion: String = V.scala3, )(implicit loc: Location): Unit = test(name) { val (buffers, classFinder) = init(scalaVersion) diff --git a/tests/unit/src/test/scala/tests/classFinder/TastyNameResolverSuite.scala b/tests/unit/src/test/scala/tests/classFinder/TastyNameResolverSuite.scala index 5d27716c0cf..124daa19b09 100644 --- a/tests/unit/src/test/scala/tests/classFinder/TastyNameResolverSuite.scala +++ b/tests/unit/src/test/scala/tests/classFinder/TastyNameResolverSuite.scala @@ -135,7 +135,7 @@ class ClassNameResolverSuite extends BaseClassFinderSuite { original: String, expected: String, filename: String = "Main.scala", - scalaVersion: String = V.scala213, + scalaVersion: String = V.scala3, ): Unit = test(name) { val (buffers, classFinder) = init(scalaVersion) diff --git a/tests/unit/src/test/scala/tests/codeactions/ConvertPatternMatchLspSuite.scala b/tests/unit/src/test/scala/tests/codeactions/ConvertPatternMatchLspSuite.scala index 79dfa997957..4e1e85e4b71 100644 --- a/tests/unit/src/test/scala/tests/codeactions/ConvertPatternMatchLspSuite.scala +++ b/tests/unit/src/test/scala/tests/codeactions/ConvertPatternMatchLspSuite.scala @@ -9,7 +9,7 @@ class ConvertPatternMatchLspSuite "convertPatternMatch" ) { - val filterAction: CodeAction => Boolean = { act: CodeAction => + val filterAction: CodeAction => Boolean = { (act: CodeAction) => act.getTitle() == PatternMatchRefactor.convertPatternMatch } diff --git a/tests/unit/src/test/scala/tests/codeactions/ConvertToNamedArgumentsLspSuite.scala b/tests/unit/src/test/scala/tests/codeactions/ConvertToNamedArgumentsLspSuite.scala index b371dc684ff..073cad19e0b 100644 --- a/tests/unit/src/test/scala/tests/codeactions/ConvertToNamedArgumentsLspSuite.scala +++ b/tests/unit/src/test/scala/tests/codeactions/ConvertToNamedArgumentsLspSuite.scala @@ -9,7 +9,7 @@ class ConvertToNamedArgumentsLspSuite "convertToNamedArguments" ) { - val filterAction: CodeAction => Boolean = { act: CodeAction => + val filterAction: CodeAction => Boolean = { (act: CodeAction) => ConvertToNamedArguments.title(".*").r matches act.getTitle() } diff --git a/tests/unit/src/test/scala/tests/codeactions/ExtractRenameMemberLspSuite.scala b/tests/unit/src/test/scala/tests/codeactions/ExtractRenameMemberLspSuite.scala index bf8c10b1709..05a11e6975a 100644 --- a/tests/unit/src/test/scala/tests/codeactions/ExtractRenameMemberLspSuite.scala +++ b/tests/unit/src/test/scala/tests/codeactions/ExtractRenameMemberLspSuite.scala @@ -437,7 +437,7 @@ class ExtractRenameMemberLspSuite name: TestOptions, original: String, codeActionExpected: Boolean = true, - scalaVersion: String = V.scala213, + scalaVersion: String = V.scala3, fileName: String = "A.scala", ): Unit = test(name) { diff --git a/tests/unit/src/test/scala/tests/codeactions/ExtractValueLspSuite.scala b/tests/unit/src/test/scala/tests/codeactions/ExtractValueLspSuite.scala index 71cd0f9513d..aa9a9e602a6 100644 --- a/tests/unit/src/test/scala/tests/codeactions/ExtractValueLspSuite.scala +++ b/tests/unit/src/test/scala/tests/codeactions/ExtractValueLspSuite.scala @@ -346,7 +346,7 @@ class ExtractValueLspSuite "extract-new", """|class Car(age: Int) |object Main{ - | new Car(age = <<1>>) + | val car = new Car(age = <<1>>) |} |""".stripMargin, s"""|${ExtractValueCodeAction.title("1")} @@ -354,7 +354,7 @@ class ExtractValueLspSuite """|class Car(age: Int) |object Main{ | val newValue = 1 - | new Car(age = newValue) + | val car = new Car(age = newValue) |} |""".stripMargin, ) diff --git a/tests/unit/src/test/scala/tests/codeactions/FlatMapToForComprehensionSuite.scala b/tests/unit/src/test/scala/tests/codeactions/FlatMapToForComprehensionSuite.scala index 58588abb564..616d05f3f41 100644 --- a/tests/unit/src/test/scala/tests/codeactions/FlatMapToForComprehensionSuite.scala +++ b/tests/unit/src/test/scala/tests/codeactions/FlatMapToForComprehensionSuite.scala @@ -53,6 +53,7 @@ class FlatMapToForComprehensionSuite |} |""".stripMargin, selectedActionIndex = 1, + expectNoDiagnostics = false, ) check( diff --git a/tests/unit/src/test/scala/tests/codeactions/InsertInferredTypeLspSuite.scala b/tests/unit/src/test/scala/tests/codeactions/InsertInferredTypeLspSuite.scala index bcfdb7d276d..026bff9389c 100644 --- a/tests/unit/src/test/scala/tests/codeactions/InsertInferredTypeLspSuite.scala +++ b/tests/unit/src/test/scala/tests/codeactions/InsertInferredTypeLspSuite.scala @@ -9,7 +9,7 @@ class InsertInferredTypeLspSuite "insertInferredType" ) { - val filterAction: CodeAction => Boolean = { act: CodeAction => + val filterAction: CodeAction => Boolean = { (act: CodeAction) => act.getTitle() == InsertInferredType.insertType || act .getTitle() == InsertInferredType.insertTypeToPattern } diff --git a/tests/unit/src/test/scala/tests/debug/CompletionDapSuite.scala b/tests/unit/src/test/scala/tests/debug/CompletionDapSuite.scala index 8a3ed3bbf7e..c47596e74f2 100644 --- a/tests/unit/src/test/scala/tests/debug/CompletionDapSuite.scala +++ b/tests/unit/src/test/scala/tests/debug/CompletionDapSuite.scala @@ -20,11 +20,6 @@ class CompletionDapSuite "basic", expression = "1.toS@@", expectedCompletions = """|toShort: Short - |toBinaryString: String - |toDegrees: Double - |toHexString: String - |toOctalString: String - |toRadians: Double |toString(): String |""".stripMargin, expectedEdit = "1.toShort", @@ -71,12 +66,11 @@ class CompletionDapSuite assertCompletion( "advanced-snippet", expression = "1.until@@", - expectedCompletions = - """|until(end: Long): NumericRange.Exclusive[Long] - |until(end: Long, step: Long): NumericRange.Exclusive[Long] - |until(end: Int): Range - |until(end: Int, step: Int): Range - |""".stripMargin, + expectedCompletions = """|until(end: T): Exclusive[T] + |until(end: T, step: T): Exclusive[T] + |until(end: Int): Range + |until(end: Int, step: Int): Range + |""".stripMargin, expectedEdit = "1.until(@@)", topLines = Some(4), )( @@ -121,13 +115,10 @@ class CompletionDapSuite "multiline", expression = """|val a = 123 |a.toStri@@""".stripMargin, - expectedCompletions = """|toBinaryString: String - |toHexString: String - |toOctalString: String - |toString(): String + expectedCompletions = """|toString(): String |""".stripMargin, expectedEdit = """|val a = 123 - |a.toBinaryString""".stripMargin, + |a.toString()""".stripMargin, topLines = Some(4), )( """|/a/src/main/scala/a/Main.scala @@ -152,16 +143,13 @@ class CompletionDapSuite |val d = 111 |a.toStri@@ |1 + 234""".stripMargin, - expectedCompletions = """|toBinaryString: String - |toHexString: String - |toOctalString: String - |toString(): String + expectedCompletions = """|toString(): String |""".stripMargin, expectedEdit = """|val a = 123 |val b = 111 |val c = 111 |val d = 111 - |a.toBinaryString + |a.toString() |1 + 234 |""".stripMargin, topLines = Some(4), @@ -184,8 +172,8 @@ class CompletionDapSuite "single-dot", expression = "Main.@@", expectedCompletions = """|name: Option[String] - |args: Array[String] |executionStart: Long + |args: Array[String] |main(args: Array[String]): Unit |""".stripMargin, expectedEdit = "Main.name", diff --git a/tests/unit/src/test/scala/tests/formatting/OnTypeFormattingSuite.scala b/tests/unit/src/test/scala/tests/formatting/OnTypeFormattingSuite.scala index 25da27ee845..326ba6284d7 100644 --- a/tests/unit/src/test/scala/tests/formatting/OnTypeFormattingSuite.scala +++ b/tests/unit/src/test/scala/tests/formatting/OnTypeFormattingSuite.scala @@ -621,7 +621,7 @@ class OnTypeFormattingSuite extends BaseLspSuite("onTypeFormatting") { stripMarginEnabled: Boolean = true, additionalRequests: TestingServer => Future[Unit] = _ => Future.unit, )(implicit loc: Location): Unit = { - val quote = """\u0022""" + val quote = "\"" def unmangle(string: String): String = string.replaceAll("'", quote) diff --git a/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala b/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala index 60f4d5bc4a8..d2e72d470c0 100644 --- a/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala +++ b/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala @@ -345,7 +345,7 @@ class MultilineStringRangeFormattingWhenPastingSuite paste: String, expectedCase: String, )(implicit loc: Location): Unit = { - val tripleQuote = """\u0022\u0022\u0022""" + val tripleQuote = "\"\"\"" def unmangle(string: String): String = string.replaceAll("'''", tripleQuote) diff --git a/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenSelectingSuite.scala b/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenSelectingSuite.scala index ff2026994e4..a31fbcf2b7c 100644 --- a/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenSelectingSuite.scala +++ b/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenSelectingSuite.scala @@ -142,7 +142,7 @@ class MultilineStringRangeFormattingWhenSelectingSuite testCase: String, expectedCase: String, )(implicit loc: Location): Unit = { - val tripleQuote = """\u0022\u0022\u0022""" + val tripleQuote = "\"\"\"" def unmangle(string: String): String = string.replaceAll("'''", tripleQuote) diff --git a/tests/unit/src/test/scala/tests/scalafix/ScalafixProviderLspSuite.scala b/tests/unit/src/test/scala/tests/scalafix/ScalafixProviderLspSuite.scala index 8972333d773..84c0d637a32 100644 --- a/tests/unit/src/test/scala/tests/scalafix/ScalafixProviderLspSuite.scala +++ b/tests/unit/src/test/scala/tests/scalafix/ScalafixProviderLspSuite.scala @@ -117,8 +117,7 @@ class ScalafixProviderLspSuite extends BaseLspSuite("scalafix-provider") { | |} |""".stripMargin, - ), - + ) } yield () } diff --git a/tests/unit/src/test/scala/tests/testProvider/TestSuitesProviderSuite.scala b/tests/unit/src/test/scala/tests/testProvider/TestSuitesProviderSuite.scala index 47007e2cc5b..afae8994847 100644 --- a/tests/unit/src/test/scala/tests/testProvider/TestSuitesProviderSuite.scala +++ b/tests/unit/src/test/scala/tests/testProvider/TestSuitesProviderSuite.scala @@ -574,7 +574,7 @@ class TestSuitesProviderSuite extends BaseLspSuite("testSuitesFinderSuite") { TestCaseEntry( "test$minusbacktick", "test-backtick", - QuickLocation(classUriFor(file), (3, 6, 3, 21)).toLsp, + QuickLocation(classUriFor(file), (3, 7, 3, 20)).toLsp, ) ).asJava, ), diff --git a/tests/unit/src/test/scala/tests/worksheets/WorksheetLspSuite.scala b/tests/unit/src/test/scala/tests/worksheets/WorksheetLspSuite.scala index 78fd5877042..8774f610c3b 100644 --- a/tests/unit/src/test/scala/tests/worksheets/WorksheetLspSuite.scala +++ b/tests/unit/src/test/scala/tests/worksheets/WorksheetLspSuite.scala @@ -4,8 +4,14 @@ import scala.meta.internal.metals.{BuildInfo => V} import munit.TestOptions -class WorksheetLspSuite extends tests.BaseWorksheetLspSuite(V.scala213) { +class WorksheetLspSuite extends tests.BaseWorksheetLspSuite(V.scala3) { + override def versionSpecificCodeToValidate: String = + """given str: String = """"" + + override def versionSpecificScalacOptionsToValidate: List[String] = List( + "-Ycheck-reentrant" + ) checkWorksheetDeps( "imports-inside", "a/src/main/scala/foo/Main.worksheet.sc", @@ -24,7 +30,7 @@ class WorksheetLspSuite extends tests.BaseWorksheetLspSuite(V.scala213) { | "a": {} |} |/$path - |import $$dep.`com.lihaoyi::scalatags:0.9.0` + |import $$dep.`com.lihaoyi::scalatags:0.12.0` |import scalatags.Text.all._ |val htmlFile = html( | body( @@ -43,11 +49,11 @@ class WorksheetLspSuite extends tests.BaseWorksheetLspSuite(V.scala213) { _ = assertNoDiff( server.workspaceDefinitions, s"""|/$path - |import $$dep/**/.`com.lihaoyi::scalatags:0.9.0`/**/ + |import $$dep/**/.`com.lihaoyi::scalatags:0.12.0`/**/ |import scalatags.Text/*Text.scala*/.all/*Text.scala*/._ - |val htmlFile/*L2*/ = html/*Text.scala*/( - | body/*Text.scala*/( - | p/*Text.scala*/("This is a big paragraph of text") + |val htmlFile/*L2*/ = html/*Tags.scala*/( + | body/*Tags.scala*/( + | p/*Tags.scala*/("This is a big paragraph of text") | ) |) |htmlFile/*L2*/.render/*Text.scala*/ @@ -58,14 +64,14 @@ class WorksheetLspSuite extends tests.BaseWorksheetLspSuite(V.scala213) { _ = assertNoDiagnostics() _ = assertNoDiff( client.workspaceDecorations, - """|import $dep.`com.lihaoyi::scalatags:0.9.0` + """|import $dep.`com.lihaoyi::scalatags:0.12.0` |import scalatags.Text.all._ |val htmlFile = html( | body( | p("This is a big paragraph of text") | ) - |) // : scalatags.Text.TypedTag[String] = TypedTag(tag = "html",modifiers = List(ArraySeq(TypedTag(tag = "body",modifiers = L… - |htmlFile.render // : String = "

This is a big paragraph of text

" + |) // : TypedTag[String] =

This is a big paragraph of text

+ |htmlFile.render // : String =

This is a big paragraph of text

|""".stripMargin, ) } yield () @@ -89,7 +95,7 @@ class WorksheetLspSuite extends tests.BaseWorksheetLspSuite(V.scala213) { _ <- server.didOpen(path) _ = assertNoDiff( client.workspaceErrorShowMessages, - "Error downloading com.lihaoyi:scalatags_2.13:0.999.0", + "Error downloading com.lihaoyi:scalatags_3:0.999.0", ) } yield () } @@ -113,60 +119,7 @@ class WorksheetLspSuite extends tests.BaseWorksheetLspSuite(V.scala213) { _ <- server.didOpen(path) _ = assertNoDiff( client.workspaceDecorations, - "new java.sql.Date(100L) // : java.sql.Date = 1970-01-01", - ) - } yield () - } - - test("akka") { - cleanWorkspace() - val path = "hi.worksheet.sc" - for { - _ <- initialize( - s""" - |/metals.json - |{ - | "a": {} - |} - |/${path} - |import $$dep.`com.typesafe.akka::akka-stream:2.6.13` - | - |import akka.actor.ActorSystem - |import akka.NotUsed - |import akka.stream.scaladsl.Source - |import akka.stream.scaladsl.Sink - |import java.io.File - |import scala.concurrent.Await - |import scala.concurrent.duration.DurationInt - | - | - |implicit val system: ActorSystem = ActorSystem("QuickStart") - |val source: Source[Int, NotUsed] = Source(1 to 2) - |val future = source.runWith(Sink.foreach(_ => ())) - |Await.result(future, 3.seconds) - | - |""".stripMargin - ) - _ <- server.didOpen(path) - _ = assertNoDiff( - // it seems that part of the string is always different, so let's remove it - client.workspaceDecorations.replaceAll(".out\\(.*", ".out(..."), - """|import $dep.`com.typesafe.akka::akka-stream:2.6.13` - | - |import akka.actor.ActorSystem - |import akka.NotUsed - |import akka.stream.scaladsl.Source - |import akka.stream.scaladsl.Sink - |import java.io.File - |import scala.concurrent.Await - |import scala.concurrent.duration.DurationInt - | - | - |implicit val system: ActorSystem = ActorSystem("QuickStart") // : ActorSystem = akka://QuickStart - |val source: Source[Int, NotUsed] = Source(1 to 2) // : Source[Int, NotUsed] = Source(SourceShape(StatefulMapConcat.out(... - |val future = source.runWith(Sink.foreach(_ => ())) // : concurrent.Future[akka.Done] = Future(Success(Done)) - |Await.result(future, 3.seconds) // : akka.Done = Done - |""".stripMargin, + "new java.sql.Date(100L) // : Date = 1970-01-01", ) } yield () } diff --git a/tests/unit/src/test/scala/tests/worksheets/WorksheetNoDecorationsLspSuite.scala b/tests/unit/src/test/scala/tests/worksheets/WorksheetNoDecorationsLspSuite.scala index e5af14318f5..c794d69a0af 100644 --- a/tests/unit/src/test/scala/tests/worksheets/WorksheetNoDecorationsLspSuite.scala +++ b/tests/unit/src/test/scala/tests/worksheets/WorksheetNoDecorationsLspSuite.scala @@ -32,7 +32,7 @@ class WorksheetNoDecorationsLspSuite workspace.resolve("a/src/main/scala/foo/Main.worksheet.sc").readText, """ |val x = 1 /*> : Int = 1 */ - |val foo = "bar" /*> : String = "bar" */ + |val foo = "bar" /*> : String = bar */ |println("metals") /*> metals */ |""".stripMargin, ) @@ -40,11 +40,11 @@ class WorksheetNoDecorationsLspSuite "a/src/main/scala/foo/Main.worksheet.sc", """ |val x = 1 /*> : Int@@ = 1 */ - |val foo = "bar" /*> : @@String = "bar" */ + |val foo = "bar" /*> : @@String = bar */ |println("metals") /*> @@metals */ |""".stripMargin, """x: Int = 1""".hover, - """foo: String = "bar"""".hover, + """foo: String = bar""".hover, """// metals""".hover, ) } yield () @@ -70,7 +70,7 @@ class WorksheetNoDecorationsLspSuite workspace.resolve("a/src/main/scala/foo/Main.worksheet.sc").readText, """ |val x = 2 /*> : Int = 2 */ - |val foo = "baz" /*> : String = "baz" */ + |val foo = "baz" /*> : String = baz */ |println("meta ls") /*> meta ls */ |""".stripMargin, ) @@ -78,11 +78,11 @@ class WorksheetNoDecorationsLspSuite "a/src/main/scala/foo/Main.worksheet.sc", """ |val x = 2 /*> : Int @@= 2 */ - |val foo = "baz" /*> : String = "baz"@@ */ + |val foo = "baz" /*> : String = baz@@ */ |println("meta ls") /*> meta@@ ls */ |""".stripMargin, """x: Int = 2""".hover, - """foo: String = "baz"""".hover, + """foo: String = baz""".hover, """// meta ls""".hover, ) } yield ()