use of org.eclipse.lsp4j.jsonrpc.messages.ResponseError in project xtext-core by eclipse.
the class ServerRefactoringIssueAcceptor method checkSeverity.
public void checkSeverity() {
RefactoringIssueAcceptor.Severity _maximumSeverity = this.getMaximumSeverity();
boolean _lessThan = (_maximumSeverity.compareTo(RefactoringIssueAcceptor.Severity.WARNING) < 0);
if (_lessThan) {
ResponseError _responseError = this.toResponseError();
throw new ResponseErrorException(_responseError);
}
}
use of org.eclipse.lsp4j.jsonrpc.messages.ResponseError in project eclipse.jdt.ls by eclipse.
the class WorkspaceExecuteCommandHandler method executeCommand.
/**
* Execute workspace command and invoke language server delegate command
* handler for matching command
*
* @param params
* parameter from the protocol
* @param monitor
* @return execution result
*/
public Object executeCommand(ExecuteCommandParams params, IProgressMonitor monitor) {
if (params == null || params.getCommand() == null) {
String errorMessage = "The workspace/executeCommand has empty params or command";
JavaLanguageServerPlugin.logError(errorMessage);
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InvalidParams, errorMessage, null));
}
Set<DelegateCommandHandlerDescriptor> handlers = getDelegateCommandHandlerDescriptors();
// no cancellation here but it's super fast so it's ok.
Collection<DelegateCommandHandlerDescriptor> candidates = handlers.stream().filter(desc -> desc.getCommands().contains(params.getCommand())).collect(Collectors.toSet());
if (candidates.size() > 1) {
Exception ex = new IllegalStateException(String.format("Found multiple delegateCommandHandlers (%s) matching command %s", candidates, params.getCommand()));
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InternalError, ex.getMessage(), ex));
}
if (monitor.isCanceled()) {
return "";
}
if (candidates.isEmpty()) {
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.MethodNotFound, String.format("No delegateCommandHandler for %s", params.getCommand()), null));
}
final Object[] resultValues = new Object[1];
SafeRunner.run(new ISafeRunnable() {
@Override
public void run() throws Exception {
final IDelegateCommandHandler delegateCommandHandler = candidates.iterator().next().getDelegateCommandHandler();
if (delegateCommandHandler != null) {
// Convert args to java objects before sending to extensions
List<Object> args = Collections.emptyList();
if (params.getArguments() != null) {
args = params.getArguments().stream().map((element) -> {
return JSONUtility.toModel(element, Object.class);
}).collect(Collectors.toList());
}
resultValues[0] = delegateCommandHandler.executeCommand(params.getCommand(), args, monitor);
}
}
@Override
public void handleException(Throwable ex) {
IStatus status = new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, IStatus.OK, "Error in calling delegate command handler", ex);
JavaLanguageServerPlugin.log(status);
if (ex instanceof ResponseErrorException) {
throw (ResponseErrorException) ex;
}
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.UnknownErrorCode, ex.getMessage(), ex));
}
});
return resultValues[0];
}
use of org.eclipse.lsp4j.jsonrpc.messages.ResponseError in project xtext-core by eclipse.
the class ServerRefactoringIssueAcceptor method toResponseError.
public ResponseError toResponseError() {
ResponseError _xblockexpression = null;
{
final RefactoringIssueAcceptor.Severity maxSeverity = this.getMaximumSeverity();
ResponseError _responseError = new ResponseError();
final Procedure1<ResponseError> _function = (ResponseError it) -> {
String _switchResult = null;
if (maxSeverity != null) {
switch(maxSeverity) {
case OK:
_switchResult = "Refactoring is possible";
break;
case INFO:
_switchResult = "Refactoring is possible";
break;
case WARNING:
_switchResult = "Refactoring could cause issues";
break;
case ERROR:
_switchResult = "Refactoring has errors";
break;
case FATAL:
_switchResult = "Refactoring cannot be performed";
break;
default:
break;
}
}
it.setMessage(_switchResult);
final Function1<ServerRefactoringIssueAcceptor.Issue, RefactoringIssueAcceptor.Severity> _function_1 = (ServerRefactoringIssueAcceptor.Issue it_1) -> {
return it_1.severity;
};
final Function1<ServerRefactoringIssueAcceptor.Issue, String> _function_2 = (ServerRefactoringIssueAcceptor.Issue it_1) -> {
return it_1.message;
};
it.setData(IterableExtensions.join(ListExtensions.<ServerRefactoringIssueAcceptor.Issue, String>map(ListExtensions.<ServerRefactoringIssueAcceptor.Issue>reverse(IterableExtensions.<ServerRefactoringIssueAcceptor.Issue, RefactoringIssueAcceptor.Severity>sortBy(this.issues, _function_1)), _function_2), "\n"));
int _switchResult_1 = (int) 0;
if (maxSeverity != null) {
switch(maxSeverity) {
case OK:
_switchResult_1 = 0;
break;
case INFO:
_switchResult_1 = 0;
break;
case WARNING:
_switchResult_1 = 0;
break;
case ERROR:
_switchResult_1 = ResponseErrorCode.UnknownErrorCode.getValue();
break;
case FATAL:
_switchResult_1 = ResponseErrorCode.UnknownErrorCode.getValue();
break;
default:
break;
}
}
it.setCode(_switchResult_1);
};
_xblockexpression = ObjectExtensions.<ResponseError>operator_doubleArrow(_responseError, _function);
}
return _xblockexpression;
}
use of org.eclipse.lsp4j.jsonrpc.messages.ResponseError 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