Skip to content

Commit

Permalink
refactor: move SupportedFeatures into ClientCapabilitiesFactory
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr authored and fbricon committed May 14, 2024
1 parent 2de1906 commit 20883ee
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -325,16 +325,8 @@ public synchronized void start() throws LanguageServerException {
}

private CompletableFuture<InitializeResult> 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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* Contributors:
* Ahmed Hussain (Cocotec Ltd) - initial implementation
*
* Red Hat Inc. - rename SupportedFeatures to ClientCapabilitiesFactory
*******************************************************************************/
package com.redhat.devtools.lsp4ij.internal;

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
/**
Expand All @@ -211,6 +220,7 @@ public static WindowClientCapabilities getWindowClientCapabilities() {
windowClientCapabilities.setWorkDoneProgress(true);
windowClientCapabilities.setShowMessage(new WindowShowMessageRequestCapabilities());
return windowClientCapabilities;

}

}
}

0 comments on commit 20883ee

Please sign in to comment.