Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: queue or cancel previous connect request #6691

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading