diff --git a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java index 64f6f7be7..384e1ce1d 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java @@ -27,7 +27,7 @@ import com.intellij.util.messages.MessageBusConnection; import com.redhat.devtools.lsp4ij.client.LanguageClientImpl; import com.redhat.devtools.lsp4ij.features.files.operations.FileOperationsManager; -import com.redhat.devtools.lsp4ij.internal.SupportedFeatures; +import com.redhat.devtools.lsp4ij.internal.ClientCapabilitiesFactory; import com.redhat.devtools.lsp4ij.lifecycle.LanguageServerLifecycleManager; import com.redhat.devtools.lsp4ij.lifecycle.NullLanguageServerLifecycleManager; import com.redhat.devtools.lsp4ij.server.*; @@ -325,16 +325,8 @@ public synchronized void start() throws LanguageServerException { } private CompletableFuture initServer(final URI rootURI) { - - final var workspaceClientCapabilities = SupportedFeatures.getWorkspaceClientCapabilities(); - final var textDocumentClientCapabilities = SupportedFeatures.getTextDocumentClientCapabilities(); - - WindowClientCapabilities windowClientCapabilities = SupportedFeatures.getWindowClientCapabilities(); - initParams.setCapabilities(new ClientCapabilities( - workspaceClientCapabilities, - textDocumentClientCapabilities, - windowClientCapabilities, - lspStreamProvider.getExperimentalFeaturesPOJO())); + initParams.setCapabilities(ClientCapabilitiesFactory + .create(lspStreamProvider.getExperimentalFeaturesPOJO())); initParams.setClientInfo(getClientInfo()); initParams.setTrace(this.lspStreamProvider.getTrace(rootURI)); diff --git a/src/main/java/com/redhat/devtools/lsp4ij/internal/SupportedFeatures.java b/src/main/java/com/redhat/devtools/lsp4ij/internal/ClientCapabilitiesFactory.java similarity index 92% rename from src/main/java/com/redhat/devtools/lsp4ij/internal/SupportedFeatures.java rename to src/main/java/com/redhat/devtools/lsp4ij/internal/ClientCapabilitiesFactory.java index 79e1e3d18..e7ebfae30 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/internal/SupportedFeatures.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/internal/ClientCapabilitiesFactory.java @@ -8,7 +8,7 @@ * * Contributors: * Ahmed Hussain (Cocotec Ltd) - initial implementation - * + * Red Hat Inc. - rename SupportedFeatures to ClientCapabilitiesFactory *******************************************************************************/ package com.redhat.devtools.lsp4ij.internal; @@ -18,11 +18,71 @@ import java.util.List; /** - * LSP client capabilities. + * Factory of LSP client capabilities. */ -public class SupportedFeatures { +public class ClientCapabilitiesFactory { + + public static ClientCapabilities create(Object experimental) { + return new ClientCapabilities( + getWorkspaceClientCapabilities(), + getTextDocumentClientCapabilities(), + getWindowClientCapabilities(), + experimental); + } + + private static @NotNull WorkspaceClientCapabilities getWorkspaceClientCapabilities() { + final var workspaceClientCapabilities = new WorkspaceClientCapabilities(); + + // Apply edit support + // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_applyEdit + workspaceClientCapabilities.setApplyEdit(Boolean.TRUE); + + // TODO + // workspaceClientCapabilities.setConfiguration(Boolean.TRUE); + + // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#executeCommandClientCapabilities + workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities(Boolean.TRUE)); + // TODO + // workspaceClientCapabilities.setSymbol(new SymbolCapabilities(Boolean.TRUE)); + workspaceClientCapabilities.setWorkspaceFolders(Boolean.TRUE); + + // Workspace edit support + // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceEditClientCapabilities + WorkspaceEditCapabilities editCapabilities = new WorkspaceEditCapabilities(); + editCapabilities.setDocumentChanges(Boolean.TRUE); + editCapabilities.setResourceOperations(List.of( + ResourceOperationKind.Create, + ResourceOperationKind.Delete, + ResourceOperationKind.Rename)); + // editCapabilities.setFailureHandling(FailureHandlingKind.Undo); + workspaceClientCapabilities.setWorkspaceEdit(editCapabilities); + + // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#didChangeWatchedFilesClientCapabilities + workspaceClientCapabilities.setDidChangeWatchedFiles(new DidChangeWatchedFilesCapabilities(Boolean.TRUE)); + + // File operations support + FileOperationsWorkspaceCapabilities fileOperationsWorkspaceCapabilities = new FileOperationsWorkspaceCapabilities(); + fileOperationsWorkspaceCapabilities.setDynamicRegistration(Boolean.TRUE); + //fileOperationsWorkspaceCapabilities.setWillCreate(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willCreateFiles + //fileOperationsWorkspaceCapabilities.setDidCreate(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didCreateFiles + //fileOperationsWorkspaceCapabilities.setWillDelete(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willDeleteFiles + //fileOperationsWorkspaceCapabilities.setDidDelete(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didDeleteFiles + fileOperationsWorkspaceCapabilities.setWillRename(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willRenameFiles + fileOperationsWorkspaceCapabilities.setDidRename(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didRenameFiles + workspaceClientCapabilities.setFileOperations(fileOperationsWorkspaceCapabilities); + + // DidChangeConfiguration support + // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#didChangeConfigurationClientCapabilities + workspaceClientCapabilities.setDidChangeConfiguration(new DidChangeConfigurationCapabilities(Boolean.TRUE)); + + // Refresh support for InlayHint + workspaceClientCapabilities.setInlayHint(new InlayHintWorkspaceCapabilities(Boolean.TRUE)); + + return workspaceClientCapabilities; + } - public static @NotNull TextDocumentClientCapabilities getTextDocumentClientCapabilities() { + + private static @NotNull TextDocumentClientCapabilities getTextDocumentClientCapabilities() { final var textDocumentClientCapabilities = new TextDocumentClientCapabilities(); // Publish diagnostics capabilities @@ -60,9 +120,9 @@ public class SupportedFeatures { completionItemCapabilities.setResolveSupport(new CompletionItemResolveSupportCapabilities( List.of( - "documentation" , + "documentation", "detail", - "additionalTextEdits" ))); + "additionalTextEdits"))); CompletionCapabilities completionCapabilities = new CompletionCapabilities(completionItemCapabilities); completionCapabilities.setCompletionList(new CompletionListCapabilities(List.of("editRange"))); textDocumentClientCapabilities.setCompletion(completionCapabilities); @@ -150,58 +210,7 @@ public class SupportedFeatures { return textDocumentClientCapabilities; } - public static @NotNull WorkspaceClientCapabilities getWorkspaceClientCapabilities() { - final var workspaceClientCapabilities = new WorkspaceClientCapabilities(); - - // Apply edit support - // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_applyEdit - workspaceClientCapabilities.setApplyEdit(Boolean.TRUE); - - // TODO - // workspaceClientCapabilities.setConfiguration(Boolean.TRUE); - - // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#executeCommandClientCapabilities - workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities(Boolean.TRUE)); - // TODO - // workspaceClientCapabilities.setSymbol(new SymbolCapabilities(Boolean.TRUE)); - workspaceClientCapabilities.setWorkspaceFolders(Boolean.TRUE); - - // Workspace edit support - // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceEditClientCapabilities - WorkspaceEditCapabilities editCapabilities = new WorkspaceEditCapabilities(); - editCapabilities.setDocumentChanges(Boolean.TRUE); - editCapabilities.setResourceOperations(List.of( - ResourceOperationKind.Create, - ResourceOperationKind.Delete, - ResourceOperationKind.Rename)); - // editCapabilities.setFailureHandling(FailureHandlingKind.Undo); - workspaceClientCapabilities.setWorkspaceEdit(editCapabilities); - - // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#didChangeWatchedFilesClientCapabilities - workspaceClientCapabilities.setDidChangeWatchedFiles(new DidChangeWatchedFilesCapabilities(Boolean.TRUE)); - - // File operations support - FileOperationsWorkspaceCapabilities fileOperationsWorkspaceCapabilities = new FileOperationsWorkspaceCapabilities(); - fileOperationsWorkspaceCapabilities.setDynamicRegistration(Boolean.TRUE); - //fileOperationsWorkspaceCapabilities.setWillCreate(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willCreateFiles - //fileOperationsWorkspaceCapabilities.setDidCreate(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didCreateFiles - //fileOperationsWorkspaceCapabilities.setWillDelete(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willDeleteFiles - //fileOperationsWorkspaceCapabilities.setDidDelete(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didDeleteFiles - fileOperationsWorkspaceCapabilities.setWillRename(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willRenameFiles - fileOperationsWorkspaceCapabilities.setDidRename(Boolean.TRUE); // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didRenameFiles - workspaceClientCapabilities.setFileOperations(fileOperationsWorkspaceCapabilities); - - // DidChangeConfiguration support - // See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#didChangeConfigurationClientCapabilities - workspaceClientCapabilities.setDidChangeConfiguration(new DidChangeConfigurationCapabilities(Boolean.TRUE)); - - // Refresh support for InlayHint - workspaceClientCapabilities.setInlayHint(new InlayHintWorkspaceCapabilities(Boolean.TRUE)); - - return workspaceClientCapabilities; - } - - public static WindowClientCapabilities getWindowClientCapabilities() { + private static WindowClientCapabilities getWindowClientCapabilities() { final var windowClientCapabilities = new WindowClientCapabilities(); windowClientCapabilities.setShowDocument(new ShowDocumentCapabilities(true)); /** @@ -211,6 +220,7 @@ public static WindowClientCapabilities getWindowClientCapabilities() { windowClientCapabilities.setWorkDoneProgress(true); windowClientCapabilities.setShowMessage(new WindowShowMessageRequestCapabilities()); return windowClientCapabilities; + } -} \ No newline at end of file +}