From f4a8c6cc5162391a4385d4401def972f3a7f3167 Mon Sep 17 00:00:00 2001 From: Siddharth Srinivasan Date: Tue, 29 Oct 2024 13:51:46 +0530 Subject: [PATCH] [JVSC-249] Fix code-folding for LSP clients that support line-folding only Backported apache/netbeans#7921 to fix unit tests breakage due to uninitialised `NbCodeClientCapabilities.getClientCapabilities()` by adding a null check in the initialisation of `lineFoldingOnly` in `TextDocumentServiceImpl.foldingRange()`. Signed-off-by: Siddharth Srinivasan --- build.xml | 1 + patches/7921.diff | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 patches/7921.diff diff --git a/build.xml b/build.xml index fc107a2..ab6b363 100644 --- a/build.xml +++ b/build.xml @@ -57,6 +57,7 @@ patches/7733.diff patches/7750.diff patches/7910.diff + patches/7921.diff patches/mvn-sh.diff patches/generate-dependencies.diff patches/rename-debugger.diff diff --git a/patches/7921.diff b/patches/7921.diff new file mode 100644 index 0000000..75f831d --- /dev/null +++ b/patches/7921.diff @@ -0,0 +1,34 @@ +diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java +index 7a5a5f40e4f9..85c223130e32 100644 +--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java ++++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java +@@ -128,6 +128,7 @@ + import org.eclipse.lsp4j.DocumentSymbol; + import org.eclipse.lsp4j.DocumentSymbolParams; + import org.eclipse.lsp4j.FoldingRange; ++import org.eclipse.lsp4j.FoldingRangeCapabilities; + import org.eclipse.lsp4j.FoldingRangeKind; + import org.eclipse.lsp4j.FoldingRangeRequestParams; + import org.eclipse.lsp4j.Hover; +@@ -160,6 +161,7 @@ + import org.eclipse.lsp4j.SignatureHelpParams; + import org.eclipse.lsp4j.SignatureInformation; + import org.eclipse.lsp4j.SymbolInformation; ++import org.eclipse.lsp4j.TextDocumentClientCapabilities; + import org.eclipse.lsp4j.TextDocumentContentChangeEvent; + import org.eclipse.lsp4j.TextDocumentEdit; + import org.eclipse.lsp4j.TextEdit; +@@ -1638,7 +1640,12 @@ public CompletableFuture> foldingRange(FoldingRangeRequestPar + if (source == null) { + return CompletableFuture.completedFuture(Collections.emptyList()); + } +- final boolean lineFoldingOnly = client.getNbCodeCapabilities().getClientCapabilities().getTextDocument().getFoldingRange().getLineFoldingOnly() == Boolean.TRUE; ++ ClientCapabilities clientCapabilities = client.getNbCodeCapabilities() ++ .getClientCapabilities(); ++ TextDocumentClientCapabilities textDocumentCapabilities = clientCapabilities != null ? clientCapabilities.getTextDocument() : null; ++ FoldingRangeCapabilities foldingRangeCapabilities = textDocumentCapabilities != null ? textDocumentCapabilities.getFoldingRange() : null; ++ Boolean lineFoldingOnlyCapability = foldingRangeCapabilities != null ? foldingRangeCapabilities.getLineFoldingOnly() : null; ++ final boolean lineFoldingOnly = lineFoldingOnlyCapability == Boolean.TRUE; + CompletableFuture> result = new CompletableFuture<>(); + try { + source.runUserActionTask(cc -> {