Skip to content

Commit

Permalink
bugfix: auto-connect to build server
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Oct 10, 2023
1 parent 2a57231 commit 1ad9f07
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,14 @@ class MetalsLspService(
cancel()
}

def onUserConfigUpdate(newConfig: UserConfiguration): Future[Unit] = {
def setUserConfig(newConfig: UserConfiguration): UserConfiguration = {
val old = userConfig
userConfig = newConfig
old
}

def onUserConfigUpdate(newConfig: UserConfiguration): Future[Unit] = {
val old = setUserConfig(newConfig)
if (userConfig.excludedPackages != old.excludedPackages) {
excludedPackageHandler = ExcludedPackagesHandler.fromUserConfiguration(
userConfig.excludedPackages.getOrElse(Nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ class UserConfigurationSync(
out <- Option(workspace.getConfiguration())
} yield out.booleanValue()).getOrElse(false)

def syncUserConfiguration(services: List[MetalsLspService]): Future[Unit] =
optSyncUserConfiguration(services).getOrElse(Future.successful(()))
def initSyncUserConfiguration(
services: List[MetalsLspService]
): Future[Unit] =
optSyncUserConfiguration(
services,
folder =>
newConfig => {
folder.setUserConfig(newConfig)
Future.unit
},
).getOrElse(Future.successful(()))

def onDidChangeConfiguration(
params: lsp4j.DidChangeConfigurationParams,
services: List[MetalsLspService],
): Future[Unit] =
optSyncUserConfiguration(services)
optSyncUserConfiguration(
services,
folder => newConfig => folder.onUserConfigUpdate(newConfig),
)
.orElse {
val fullJson =
params.getSettings.asInstanceOf[JsonElement].getAsJsonObject
Expand All @@ -44,7 +56,8 @@ class UserConfigurationSync(
.getOrElse(Future.successful(()))

private def optSyncUserConfiguration(
services: List[MetalsLspService]
services: List[MetalsLspService],
consume: MetalsLspService => UserConfiguration => Future[Unit],
): Option[Future[Unit]] =
Option.when(supportsConfiguration) {
val items = services.map { service =>
Expand All @@ -63,7 +76,7 @@ class UserConfigurationSync(
case (item, folder) =>
val json = item.asInstanceOf[JsonElement].getAsJsonObject()
userConfigFrom(json)
.map(folder.onUserConfigUpdate)
.map(consume(folder))
.getOrElse(Future.successful(()))
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class WorkspaceFolders(

val services = newServices.filterNot(isIn(prev, _))
for {
_ <- userConfigSync.syncUserConfiguration(services)
_ <- userConfigSync.initSyncUserConfiguration(services)
_ <- Future.sequence(services.map(_.initialized()))
_ <- Future(prev.filter(shouldBeRemoved).foreach(_.onShutdown()))
} yield ()
Expand All @@ -86,7 +86,7 @@ class WorkspaceFolders(
case None =>
setupLogger()
userConfigSync
.syncUserConfiguration(List(newService))
.initSyncUserConfiguration(List(newService))
.map(_ => newService.initialized())
newService
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ class WorkspaceLspService(
def initialized(): Future[Unit] = {
statusBar.start(sh, 0, 1, ju.concurrent.TimeUnit.SECONDS)
for {
_ <- userConfigSync.syncUserConfiguration(folderServices)
_ <- userConfigSync.initSyncUserConfiguration(folderServices)
_ <- Future.sequence(folderServices.map(_.initialized()))
_ <- Future(startHttpServer())
} yield ()
Expand Down

0 comments on commit 1ad9f07

Please sign in to comment.