Skip to content

Commit b591ac1

Browse files
committed
fix: exception in Outline view when LS fails to start (#1239)
Ensure getServerCapabilitiesAsync() fails gracefully when serverCapabilities is unexpectedly null.
1 parent b1e5d7a commit b591ac1

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerWrapper.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ synchronized void close() {
196196
private final AtomicReference<@Nullable IProgressMonitor> initializeFutureMonitorRef = new AtomicReference<>();
197197
private final int initializeFutureNumberOfStages = 7;
198198
private @Nullable LanguageClientImpl languageClient;
199-
private @Nullable ServerCapabilities serverCapabilities;
199+
private volatile @Nullable ServerCapabilities serverCapabilities;
200200
private final Timer timer = new Timer("Stop Language Server Task Processor"); //$NON-NLS-1$
201201
private @Nullable TimerTask stopTimerTask;
202202

@@ -935,7 +935,16 @@ public void sendNotification(Consumer<LanguageServer> fn) {
935935
}
936936

937937
public CompletableFuture<ServerCapabilities> getServerCapabilitiesAsync() {
938-
return getInitializedServer().thenApply(ls -> castNonNull(this.serverCapabilities));
938+
return getInitializedServer().thenCompose(ls -> {
939+
final var serverCapabilities = this.serverCapabilities;
940+
if (serverCapabilities == null) {
941+
// This can happen if the server shuts down immediately after initialization,
942+
// but before this callback was invoked.
943+
return CompletableFuture
944+
.failedFuture(new IllegalStateException("serverCapabilities unexpectedly null after initialization")); //$NON-NLS-1$
945+
}
946+
return CompletableFuture.completedFuture(serverCapabilities);
947+
});
939948
}
940949

941950
/**

0 commit comments

Comments
 (0)