diff --git a/engine/language-server/src/main/java/org/enso/languageserver/boot/resource/RepoInitialization.java b/engine/language-server/src/main/java/org/enso/languageserver/boot/resource/RepoInitialization.java index 40b74dc72f7..2912e6ec990 100644 --- a/engine/language-server/src/main/java/org/enso/languageserver/boot/resource/RepoInitialization.java +++ b/engine/language-server/src/main/java/org/enso/languageserver/boot/resource/RepoInitialization.java @@ -63,7 +63,7 @@ public class RepoInitialization implements InitializationComponent { return initSuggestionsRepo() .whenCompleteAsync( (res, err) -> { - if (err == null && res != null) { + if (err == null) { isInitialized = true; } lock.release(); diff --git a/engine/language-server/src/main/java/org/enso/languageserver/boot/resource/YdocInitialization.java b/engine/language-server/src/main/java/org/enso/languageserver/boot/resource/YdocInitialization.java new file mode 100644 index 00000000000..e8217b3477f --- /dev/null +++ b/engine/language-server/src/main/java/org/enso/languageserver/boot/resource/YdocInitialization.java @@ -0,0 +1,29 @@ +package org.enso.languageserver.boot.resource; + +import java.util.concurrent.Executor; +import org.enso.ydoc.Ydoc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class YdocInitialization extends LockedInitialization { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + private final Ydoc ydoc; + + public YdocInitialization(Executor executor, Ydoc ydoc) { + super(executor); + this.ydoc = ydoc; + } + + @Override + public void initComponent() { + logger.info("Starting Ydoc server..."); + try { + ydoc.start(); + } catch (Exception e) { + throw new RuntimeException(e); + } + logger.info("Started Ydoc server."); + } +} diff --git a/engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala b/engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala index 54d181d3fee..cb1b298228b 100644 --- a/engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala +++ b/engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala @@ -440,6 +440,12 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: Level) { private val jsonRpcProtocolFactory = new JsonRpcProtocolFactory + private val ydoc = Ydoc + .builder() + .hostname(applicationConfig.ydoc.hostname) + .port(applicationConfig.ydoc.port) + .build() + private val initializationComponent = ResourcesInitialization( system.eventStream, @@ -447,7 +453,8 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: Level) { jsonRpcProtocolFactory, suggestionsRepo, context, - zioRuntime + zioRuntime, + ydoc )(system.dispatcher) private val jsonRpcControllerFactory = new JsonConnectionControllerFactory( @@ -510,14 +517,6 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: Level) { ) log.trace("Created Binary WebSocket Server [{}].", binaryServer) - private val ydoc = Ydoc - .builder() - .hostname(applicationConfig.ydoc.hostname) - .port(applicationConfig.ydoc.port) - .build() - ydoc.start() - log.debug("Started Ydoc server.") - log.info( "Main module of the Language Server initialized with config [{}].", languageServerConfig diff --git a/engine/language-server/src/main/scala/org/enso/languageserver/boot/ResourcesInitialization.scala b/engine/language-server/src/main/scala/org/enso/languageserver/boot/ResourcesInitialization.scala index 9feac947fab..6a3abc34ec9 100644 --- a/engine/language-server/src/main/scala/org/enso/languageserver/boot/ResourcesInitialization.scala +++ b/engine/language-server/src/main/scala/org/enso/languageserver/boot/ResourcesInitialization.scala @@ -10,11 +10,13 @@ import org.enso.languageserver.boot.resource.{ RepoInitialization, SequentialResourcesInitialization, TruffleContextInitialization, + YdocInitialization, ZioRuntimeInitialization } import org.enso.languageserver.data.ProjectDirectoriesConfig import org.enso.languageserver.effect import org.enso.searcher.memory.InMemorySuggestionsRepo +import org.enso.ydoc.Ydoc import org.graalvm.polyglot.Context import scala.concurrent.ExecutionContextExecutor @@ -32,6 +34,7 @@ object ResourcesInitialization { * @param suggestionsRepo the suggestions repo * @param truffleContext the runtime context * @param runtime the runtime to run effects + * @param ydoc the ydoc server * @return the initialization component */ def apply( @@ -40,7 +43,8 @@ object ResourcesInitialization { protocolFactory: ProtocolFactory, suggestionsRepo: InMemorySuggestionsRepo, truffleContext: Context, - runtime: effect.Runtime + runtime: effect.Runtime, + ydoc: Ydoc )(implicit ec: ExecutionContextExecutor): InitializationComponent = { new SequentialResourcesInitialization( ec, @@ -54,7 +58,8 @@ object ResourcesInitialization { eventStream, suggestionsRepo ), - new TruffleContextInitialization(ec, truffleContext, eventStream) + new TruffleContextInitialization(ec, truffleContext, eventStream), + new YdocInitialization(ec, ydoc) ) ) }