Skip to content

Commit

Permalink
refactor: move excepton handler closer to the exception
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenporras committed Sep 5, 2024
1 parent 74d276e commit 4ee815f
Showing 1 changed file with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +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 (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 Expand Up @@ -165,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 4ee815f

Please sign in to comment.