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

bugfix: Remove all cancallables on finish #4432

Merged
merged 1 commit into from Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -116,9 +116,9 @@ class ShellRunner(
ps.cancel
}
}
cancelables
.add(() => ps.cancel)
.add(() => taskResponse.cancel(false))
val newCancelables: List[Cancelable] =
List(() => ps.cancel, () => taskResponse.cancel(false))
newCancelables.foreach(cancelables.add)

val processFuture = ps.complete
statusBar.trackFuture(
Expand All @@ -131,6 +131,7 @@ class ShellRunner(
scribe.info(s"time: ran '$commandRun' in $elapsed")
result.trySuccess(code)
}
result.future.onComplete(_ => newCancelables.foreach(cancelables.remove))
result.future
}

Expand Down
Expand Up @@ -133,8 +133,9 @@ class MetalsLanguageServer(
case Some(session) => session.shutdown()
case None => Future.successful(())
}
try cancelables.cancel()
catch {
try {
cancelables.cancel()
} catch {
case NonFatal(_) =>
}
try buildShutdown.asJava.get(100, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -699,21 +700,23 @@ class MetalsLanguageServer(
sourceMapper,
)
)
debugProvider = new DebugProvider(
workspace,
definitionProvider,
buildTargets,
buildTargetClasses,
compilations,
languageClient,
buildClient,
classFinder,
definitionIndex,
stacktraceAnalyzer,
clientConfig,
semanticdbs,
compilers,
statusBar,
debugProvider = register(
new DebugProvider(
workspace,
definitionProvider,
buildTargets,
buildTargetClasses,
compilations,
languageClient,
buildClient,
classFinder,
definitionIndex,
stacktraceAnalyzer,
clientConfig,
semanticdbs,
compilers,
statusBar,
)
)
scalafixProvider = ScalafixProvider(
buffers,
Expand Down Expand Up @@ -1972,7 +1975,6 @@ class MetalsLanguageServer(
)
} yield {
statusBar.addMessage("Started debug server!")
cancelables.add(server)
DebugSession(server.sessionName, server.uri.toString)
}
session.asJavaObject
Expand Down
Expand Up @@ -20,6 +20,7 @@ import scala.util.control.NonFatal

import scala.meta.internal.metals.BuildServerConnection
import scala.meta.internal.metals.BuildTargets
import scala.meta.internal.metals.Cancelable
import scala.meta.internal.metals.ClientCommands
import scala.meta.internal.metals.ClientConfiguration
import scala.meta.internal.metals.Compilations
Expand All @@ -35,6 +36,7 @@ import scala.meta.internal.metals.Messages
import scala.meta.internal.metals.Messages.UnresolvedDebugSessionParams
import scala.meta.internal.metals.MetalsBuildClient
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.MutableCancelable
import scala.meta.internal.metals.ScalaTestSuites
import scala.meta.internal.metals.ScalaTestSuitesDebugRequest
import scala.meta.internal.metals.ScalaVersionSelector
Expand Down Expand Up @@ -84,10 +86,14 @@ class DebugProvider(
semanticdbs: Semanticdbs,
compilers: Compilers,
statusBar: StatusBar,
) {
) extends Cancelable {

import DebugProvider._

private val debugSessions = new MutableCancelable()

override def cancel(): Unit = debugSessions.cancel()

lazy val buildTargetClassesFinder = new BuildTargetClassesFinder(
buildTargets,
buildTargetClasses,
Expand Down Expand Up @@ -185,7 +191,11 @@ class DebugProvider(
}
val server = new DebugServer(sessionName, uri, proxyFactory)

server.listen.andThen { case _ => proxyServer.close() }
debugSessions.add(server)
server.listen.andThen { case _ =>
proxyServer.close()
debugSessions.remove(server)
}

connectedToServer.future.map(_ => server)
}
Expand Down