File tree Expand file tree Collapse file tree
org.eclipse.lsp4e/src/org/eclipse/lsp4e Expand file tree Collapse file tree Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments