Skip to content

Commit

Permalink
try fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Nov 9, 2023
1 parent f64429e commit eac1a09
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -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)) {
Expand All @@ -2168,6 +2192,7 @@ class MetalsLspService(
buildServerPromise.trySuccess(())
change
}
}

private def onBuildTargetChanges(
params: b.DidChangeBuildTarget
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eac1a09

Please sign in to comment.