Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private void formatDocument() {
return languageServerWrapper.getServerCapabilitiesAsync().thenCompose(capabilities -> {
FormattingOptions formatOptions = LSPFormatter.getFormatOptions();
final var docId = new TextDocumentIdentifier(fileUri.toString());
if (LSPFormatter.isDocumentRangeFormattingSupported(capabilities)
if (capabilities != null && LSPFormatter.isDocumentRangeFormattingSupported(capabilities)
&& !(LSPFormatter.isDocumentFormattingSupported(capabilities) && textSelection.getLength() == 0)) {
try {
DocumentRangeFormattingParams rangeParams = LSPFormatter.getRangeFormattingParams(document,
Expand Down
38 changes: 16 additions & 22 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1079,17 +1079,14 @@ public void sendNotification(Consumer<LanguageServer> fn) {
return res;
}

public CompletableFuture<InitializeResult> getInitializeResultAsync() {
return getInitializedServer().thenCompose(ls -> {
final var initializeResult = this.initializeResult;
if (initializeResult == null) {
// This can happen if the server shuts down immediately after initialization,
// but before this callback was invoked.
return CompletableFuture.failedFuture(
new IllegalStateException("initializeResult unexpectedly null after initialization")); //$NON-NLS-1$
Copy link
Copy Markdown
Contributor

@FlorianKroiss FlorianKroiss Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming these are the errors you wanted to get rid of?

}
return CompletableFuture.completedFuture(initializeResult);
});
/**
* @return a {@link CompletableFuture} that provides the {@link InitializeResult}.
* <p>
* The {@link InitializeResult} will be {@code null} if the server shuts down
* immediately after initialization or if it fails to start.
*/
public CompletableFuture<@Nullable InitializeResult> getInitializeResultAsync() {
return getInitializedServer().thenCompose(ls -> CompletableFuture.completedFuture(this.initializeResult));
}

/**
Expand All @@ -1116,17 +1113,14 @@ public CompletableFuture<InitializeResult> getInitializeResultAsync() {
return this.serverCapabilities;
}

public CompletableFuture<ServerCapabilities> getServerCapabilitiesAsync() {
return getInitializedServer().thenCompose(ls -> {
final var serverCapabilities = this.serverCapabilities;
if (serverCapabilities == null) {
// This can happen if the server shuts down immediately after initialization,
// but before this callback was invoked.
return CompletableFuture.failedFuture(
new IllegalStateException("serverCapabilities unexpectedly null after initialization")); //$NON-NLS-1$
}
return CompletableFuture.completedFuture(serverCapabilities);
});
/**
* @return a {@link CompletableFuture} that provides the {@link ServerCapabilities}.
* <p>
* The {@link ServerCapabilities} will be {@code null} if the server shuts down
* immediately after initialization or if it fails to start.
*/
public CompletableFuture<@Nullable ServerCapabilities> getServerCapabilitiesAsync() {
return getInitializedServer().thenCompose(ls -> CompletableFuture.completedFuture(this.serverCapabilities));
}

public CompletableFuture<@Nullable ServerInfo> getServerInfoAsync() {
Expand Down
6 changes: 3 additions & 3 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServers.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ public E withFilter(final Predicate<ServerCapabilities> filter) {
* @param serverCapabilities
*/
@SuppressWarnings("unchecked")
public E withCapability(final Function<ServerCapabilities, Either<Boolean, ?>> serverCapabilities) {
public E withCapability(final @Nullable Function<ServerCapabilities, Either<Boolean, ?>> serverCapabilities) {
Assert.isLegal(this.filter == NO_FILTER);
this.filter = f -> LSPEclipseUtils.hasCapability(serverCapabilities.apply(f));
this.filter = f -> serverCapabilities != null && LSPEclipseUtils.hasCapability(serverCapabilities.apply(f));
return (E) this;
}

Expand Down Expand Up @@ -280,7 +280,7 @@ public IDocument getDocument() {
*/
private CompletableFuture<@Nullable LanguageServerWrapper> filter(LanguageServerWrapper wrapper) {
return wrapper.getServerCapabilitiesAsync() //
.thenApply(sc -> getFilter().test(sc) ? wrapper : null);
.thenApply(sc -> sc != null && getFilter().test(sc) ? wrapper : null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private LSPDocumentInfo(URI fileUri, IDocument document, LanguageServerWrapper w
this.wrapper = wrapper;
}

@Deprecated
public IDocument getDocument() {
return this.document;
}
Expand All @@ -103,22 +104,27 @@ public IDocument getDocument() {
*
* @return the file URI
*/
@Deprecated
public URI getFileUri() {
return this.fileUri;
}

@Deprecated
public LanguageServerWrapper getLanguageServerWrapper() {
return wrapper;
}

@Deprecated
public int getVersion() {
return wrapper.getTextDocumentVersion(fileUri);
}

@Deprecated
public @Nullable ServerCapabilities getCapabilites() {
return this.wrapper.getServerCapabilities();
}

@Deprecated
public boolean isActive() {
return this.wrapper.isActive();
}
Expand Down Expand Up @@ -220,7 +226,7 @@ private static CompletableFuture<Boolean> capabilitiesComplyAsync(final Language
final @Nullable Predicate<ServerCapabilities> capabilitiesPredicate) {
return capabilitiesPredicate == null //
? CompletableFuture.completedFuture(true) //
: wrapper.getServerCapabilitiesAsync().thenApply(capabilitiesPredicate::test);
: wrapper.getServerCapabilitiesAsync().thenApply(sC -> sC != null && capabilitiesPredicate.test(sC));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public LSPCodeMining(CodeLens codeLens, IDocument document, LanguageServerWrappe
@Override
protected CompletableFuture<@Nullable Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
return languageServerWrapper.getServerCapabilitiesAsync().thenCompose(capabilities -> {
if (capabilities == null) {
return CompletableFuture.completedFuture(null);
}
final Boolean resolveProvider = capabilities.getCodeLensProvider().getResolveProvider();
if (resolveProvider == null || !resolveProvider) {
return CompletableFuture.completedFuture(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public CompletableFuture<Optional<VersionedEdits>> requestFormatting(IDocument d
// can fall through to the next server (e.g. Vue LS after TS LS on .vue files).
long modificationStamp = DocumentUtil.getDocumentModificationStamp(document);
return executor.computeFirst((w, ls) -> w.getServerCapabilitiesAsync().thenCompose(capabilities -> {
if (capabilities == null) {
return CompletableFuture.completedFuture(null);
}

if (isDocumentRangeFormattingSupported(capabilities) && (textSelection.getLength() > 0 || !isDocumentFormattingSupported(capabilities))) {
return (CompletableFuture<@Nullable List<? extends TextEdit>>) ls.getTextDocumentService()
.rangeFormatting(rangeParams);
Expand Down
Loading