use of org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider in project xtext-core by eclipse.
the class LanguageServerImpl method supportedMethods.
@Override
public Map<String, JsonRpcMethod> supportedMethods() {
if (supportedMethods != null) {
return supportedMethods;
}
synchronized (extensionProviders) {
Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(getClass()));
Map<String, JsonRpcMethod> extensions = new LinkedHashMap<>();
for (IResourceServiceProvider resourceServiceProvider : getAllLanguages()) {
ILanguageServerExtension ext = resourceServiceProvider.get(ILanguageServerExtension.class);
if (ext != null) {
ext.initialize(access);
Map<String, JsonRpcMethod> supportedExtensions = ext instanceof JsonRpcMethodProvider ? ((JsonRpcMethodProvider) ext).supportedMethods() : ServiceEndpoints.getSupportedMethods(ext.getClass());
for (Map.Entry<String, JsonRpcMethod> entry : supportedExtensions.entrySet()) {
if (supportedMethods.containsKey(entry.getKey())) {
LOG.error("The json rpc method \'" + entry.getKey() + "\' can not be an extension as it is already defined in the LSP standard.");
} else {
JsonRpcMethod existing = extensions.put(entry.getKey(), entry.getValue());
if (existing != null && !Objects.equal(existing, entry.getValue())) {
LOG.error("An incompatible LSP extension \'" + entry.getKey() + "\' has already been registered. Using 1 ignoring 2. \n1 : " + existing + " \n2 : " + entry.getValue());
extensions.put(entry.getKey(), existing);
} else {
Endpoint endpoint = ServiceEndpoints.toEndpoint(ext);
extensionProviders.put(entry.getKey(), endpoint);
supportedMethods.put(entry.getKey(), entry.getValue());
}
}
}
}
}
this.supportedMethods = supportedMethods;
return supportedMethods;
}
}
use of org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider 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;
}
};
}
Aggregations