use of org.eclipse.lsp4j.jsonrpc.MessageConsumer in project sts4 by spring-projects.
the class LaunguageServerApp method run.
/**
* Listen for requests from the parent node process.
* Send replies asynchronously.
* When the request stream is closed, wait for 5s for all outstanding responses to compute, then return.
* @throws ExecutionException
* @throws InterruptedException
*/
protected void run(Connection connection) throws InterruptedException, ExecutionException {
LanguageServer server = createServer();
ExecutorService executor = createServerThreads();
Function<MessageConsumer, MessageConsumer> wrapper = (MessageConsumer consumer) -> {
return (msg) -> {
try {
consumer.consume(msg);
} catch (UnsupportedOperationException e) {
// log a warning and ignore. We are getting some messages from vsCode the server doesn't know about
Log.warn("Unsupported message was ignored!", e);
}
};
};
Launcher<STS4LanguageClient> launcher = Launcher.createLauncher(server, STS4LanguageClient.class, connection.in, connection.out, executor, wrapper);
if (server instanceof LanguageClientAware) {
LanguageClient client = launcher.getRemoteProxy();
((LanguageClientAware) server).connect(client);
}
launcher.startListening().get();
}
use of org.eclipse.lsp4j.jsonrpc.MessageConsumer in project ballerina by ballerina-lang.
the class BallerinaLangServerService method launchRPCServer.
private <T> Launcher<T> launchRPCServer(Object localService, Class<T> remoteInterface) {
Consumer<GsonBuilder> configureGson = (gsonBuilder) -> {
};
Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap();
supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(remoteInterface));
if (localService instanceof JsonRpcMethodProvider) {
JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService;
supportedMethods.putAll(rpcMethodProvider.supportedMethods());
} else {
supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass()));
}
MessageJsonHandler jsonHandler = new MessageJsonHandler(supportedMethods, configureGson);
MessageConsumer outGoingMessageStream = new WSRPCMessageConsumer(this, jsonHandler);
RemoteEndpoint serverEndpoint = new RemoteEndpoint(outGoingMessageStream, ServiceEndpoints.toEndpoint(localService));
jsonHandler.setMethodProvider(serverEndpoint);
final MessageConsumer messageConsumer = serverEndpoint;
final MessageProducer reader = new WSRPCMessageProducer(this, jsonHandler);
final T remoteProxy = ServiceEndpoints.toServiceObject(serverEndpoint, remoteInterface);
return new Launcher<T>() {
public Future<?> startListening() {
return ConcurrentMessageProcessor.startProcessing(reader, messageConsumer, Executors.newCachedThreadPool());
}
public T getRemoteProxy() {
return remoteProxy;
}
};
}
use of org.eclipse.lsp4j.jsonrpc.MessageConsumer in project sts4 by spring-projects.
the class LaunguageServerApp method startAsServer.
/**
* starts up the language server and let it listen for connections from the outside
* instead of connecting itself to an existing port or channel.
*
* This is meant for development only, to reduce turnaround times while working
* on the language server from within an IDE, so that you can start the language
* server right away in debug mode and let the vscode extension connect to that
* instance instead of vice versa.
*
* Source of inspiration:
* https://github.com/itemis/xtext-languageserver-example/blob/master/org.xtext.example.mydsl.ide/src/org/xtext/example/mydsl/ide/RunServer.java
*/
public void startAsServer() throws IOException, InterruptedException {
Log.info("Starting LS as standlone server");
Function<MessageConsumer, MessageConsumer> wrapper = consumer -> {
MessageConsumer result = consumer;
return result;
};
SimpleLanguageServer languageServer = createServer();
Launcher<STS4LanguageClient> launcher = createSocketLauncher(languageServer, STS4LanguageClient.class, new InetSocketAddress("localhost", SERVER_STANDALONE_PORT), createServerThreads(), wrapper);
languageServer.connect(launcher.getRemoteProxy());
Future<?> future = launcher.startListening();
while (!future.isDone()) {
Thread.sleep(10_000l);
}
}
Aggregations