From eac1a09d6f0dfbc9a068f668823265b7ca7cb47b Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Tue, 7 Nov 2023 18:27:13 +0100 Subject: [PATCH] try fixing tests --- .../meta/internal/bsp/BspConnector.scala | 5 ++- .../scala/meta/internal/metals/Indexer.scala | 1 + .../internal/metals/MetalsLspService.scala | 43 ++++++++++++++++--- 3 files changed, 42 insertions(+), 7 deletions(-) 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 103a69407ea..e4b2dc09e29 100644 --- a/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala +++ b/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala @@ -77,6 +77,7 @@ class BspConnector( userConfiguration: UserConfiguration, shellRunner: ShellRunner, )(implicit ec: ExecutionContext): Future[Option[BspSession]] = { + scribe.info(s"connecting to new build server with build tool $buildTool") val projectRoot = buildTool.map(_.projectRoot).getOrElse(workspace) def connect( projectRoot: AbsolutePath, @@ -179,7 +180,9 @@ class BspConnector( possibleBuildServerConn match { case None => Future.successful(None) case Some(buildServerConn) - if buildServerConn.isBloop && buildTools.isSbt => + if buildServerConn.isBloop && buildTool.exists( + _.isInstanceOf[SbtBuildTool] + ) => // NOTE: (ckipp01) we special case this here since sbt bsp server // doesn't yet support metabuilds. So in the future when that // changes, re-work this and move the creation of this out above 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 e6396948819..4ca4f671cc6 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Indexer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Indexer.scala @@ -120,6 +120,7 @@ final case class Indexer( scribe.info(s"Skipping reload with status '${status.name}'") Future.successful(BuildChange.None) case None => + scribe.info(s"running workspace reload") for { userResponse <- workspaceReload().requestReload( buildTool, 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 67c3c228086..725a3d55954 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -35,6 +35,7 @@ import scala.meta.internal.builds.BuildServerProvider import scala.meta.internal.builds.BuildTool import scala.meta.internal.builds.BuildToolSelector import scala.meta.internal.builds.BuildTools +import scala.meta.internal.builds.Digest import scala.meta.internal.builds.SbtBuildTool import scala.meta.internal.builds.ScalaCliBuildTool import scala.meta.internal.builds.ShellRunner @@ -911,17 +912,25 @@ class MetalsLspService( def fullConnect(): Future[Unit] = for { found <- supportedBuildTool() - _ = found match { + chosenBuildServer = found match { case Some(BuildTool.Found(buildServer, _)) if buildServer.forcesBuildServer => + scribe.info( + s"build tool forces build server to be: ${buildServer.executableName}" + ) tables.buildServers.chooseServer(buildServer.executableName) - case _ => + Some(buildServer.executableName) + case _ => tables.buildServers.selectedServer() } _ <- Future .sequence( List( quickConnectToBuildServer(), - slowConnectToBuildServer(forceImport = false, found), + slowConnectToBuildServer( + forceImport = false, + found, + chosenBuildServer, + ), ) ) } yield () @@ -2058,18 +2067,30 @@ class MetalsLspService( forceImport: Boolean ): Future[BuildChange] = for { buildTool <- supportedBuildTool() - buildChange <- slowConnectToBuildServer(forceImport, buildTool) + chosenBuildServer = tables.buildServers.selectedServer() + buildChange <- slowConnectToBuildServer( + forceImport, + buildTool, + chosenBuildServer, + ) } yield buildChange def slowConnectToBuildServer( forceImport: Boolean, buildTool: Option[BuildTool.Found], + chosenBuildServer: Option[String], ): Future[BuildChange] = { - val chosenBuildServer = tables.buildServers.selectedServer() + val chosenBuildServerNow = tables.buildServers.selectedServer() + assert(chosenBuildServerNow == chosenBuildServer) val isBloopOrEmpty = chosenBuildServer.isEmpty || chosenBuildServer.exists( _ == BloopServers.name ) + scribe.info( + s"running slow-connect with chosen build server $chosenBuildServer" + ) + scribe.info(s"found build tool: $buildTool") + buildTool match { case Some(BuildTool.Found(buildTool: BloopInstallProvider, digest)) if isBloopOrEmpty => @@ -2155,7 +2176,10 @@ class MetalsLspService( def optProjectRoot(): Option[AbsolutePath] = buildTool.map(_.projectRoot).orElse(buildTools.bloopProject) - def quickConnectToBuildServer(): Future[BuildChange] = + def quickConnectToBuildServer(): Future[BuildChange] = { + scribe.info("running quick-connect") + val stacktrace = Thread.currentThread().getStackTrace() + scribe.info(stacktrace.mkString("\t\n")) for { change <- if (!buildTools.isAutoConnectable(optProjectRoot)) { @@ -2168,6 +2192,7 @@ class MetalsLspService( buildServerPromise.trySuccess(()) change } + } private def onBuildTargetChanges( params: b.DidChangeBuildTarget @@ -2323,10 +2348,16 @@ class MetalsLspService( s"Connected to Build server: ${session.main.name} v${session.version}" ) cancelables.add(session) + buildTool.foreach( + workspaceReload.persistChecksumStatus(Digest.Status.Started, _) + ) bspSession = Some(session) for { _ <- importBuild(session) _ <- indexer.profiledIndexWorkspace(runDoctorCheck) + _ = buildTool.foreach( + workspaceReload.persistChecksumStatus(Digest.Status.Installed, _) + ) _ = if (session.main.isBloop) checkRunningBloopVersion(session.version) } yield { BuildChange.Reconnected