Skip to content

Commit

Permalink
HCR only compiles needed targets
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Feb 8, 2024
1 parent d07b80c commit 03fce9b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ final class Compilations(
Future.sequence(expansions).map(_.flatten)
}

def compileAll(): Future[Map[BuildTargetIdentifier, b.CompileResult]] =
compile(None)(buildTargets.allBuildTargetIds).future

private def compile(timeout: Option[Timeout])(
targets: Seq[b.BuildTargetIdentifier]
): CancelableFuture[Map[BuildTargetIdentifier, b.CompileResult]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class DebugProvider(
statusBar,
sourceMapper,
compilations,
targets,
)
}
val server = new DebugServer(sessionName, uri, proxyFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import scala.meta.internal.metals.debug.DebugProtocol.SetBreakpointRequest
import scala.meta.internal.metals.debug.DebugProxy._
import scala.meta.io.AbsolutePath

import ch.epfl.scala.bsp4j.BuildTargetIdentifier
import org.eclipse.lsp4j.Position
import org.eclipse.lsp4j.debug.Breakpoint
import org.eclipse.lsp4j.debug.CompletionsResponse
Expand All @@ -45,8 +46,6 @@ import org.eclipse.lsp4j.jsonrpc.debug.messages.DebugResponseMessage
import org.eclipse.lsp4j.jsonrpc.messages.Message
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError
import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode
import scala.util.Success
import scala.util.Failure

private[debug] final class DebugProxy(
sessionName: String,
Expand All @@ -59,6 +58,7 @@ private[debug] final class DebugProxy(
statusBar: StatusBar,
sourceMapper: SourceMapper,
compilations: Compilations,
targets: Seq[BuildTargetIdentifier],
)(implicit ec: ExecutionContext) {
private val exitStatus = Promise[ExitStatus]()
@volatile private var outputTerminated = false
Expand All @@ -67,7 +67,7 @@ private[debug] final class DebugProxy(

@volatile private var clientAdapter =
ClientConfigurationAdapter.default(sourceMapper)
@volatile private var frameIdToFrame: TrieMap[Int, StackFrame] = TrieMap.empty
private val frameIdToFrame: TrieMap[Int, StackFrame] = TrieMap.empty

lazy val listen: Future[ExitStatus] = {
scribe.info(s"Starting debug proxy for [$sessionName]")
Expand Down Expand Up @@ -190,23 +190,21 @@ private[debug] final class DebugProxy(
case HotCodeReplace(req) =>
scribe.info("Hot code replace triggered")
compilations
.compileAll()
.onComplete { res =>
res match {
case _: Success[?] => server.send(req)
case Failure(e) =>
val res = new DebugResponseMessage
res.setId(req.getId)
res.setMethod(req.getMethod)
res.setError(
new ResponseError(
ResponseErrorCode.InternalError,
s"Failed to compile ${e.getLocalizedMessage()}",
null,
)
.compileTargets(targets)
.onComplete {
case _: Success[?] => server.send(req)
case Failure(e) =>
val res = new DebugResponseMessage
res.setId(req.getId)
res.setMethod(req.getMethod)
res.setError(
new ResponseError(
ResponseErrorCode.InternalError,
s"Failed to compile ${e.getLocalizedMessage()}",
null,
)
client.consume(res)
}
)
client.consume(res)
}

case message => server.send(message)
Expand Down Expand Up @@ -317,6 +315,7 @@ private[debug] object DebugProxy {
status: StatusBar,
sourceMapper: SourceMapper,
compilations: Compilations,
targets: Seq[BuildTargetIdentifier],
)(implicit ec: ExecutionContext): Future[DebugProxy] = {
for {
server <- connectToServer()
Expand All @@ -343,6 +342,7 @@ private[debug] object DebugProxy {
status,
sourceMapper,
compilations,
targets,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.eclipse.lsp4j.debug.SetBreakpointsArguments
* - a file in a build target SourceItem
* - a file in a build target DependencySourcesItem
*
* If it is a file in a DependencySourcesItem, the [[MetalsDebugAdapter2x]] maps it to
* If it is a file in a DependencySourcesItem, the [[MetalsDebugAdapter]] maps it to
* its corresponding file in the .metals/readonly/dependencies/ folder.
*/
private[debug] class MetalsDebugAdapter(sourcePathAdapter: SourcePathAdapter) {
Expand Down

0 comments on commit 03fce9b

Please sign in to comment.