use of org.eclipse.lsp4j.ServerCapabilities in project xtext-core by eclipse.
the class LanguageServerImpl method createServerCapabilities.
/**
* Configure the server capabilities for this instance.
*
* @param params
* the initialization parametrs
* @return the server capabilities
* @since 2.20
*/
protected ServerCapabilities createServerCapabilities(InitializeParams params) {
ServerCapabilities serverCapabilities = new ServerCapabilities();
serverCapabilities.setHoverProvider(true);
serverCapabilities.setDefinitionProvider(true);
serverCapabilities.setReferencesProvider(true);
serverCapabilities.setDocumentSymbolProvider(true);
serverCapabilities.setWorkspaceSymbolProvider(true);
Set<? extends IResourceServiceProvider> allLanguages = getAllLanguages();
if (allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(ICodeLensService.class) != null)) {
CodeLensOptions codeLensOptions = new CodeLensOptions();
codeLensOptions.setResolveProvider(allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(ICodeLensResolver.class) != null));
serverCapabilities.setCodeLensProvider(codeLensOptions);
}
serverCapabilities.setCodeActionProvider(allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(ICodeActionService2.class) != null));
serverCapabilities.setSignatureHelpProvider(new SignatureHelpOptions(ImmutableList.of("(", ",")));
serverCapabilities.setTextDocumentSync(TextDocumentSyncKind.Incremental);
CompletionOptions completionOptions = new CompletionOptions();
completionOptions.setResolveProvider(false);
completionOptions.setTriggerCharacters(ImmutableList.of("."));
serverCapabilities.setCompletionProvider(completionOptions);
serverCapabilities.setDocumentFormattingProvider(true);
serverCapabilities.setDocumentRangeFormattingProvider(true);
serverCapabilities.setDocumentHighlightProvider(true);
ClientCapabilities clientCapabilities = null;
if (params != null) {
clientCapabilities = params.getCapabilities();
}
TextDocumentClientCapabilities textDocument = null;
if (clientCapabilities != null) {
textDocument = clientCapabilities.getTextDocument();
}
RenameCapabilities rename = null;
FoldingRangeCapabilities folding = null;
if (textDocument != null) {
rename = textDocument.getRename();
folding = textDocument.getFoldingRange();
}
if (folding != null) {
serverCapabilities.setFoldingRangeProvider(allLanguages.stream().anyMatch(serviceProvider -> serviceProvider.get(FoldingRangeService.class) != null));
}
Boolean prepareSupport = null;
if (rename != null) {
prepareSupport = rename.getPrepareSupport();
}
boolean clientPrepareSupport = Objects.equal(Boolean.TRUE, prepareSupport);
if (clientPrepareSupport && allLanguages.stream().anyMatch(serviceProvider -> serviceProvider.get(IRenameService2.class) != null)) {
RenameOptions renameOptions = new RenameOptions();
renameOptions.setPrepareProvider(true);
serverCapabilities.setRenameProvider(Either.<Boolean, RenameOptions>forRight(renameOptions));
} else {
serverCapabilities.setRenameProvider(Either.forLeft(allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(IRenameService2.class) != null)));
}
WorkspaceClientCapabilities workspace = null;
if (clientCapabilities != null) {
workspace = clientCapabilities.getWorkspace();
}
ExecuteCommandCapabilities executeCommand = null;
if (workspace != null) {
executeCommand = workspace.getExecuteCommand();
if (workspace.getWorkspaceFolders() == Boolean.TRUE && workspaceManager.isSupportsWorkspaceFolders()) {
WorkspaceFoldersOptions workspaceFoldersOptions = new WorkspaceFoldersOptions();
workspaceFoldersOptions.setSupported(true);
workspaceFoldersOptions.setChangeNotifications(true);
serverCapabilities.setWorkspace(new WorkspaceServerCapabilities(workspaceFoldersOptions));
}
}
if (executeCommand != null) {
commandRegistry.initialize(allLanguages, clientCapabilities, client);
ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions();
executeCommandOptions.setCommands(commandRegistry.getCommands());
serverCapabilities.setExecuteCommandProvider(executeCommandOptions);
}
for (IResourceServiceProvider language : allLanguages) {
ICapabilitiesContributor capabilitiesContributor = language.get(ICapabilitiesContributor.class);
if (capabilitiesContributor != null) {
capabilitiesContributor.contribute(serverCapabilities, params);
}
}
return serverCapabilities;
}
use of org.eclipse.lsp4j.ServerCapabilities in project ballerina by ballerina-lang.
the class BallerinaLanguageServer method initialize.
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
final InitializeResult res = new InitializeResult(new ServerCapabilities());
final SignatureHelpOptions signatureHelpOptions = new SignatureHelpOptions(Arrays.asList("(", ","));
final List<String> commandList = new ArrayList<>(Arrays.asList(CommandConstants.CMD_IMPORT_PACKAGE, CommandConstants.CMD_ADD_DOCUMENTATION, CommandConstants.CMD_ADD_ALL_DOC));
final ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions(commandList);
final CompletionOptions completionOptions = new CompletionOptions();
completionOptions.setTriggerCharacters(Arrays.asList(":", ".", ">"));
res.getCapabilities().setCompletionProvider(completionOptions);
res.getCapabilities().setTextDocumentSync(TextDocumentSyncKind.Full);
res.getCapabilities().setSignatureHelpProvider(signatureHelpOptions);
res.getCapabilities().setHoverProvider(true);
res.getCapabilities().setDocumentSymbolProvider(true);
res.getCapabilities().setDefinitionProvider(true);
res.getCapabilities().setReferencesProvider(true);
res.getCapabilities().setCodeActionProvider(true);
res.getCapabilities().setExecuteCommandProvider(executeCommandOptions);
res.getCapabilities().setDocumentFormattingProvider(true);
res.getCapabilities().setRenameProvider(true);
return CompletableFuture.supplyAsync(() -> res);
}
use of org.eclipse.lsp4j.ServerCapabilities in project sts4 by spring-projects.
the class SimpleLanguageServer method initialize.
@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
Log.debug("Initializing: " + params);
// multi-root workspace handling
List<WorkspaceFolder> workspaceFolders = getWorkspaceFolders(params);
if (!workspaceFolders.isEmpty()) {
this.getWorkspaceService().setWorkspaceFolders(workspaceFolders);
} else {
String rootUri = params.getRootUri();
if (rootUri == null) {
Log.debug("workspaceRoot NOT SET");
} else {
List<WorkspaceFolder> singleRootFolder = new ArrayList<>();
String name;
try {
name = Paths.get(new URI(rootUri).getPath()).getFileName().toString();
} catch (Exception e) {
name = "";
}
WorkspaceFolder folder = new WorkspaceFolder();
folder.setName(name);
folder.setUri(rootUri);
singleRootFolder.add(folder);
this.getWorkspaceService().setWorkspaceFolders(singleRootFolder);
}
}
this.hasCompletionSnippetSupport = safeGet(false, () -> params.getCapabilities().getTextDocument().getCompletion().getCompletionItem().getSnippetSupport());
this.hasExecuteCommandSupport = safeGet(false, () -> params.getCapabilities().getWorkspace().getExecuteCommand() != null);
this.hasFileWatcherRegistrationSupport = safeGet(false, () -> params.getCapabilities().getWorkspace().getDidChangeWatchedFiles().getDynamicRegistration());
Log.debug("workspaceRoots = " + getWorkspaceService().getWorkspaceRoots());
Log.debug("hasCompletionSnippetSupport = " + hasCompletionSnippetSupport);
Log.debug("hasExecuteCommandSupport = " + hasExecuteCommandSupport);
InitializeResult result = new InitializeResult();
if (hasExecuteCommandSupport) {
getWorkspaceService().onExecuteCommand(this::executeCommand);
}
ServerCapabilities cap = getServerCapabilities();
result.setCapabilities(cap);
Consumer<InitializeParams> ih = this.initializeHandler;
if (ih != null) {
ih.accept(params);
}
return CompletableFuture.completedFuture(result);
}
Aggregations