diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/format/LSPFormatter.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/format/LSPFormatter.java index fc7bf21b4..9614a1360 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/format/LSPFormatter.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/format/LSPFormatter.java @@ -56,13 +56,14 @@ public CompletableFuture> requestFormatting(IDocument d // range formatting, falling back to a full format if unavailable long modificationStamp = DocumentUtil.getDocumentModificationStamp(document); return executor.computeFirst((w, ls) -> w.getServerCapabilitiesAsync().thenCompose(capabilities -> { - if (textSelection.getLength() == 0 && isDocumentRangeFormattingSupported(capabilities) - && !(isDocumentFormattingSupported(capabilities))) { + if (textSelection.getLength() != 0 && isDocumentRangeFormattingSupported(capabilities)) { return ls.getTextDocumentService().rangeFormatting(rangeParams) .thenApply(edits -> new VersionedEdits(modificationStamp, edits, document)); - } else { + } else if (isDocumentFormattingSupported(capabilities)) { return ls.getTextDocumentService().formatting(params) .thenApply(edits -> new VersionedEdits(modificationStamp, edits, document)); + } else { + return null; } })); }