Skip to content

Commit

Permalink
refact: remove not-thrown exceptions from throws clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom authored and mickaelistria committed May 21, 2024
1 parent 50c0e37 commit a27b7a9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ public void testStopAndActive() throws CoreException, IOException, AssertionErro
started.countDown();
while (!Thread.interrupted()) {
wrapper.stop();
try {
wrapper.start();
} catch (IOException e) {
throw new RuntimeException(e);
}
wrapper.start();
}
});
try {
Expand Down
16 changes: 4 additions & 12 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,18 @@ private List<WorkspaceFolder> getRelevantWorkspaceFolders() {
/**
* Starts a language server and triggers initialization. If language server is
* started and active, does nothing. If language server is inactive, restart it.
*
* @throws IOException
*/
public synchronized void start() throws IOException {
public synchronized void start() {
start(false);
}

/**
* Restarts a language server. If language server is not started, calling this
* method is the same as calling {@link #start()}.
*
* @throws IOException
* @since 0.18
*/
public synchronized void restart() throws IOException {
public synchronized void restart() {
start(true);
}

Expand All @@ -268,9 +265,8 @@ public synchronized void restart() throws IOException {
*
* @param forceRestart
* whether to restart the language server, even it is not inactive.
* @throws IOException
*/
private synchronized void start(boolean forceRestart) throws IOException {
private synchronized void start(boolean forceRestart) {
final var filesToReconnect = new HashMap<URI, IDocument>();
if (this.languageServer != null) {
if (isActive() && !forceRestart) {
Expand Down Expand Up @@ -785,11 +781,7 @@ protected LanguageServer getServer() {
*/
@NonNull
protected CompletableFuture<LanguageServer> getInitializedServer() {
try {
start();
} catch (IOException ex) {
LanguageServerPlugin.logError(ex);
}
start();

final CompletableFuture<Void> currentInitializeFuture = initializeFuture;
if (currentInitializeFuture != null && !currentInitializeFuture.isDone()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,16 @@ protected static Collection<LanguageServerWrapper> getLSWrappers(@NonNull final
* @param project
* @param serverDefinition
* @return a new or existing {@link LanguageServerWrapper} for the given definition.
* @throws IOException
*/
@NonNull
public static LanguageServerWrapper getLSWrapper(@Nullable IProject project,
@NonNull LanguageServerDefinition serverDefinition) throws IOException {
@NonNull LanguageServerDefinition serverDefinition) {
return getLSWrapper(project, serverDefinition, null);
}

@NonNull
private static LanguageServerWrapper getLSWrapper(@Nullable IProject project,
@NonNull LanguageServerDefinition serverDefinition, @Nullable IPath initialPath) throws IOException {
@NonNull LanguageServerDefinition serverDefinition, @Nullable IPath initialPath) {

final Predicate<LanguageServerWrapper> serverSelector = wrapper -> wrapper.canOperate(project)
&& wrapper.serverDefinition.equals(serverDefinition);
Expand All @@ -384,7 +383,7 @@ private static LanguageServerWrapper getLSWrapper(@Nullable IProject project,
}
}

public static @NonNull LanguageServerWrapper startLanguageServer(@NonNull LanguageServerDefinition serverDefinition) throws IOException {
public static @NonNull LanguageServerWrapper startLanguageServer(@NonNull LanguageServerDefinition serverDefinition) {
synchronized (startedServers) {
LanguageServerWrapper wrapper = startedServers.stream().filter(w -> w.serverDefinition == serverDefinition).findFirst().orElseGet(() -> {
LanguageServerWrapper w = new LanguageServerWrapper(serverDefinition, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*******************************************************************************/
package org.eclipse.lsp4e.operations.codeactions;

import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -108,7 +107,7 @@ public void run(IMarker marker) {
}
}
}
} catch (ExecutionException | IOException | TimeoutException | InterruptedException ex) {
} catch (ExecutionException | TimeoutException | InterruptedException ex) {
LanguageServerPlugin.logError(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
*******************************************************************************/
package org.eclipse.lsp4e.operations.codeactions;

import java.io.IOException;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.LanguageServerWrapper;
import org.eclipse.lsp4e.LanguageServersRegistry;
import org.eclipse.lsp4e.LanguageServersRegistry.LanguageServerDefinition;
Expand Down Expand Up @@ -59,19 +56,15 @@ public void run(IMarker marker) {
return;
}

try {
LanguageServerWrapper wrapper = LanguageServiceAccessor.getLSWrapper(resource.getProject(), definition);
if (wrapper != null) {
ExecuteCommandOptions provider = wrapper.getServerCapabilities().getExecuteCommandProvider();
if (provider != null && provider.getCommands().contains(command.getCommand())) {
wrapper.execute(ls -> ls.getWorkspaceService()
.executeCommand(new ExecuteCommandParams(command.getCommand(), command.getArguments())));
} else {
CommandExecutor.executeCommandClientSide(command, resource);
}
LanguageServerWrapper wrapper = LanguageServiceAccessor.getLSWrapper(resource.getProject(), definition);
if (wrapper != null) {
ExecuteCommandOptions provider = wrapper.getServerCapabilities().getExecuteCommandProvider();
if (provider != null && provider.getCommands().contains(command.getCommand())) {
wrapper.execute(ls -> ls.getWorkspaceService()
.executeCommand(new ExecuteCommandParams(command.getCommand(), command.getArguments())));
} else {
CommandExecutor.executeCommandClientSide(command, resource);
}
} catch (IOException ex) {
LanguageServerPlugin.logError(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void accept(PublishDiagnosticsParams diagnostics) {
.map(ISourceViewer.class::cast)
.forEach(sourceViewer -> updateEditorAnnotations(sourceViewer, diagnostics));
}
} catch (CoreException ex) {
} catch (Exception ex) {
LanguageServerPlugin.logError(ex);
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ private void updateEditorAnnotations(@NonNull ISourceViewer sourceViewer, Publis
}
}

private WorkspaceJob updateMarkers(PublishDiagnosticsParams diagnostics, IResource resource) throws CoreException {
private WorkspaceJob updateMarkers(PublishDiagnosticsParams diagnostics, IResource resource) {
WorkspaceJob job = new WorkspaceJob("Update markers from diagnostics") { //$NON-NLS-1$
@Override
public boolean belongsTo(Object family) {
Expand Down Expand Up @@ -288,7 +288,6 @@ private IMarker getExistingMarkerFor(IDocument document, Diagnostic diagnostic,
attributes.put(IMarker.CHAR_END, end);
}


markerAttributeComputer
.ifPresent(c -> c.addMarkerAttributesForDiagnostic(diagnostic, document, resource, attributes));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
Expand All @@ -42,7 +41,7 @@ protected void execute(ExecutionEvent event, ITextEditor textEditor) {
try {
final var query = new LSSearchQuery(textSelection.getOffset(), document);
HandlerUtil.getActiveShell(event).getDisplay().asyncExec(() -> NewSearchUI.runQueryInBackground(query));
} catch (BadLocationException e) {
} catch (Exception e) {
LanguageServerPlugin.logError(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public class LSSearchQuery extends FileSearchQuery {
* @param offset
* @param document
*/
public LSSearchQuery(int offset, @NonNull IDocument document)
throws BadLocationException {
public LSSearchQuery(int offset, @NonNull IDocument document) {
super("", false, false, true, true, null); //$NON-NLS-1$
this.document = document;
this.offset = offset;
Expand Down

0 comments on commit a27b7a9

Please sign in to comment.