Async Ydoc initialization (#10290)

close #10265

Changelog:
- add: YdocInitialization component
This commit is contained in:
Dmitry Bushev 2024-06-17 09:10:21 +01:00 committed by GitHub
parent 20998e30b0
commit 06a73606b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 12 deletions

View File

@ -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();

View File

@ -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.");
}
}

View File

@ -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

View File

@ -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)
)
)
}