Skip to content

Commit b1564af

Browse files
committed
improvement: queue or cancel previous connect request
1 parent e537ad6 commit b1564af

File tree

6 files changed

+350
-118
lines changed

6 files changed

+350
-118
lines changed

metals/src/main/scala/scala/meta/internal/bsp/BuildChange.scala

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ object BuildChange {
1212
case object Failed extends BuildChange
1313
case object Reconnected extends BuildChange
1414
case object Reloaded extends BuildChange
15+
case object Cancelled extends BuildChange
1516
}

metals/src/main/scala/scala/meta/internal/builds/BloopInstall.scala

+16-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package scala.meta.internal.builds
22

33
import java.util.concurrent.TimeUnit
4-
import java.util.concurrent.atomic.AtomicBoolean
54

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

3938
def runUnconditionally(
40-
buildTool: BloopInstallProvider,
41-
isImportInProcess: AtomicBoolean,
39+
buildTool: BloopInstallProvider
4240
): Future[WorkspaceLoadedStatus] = {
43-
if (isImportInProcess.compareAndSet(false, true)) {
44-
buildTool.bloopInstall(
45-
workspace,
46-
args => {
47-
scribe.info(s"running '${args.mkString(" ")}'")
48-
val process =
49-
runArgumentsUnconditionally(buildTool, args, userConfig().javaHome)
50-
process.foreach { e =>
51-
if (e.isFailed) {
52-
// Record the exact command that failed to help troubleshooting.
53-
scribe.error(s"$buildTool command failed: ${args.mkString(" ")}")
54-
}
41+
buildTool.bloopInstall(
42+
workspace,
43+
args => {
44+
scribe.info(s"running '${args.mkString(" ")}'")
45+
val process =
46+
runArgumentsUnconditionally(buildTool, args, userConfig().javaHome)
47+
process.foreach { e =>
48+
if (e.isFailed) {
49+
// Record the exact command that failed to help troubleshooting.
50+
scribe.error(s"$buildTool command failed: ${args.mkString(" ")}")
5551
}
56-
process.onComplete(_ => isImportInProcess.set(false))
57-
process
58-
},
59-
)
60-
} else {
61-
Future
62-
.successful {
63-
languageClient.showMessage(ImportAlreadyRunning)
64-
WorkspaceLoadedStatus.Dismissed
6552
}
66-
}
53+
process
54+
},
55+
)
6756
}
6857

6958
private def runArgumentsUnconditionally(
@@ -123,7 +112,6 @@ final class BloopInstall(
123112
def runIfApproved(
124113
buildTool: BloopInstallProvider,
125114
digest: String,
126-
isImportInProcess: AtomicBoolean,
127115
): Future[WorkspaceLoadedStatus] =
128116
synchronized {
129117
oldInstallResult(digest) match {
@@ -133,7 +121,7 @@ final class BloopInstall(
133121
Future.successful(result)
134122
case _ =>
135123
if (userConfig().shouldAutoImportNewProject) {
136-
runUnconditionally(buildTool, isImportInProcess)
124+
runUnconditionally(buildTool)
137125
} else {
138126
scribe.debug("Awaiting user response...")
139127
for {
@@ -145,7 +133,7 @@ final class BloopInstall(
145133
)
146134
installResult <- {
147135
if (userResponse.isYes) {
148-
runUnconditionally(buildTool, isImportInProcess)
136+
runUnconditionally(buildTool)
149137
} else {
150138
// Don't spam the user with requests during rapid build changes.
151139
notification.dismiss(2, TimeUnit.MINUTES)

0 commit comments

Comments
 (0)