Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ConnectionProvider(
indexProviders: IndexProviders,
syncStatusReporter: SyncStatusReporter,
mbtBuild: () => MbtBuild,
refreshMbtStateAfterIndex: () => Future[Unit] = () => Future.unit,
mbtDebugStarter: () => Option[MbtDebugSessionStarter] = () => None,
)(implicit ec: ExecutionContextExecutorService, rc: ReportContext)
extends Indexer(indexProviders, mbtBuild)
Expand Down Expand Up @@ -679,32 +680,27 @@ class ConnectionProvider(
}
_ = compilers.cancel()
buildChange <- index(check, progress)
// When testing we need to make sure the classpath is refreshed after mbt.json is generated
_ <- {
if (MetalsServerConfig.isTesting)
refreshMbtTurbineClasspath(session).withInterrupt
else
Future {
refreshMbtTurbineClasspath(session)
}.withInterrupt
}
_ <- refreshMbtStateAfterIndexIfNeeded(session)
} yield {
syncStatusReporter.importFinished(focusedDocument.map(_.toURI.toString))
buildChange
}
}

private def refreshMbtTurbineClasspath(
private def refreshMbtStateAfterIndexIfNeeded(
session: BspSession
): Future[Unit] =
if (
MbtBuildServer.isMbtServer(session.main.name) &&
userConfig.javaSymbolLoader.isTurbineClasspath
) {
mbtSymbolSearch.scheduleRecompileTurbineClasspath()
} else {
Future.unit
}
): Interruptable[Unit] = {
val refresh =
if (MbtBuildServer.isMbtServer(session.main.name))
refreshMbtStateAfterIndex()
else Future.unit

if (MetalsServerConfig.isTesting) refresh.withInterrupt
else
refresh.recover { case error =>
scribe.warn("failed to refresh MBT diagnostics", error)
}.withInterrupt
}

private def saveProjectReferencesInfo(
bspBuilds: List[BspSession.BspBuild]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,18 @@ abstract class MetalsLspService(
private def refreshAllDiagnostics(): Future[Unit] = {
refreshDiagnostics(_ => true)
}

protected def refreshMbtStateAfterIndex(): Future[Unit] = {
val refresh =
if (userConfig.javaSymbolLoader.isTurbineClasspath)
mbt2.recompileTurbineClasspath()
Comment thread
zielinsky marked this conversation as resolved.
Outdated
else Future.unit
refresh
.map(_ => compilers.cancel())
.map(_ => diagnostics.reset(buffers.open.toSeq))
.flatMap(_ => refreshAllDiagnostics())
}

protected def refreshDiagnostics(
isIncludedPath: AbsolutePath => Boolean
): Future[Unit] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class ProjectMetalsLspService(
this,
syncStatusReporter,
() => mbtBuild,
() => refreshMbtStateAfterIndex(),
mbtDebugStarter = () => mbtDebugStarter,
)
provider.buildServerPromise.future.onComplete(_ => moduleStatus.refresh())
Expand Down
Loading