use of org.eclipse.lsp4j.jsonrpc.ResponseErrorException 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.ResponseErrorException 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];
}
Aggregations