Skip to content

Commit

Permalink
fix: Adapt resolveCodeAction to handle timeout and interrupted exception
Browse files Browse the repository at this point in the history
Adapt resolveCodeAction to handle timeout and interrupted exception to
follow the usual pattern in the codebase (TimeoutException -> log
warning giving the time constraint, InterruptedException -> interrupt
thread and log error).
  • Loading branch information
rubenporras committed Sep 5, 2024
1 parent 5a9f461 commit 37907db
Showing 1 changed file with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,29 @@ public void run(IMarker marker) {
LSPEclipseUtils.applyWorkspaceEdit(codeAction.getEdit(), codeAction.getTitle());
return;
}
try {
LanguageServerWrapper wrapper = getLanguageServerWrapper(marker);
if (wrapper != null) {
resolveCodeAction(wrapper);
if (codeAction.getEdit() != null) {
LSPEclipseUtils.applyWorkspaceEdit(codeAction.getEdit(), codeAction.getTitle());
}
if (codeAction.getCommand() != null) {
Command command = codeAction.getCommand();
ServerCapabilities cap = wrapper.getServerCapabilities();
ExecuteCommandOptions provider = cap == null ? null : cap.getExecuteCommandProvider();
if (provider != null && provider.getCommands().contains(command.getCommand())) {
final LanguageServerDefinition serverDefinition = wrapper.serverDefinition;
wrapper.execute(ls -> ls.getWorkspaceService()
.executeCommand(new ExecuteCommandParams(command.getCommand(), command.getArguments()))
.exceptionally(t -> reportServerError(serverDefinition, t))
);
} else {
IResource resource = marker.getResource();
if (resource != null) {
CommandExecutor.executeCommandClientSide(command, resource);
}
LanguageServerWrapper wrapper = getLanguageServerWrapper(marker);
if (wrapper != null) {
resolveCodeAction(wrapper);
if (codeAction.getEdit() != null) {
LSPEclipseUtils.applyWorkspaceEdit(codeAction.getEdit(), codeAction.getTitle());
}
if (codeAction.getCommand() != null) {
Command command = codeAction.getCommand();
ServerCapabilities cap = wrapper.getServerCapabilities();
ExecuteCommandOptions provider = cap == null ? null : cap.getExecuteCommandProvider();
if (provider != null && provider.getCommands().contains(command.getCommand())) {
final LanguageServerDefinition serverDefinition = wrapper.serverDefinition;
wrapper.execute(ls -> ls.getWorkspaceService()
.executeCommand(new ExecuteCommandParams(command.getCommand(), command.getArguments()))
.exceptionally(t -> reportServerError(serverDefinition, t))
);
} else {
IResource resource = marker.getResource();
if (resource != null) {
CommandExecutor.executeCommandClientSide(command, resource);
}
}
}
} catch (ExecutionException | TimeoutException | InterruptedException ex) {
LanguageServerPlugin.logError(ex);
}
}

Expand Down Expand Up @@ -159,15 +155,24 @@ public IMarker[] findOtherMarkers(IMarker[] markers) {
* @param wrapper
* the wrapper for the language server to send the resolve request to.
*/
public void resolveCodeAction(LanguageServerWrapper wrapper)
throws InterruptedException, ExecutionException, TimeoutException {
public void resolveCodeAction(LanguageServerWrapper wrapper) {
if (codeAction.getEdit() != null) {
return;
}
if (CodeActionCompletionProposal.isCodeActionResolveSupported(wrapper.getServerCapabilities())) {
CodeAction resolvedCodeAction = wrapper.execute(ls -> ls.getTextDocumentService().resolveCodeAction(codeAction)).get(2, TimeUnit.SECONDS);
if (resolvedCodeAction != null) {
codeAction = resolvedCodeAction;
try {
CodeAction resolvedCodeAction = wrapper.execute(ls -> ls.getTextDocumentService().resolveCodeAction(codeAction)).get(2, TimeUnit.SECONDS);
if (resolvedCodeAction != null) {
codeAction = resolvedCodeAction;
}
} catch (TimeoutException e) {
LanguageServerPlugin.logWarning(
"Could resolve code actions due to timeout after 2 seconds in `textDocument/resolveCodeAction`", e); //$NON-NLS-1$
} catch (ExecutionException e) {
LanguageServerPlugin.logError(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LanguageServerPlugin.logError(e);
}
}
}
Expand Down

0 comments on commit 37907db

Please sign in to comment.