Skip to content

Commit

Permalink
improvement: queue or cancel previous connect request
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Aug 20, 2024
1 parent e537ad6 commit 3f2a29b
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ object BuildChange {
case object Failed extends BuildChange
case object Reconnected extends BuildChange
case object Reloaded extends BuildChange
case object Cancelled extends BuildChange
}
44 changes: 16 additions & 28 deletions metals/src/main/scala/scala/meta/internal/builds/BloopInstall.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package scala.meta.internal.builds

import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean

import scala.concurrent.ExecutionContext
import scala.concurrent.Future
Expand Down Expand Up @@ -37,33 +36,23 @@ final class BloopInstall(
override def toString: String = s"BloopInstall($workspace)"

def runUnconditionally(
buildTool: BloopInstallProvider,
isImportInProcess: AtomicBoolean,
buildTool: BloopInstallProvider
): Future[WorkspaceLoadedStatus] = {
if (isImportInProcess.compareAndSet(false, true)) {
buildTool.bloopInstall(
workspace,
args => {
scribe.info(s"running '${args.mkString(" ")}'")
val process =
runArgumentsUnconditionally(buildTool, args, userConfig().javaHome)
process.foreach { e =>
if (e.isFailed) {
// Record the exact command that failed to help troubleshooting.
scribe.error(s"$buildTool command failed: ${args.mkString(" ")}")
}
buildTool.bloopInstall(
workspace,
args => {
scribe.info(s"running '${args.mkString(" ")}'")
val process =
runArgumentsUnconditionally(buildTool, args, userConfig().javaHome)
process.foreach { e =>
if (e.isFailed) {
// Record the exact command that failed to help troubleshooting.
scribe.error(s"$buildTool command failed: ${args.mkString(" ")}")
}
process.onComplete(_ => isImportInProcess.set(false))
process
},
)
} else {
Future
.successful {
languageClient.showMessage(ImportAlreadyRunning)
WorkspaceLoadedStatus.Dismissed
}
}
process
},
)
}

private def runArgumentsUnconditionally(
Expand Down Expand Up @@ -123,7 +112,6 @@ final class BloopInstall(
def runIfApproved(
buildTool: BloopInstallProvider,
digest: String,
isImportInProcess: AtomicBoolean,
): Future[WorkspaceLoadedStatus] =
synchronized {
oldInstallResult(digest) match {
Expand All @@ -133,7 +121,7 @@ final class BloopInstall(
Future.successful(result)
case _ =>
if (userConfig().shouldAutoImportNewProject) {
runUnconditionally(buildTool, isImportInProcess)
runUnconditionally(buildTool)
} else {
scribe.debug("Awaiting user response...")
for {
Expand All @@ -145,7 +133,7 @@ final class BloopInstall(
)
installResult <- {
if (userResponse.isYes) {
runUnconditionally(buildTool, isImportInProcess)
runUnconditionally(buildTool)
} else {
// Don't spam the user with requests during rapid build changes.
notification.dismiss(2, TimeUnit.MINUTES)
Expand Down
Loading

0 comments on commit 3f2a29b

Please sign in to comment.