use of org.eclipse.lsp4j.jsonrpc.Endpoint 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.Endpoint in project xtext-core by eclipse.
the class LanguageServerImpl method request.
@Override
public CompletableFuture<?> request(final String method, final Object parameter) {
boolean _containsKey = this.extensionProviders.containsKey(method);
boolean _not = (!_containsKey);
if (_not) {
throw new UnsupportedOperationException((("The json request \'" + method) + "\' is unknown."));
}
Collection<Endpoint> _get = this.extensionProviders.get(method);
for (final Endpoint endpoint : _get) {
try {
return endpoint.request(method, parameter);
} catch (final Throwable _t) {
if (_t instanceof UnsupportedOperationException) {
final UnsupportedOperationException e = (UnsupportedOperationException) _t;
if ((e != ILanguageServerExtension.NOT_HANDLED_EXCEPTION)) {
throw e;
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
return null;
}
use of org.eclipse.lsp4j.jsonrpc.Endpoint in project ballerina by ballerina-lang.
the class CommonUtil method getLanguageServerResponseMessageAsString.
/**
* Get the definition response message as a string.
*
* @param position hovering position to get the definition.
* @param file bal file path
* @param fileContent bal file content
* @param method string name of the language feature method
* @return json string value of the response
*/
public static String getLanguageServerResponseMessageAsString(Position position, String file, String fileContent, String method) throws InterruptedException {
Gson gson = new Gson();
BallerinaLanguageServer ballerinaLanguageServer = new BallerinaLanguageServer();
Endpoint serviceEndpoint = ServiceEndpoints.toEndpoint(ballerinaLanguageServer);
TextDocumentPositionParams positionParams = new TextDocumentPositionParams();
TextDocumentIdentifier identifier = new TextDocumentIdentifier();
identifier.setUri(Paths.get(file).toUri().toString());
positionParams.setTextDocument(identifier);
positionParams.setPosition(position);
DidOpenTextDocumentParams documentParams = new DidOpenTextDocumentParams();
TextDocumentItem textDocumentItem = new TextDocumentItem();
textDocumentItem.setUri(identifier.getUri());
textDocumentItem.setText(fileContent);
documentParams.setTextDocument(textDocumentItem);
serviceEndpoint.notify("textDocument/didOpen", documentParams);
CompletableFuture result = serviceEndpoint.request(method, positionParams);
ResponseMessage jsonrpcResponse = new ResponseMessage();
try {
jsonrpcResponse.setId("324");
jsonrpcResponse.setResult(result.get());
} catch (InterruptedException e) {
ResponseError responseError = new ResponseError();
responseError.setCode(-32002);
responseError.setMessage("Attempted to retrieve the result of a task/s" + "that was aborted by throwing an exception");
jsonrpcResponse.setError(responseError);
} catch (ExecutionException e) {
ResponseError responseError = new ResponseError();
responseError.setCode(-32001);
responseError.setMessage("Current thread was interrupted");
jsonrpcResponse.setError(responseError);
}
return gson.toJson(jsonrpcResponse);
}
Aggregations