TypeFox / ls-api

MOVED TO
https://github.com/eclipse/lsp4j
20 stars 8 forks source link

LanguageClientEndpoint.connect(...) is now a blocking operation #42

Closed mickaelistria closed 8 years ago

mickaelistria commented 8 years ago

It seems like LanguageClientEndpoint.connect() is now a blocking operation, which requires to be started in a separate thread/job. This is not the usual way for a connect(..) method and not the way it used to work with previous versions of ls-api. Most example of connect(...) I have in mind are non-blocking and responsible of setting up the necessary threads, returning a connection object that can allow to join on some operations.

akosyakov commented 8 years ago

@mickaelistria Do you use ConcurrentMessageReader or plain StreamMessageReader?

mickaelistria commented 8 years ago

Plain StreamMessageReader. But I coul duse the ConcurrentMessageReader if that's better for background work. Do you have an example? What value should be given to ExecutorService?

akosyakov commented 8 years ago

@mickaelistria new ConcurrentMessageReader(new StreamMessageReader(...), executorService))

mickaelistria commented 8 years ago

yeah, my question was more what is a good value to pass as executor service?

akosyakov commented 8 years ago

Currently it let you use the same executor service for LanguageClientEndpoint and ConcurrentMessageReader. There could be some factory that does it for you. But it cannot not be a part of LanguageClientEndpoint, since generally there can be clients which don't want non-blocking behaviour. For example for web sockets one can provide a special reader which is called on a message event and just delegates to the steam reader.

mickaelistria commented 8 years ago

Here is how I've implemented it:

ExecutorService executorService = Executors.newCachedThreadPool();
this.languageClient = new LanguageClientEndpoint(executorService);
this.lspStreamProvider.start();
MessageJsonHandler jsonHandler = new MessageJsonHandler();
jsonHandler.setMethodResolver(this.languageClient);
MessageReader reader = new ConcurrentMessageReader(new StreamMessageReader(this.lspStreamProvider.getInputStream(), jsonHandler), executorService);
MessageWriter writer = new StreamMessageWriter(this.lspStreamProvider.getOutputStream(), jsonHandler);
languageClient.connect(reader, writer);