use of org.eclipse.lsp4j.CodeActionOptions in project n4js by eclipse.
the class XLanguageServerImpl method createServerCapabilities.
/**
* Configure the server capabilities for this instance.
*
* @param params
* the initialization parameters
* @return the server capabilities
*/
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);
}
boolean supportsCodeActions = allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(ICodeActionService2.class) != null);
if (supportsCodeActions) {
Optional<List<String>> supportedKinds = getSupportedCodeActionKinds();
if (supportedKinds.isPresent()) {
serverCapabilities.setCodeActionProvider(new CodeActionOptions(supportedKinds.get()));
} else {
serverCapabilities.setCodeActionProvider(true);
}
} else {
serverCapabilities.setCodeActionProvider(false);
}
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;
if (textDocument != null) {
rename = textDocument.getRename();
}
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 (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.CodeActionOptions in project OberonEmulator by schierlm.
the class Server method fillCapabilities.
protected void fillCapabilities(ServerCapabilities cap, InitializeParams params) {
cap.setTextDocumentSync(TextDocumentSyncKind.Full);
cap.setSemanticTokensProvider(new SemanticTokensWithRegistrationOptions(new SemanticTokensLegend(Bridge.TOKEN_TYPES, Bridge.TOKEN_MODIFIERS), new SemanticTokensServerFull(false), false));
cap.setDocumentSymbolProvider(new DocumentSymbolOptions("Oberon"));
cap.setCompletionProvider(new CompletionOptions(false, null));
cap.setDefinitionProvider(true);
cap.setDocumentHighlightProvider(true);
cap.setReferencesProvider(true);
cap.setLinkedEditingRangeProvider(true);
cap.setSignatureHelpProvider(new SignatureHelpOptions(Arrays.asList("("), Arrays.asList(",", ")")));
cap.setFoldingRangeProvider(true);
cap.setHoverProvider(true);
cap.setRenameProvider(new RenameOptions(true));
cap.setDocumentFormattingProvider(true);
cap.setCallHierarchyProvider(true);
CodeActionOptions cao = new CodeActionOptions(Arrays.asList(CodeActionKind.QuickFix));
cao.setResolveProvider(true);
cap.setCodeActionProvider(cao);
}
use of org.eclipse.lsp4j.CodeActionOptions in project lsp4e by eclipse.
the class LanguageServerWrapper method registerCapability.
void registerCapability(RegistrationParams params) {
params.getRegistrations().forEach(reg -> {
if ("workspace/didChangeWorkspaceFolders".equals(reg.getMethod())) {
// $NON-NLS-1$
Assert.isNotNull(serverCapabilities, // $NON-NLS-1$
"Dynamic capability registration failed! Server not yet initialized?");
if (initiallySupportsWorkspaceFolders) {
// Can treat this as a NOP since nothing can disable it dynamically if it was
// enabled on initialization.
} else if (supportsWorkspaceFolders(serverCapabilities)) {
LanguageServerPlugin.logWarning(// $NON-NLS-1$
"Dynamic registration of 'workspace/didChangeWorkspaceFolders' ignored. It was already enabled before", null);
} else {
addRegistration(reg, () -> setWorkspaceFoldersEnablement(false));
setWorkspaceFoldersEnablement(true);
}
} else if ("workspace/executeCommand".equals(reg.getMethod())) {
// $NON-NLS-1$
// TODO? retrieve the GSon used by LS
Gson gson = new Gson();
ExecuteCommandOptions executeCommandOptions = gson.fromJson((JsonObject) reg.getRegisterOptions(), ExecuteCommandOptions.class);
List<String> newCommands = executeCommandOptions.getCommands();
if (!newCommands.isEmpty()) {
addRegistration(reg, () -> unregisterCommands(newCommands));
registerCommands(newCommands);
}
} else if ("textDocument/formatting".equals(reg.getMethod())) {
// $NON-NLS-1$
Either<Boolean, DocumentFormattingOptions> documentFormattingProvider = serverCapabilities.getDocumentFormattingProvider();
if (documentFormattingProvider == null || documentFormattingProvider.isLeft()) {
serverCapabilities.setDocumentFormattingProvider(Boolean.TRUE);
addRegistration(reg, () -> serverCapabilities.setDocumentFormattingProvider(documentFormattingProvider));
} else {
serverCapabilities.setDocumentFormattingProvider(documentFormattingProvider.getRight());
addRegistration(reg, () -> serverCapabilities.setDocumentFormattingProvider(documentFormattingProvider));
}
} else if ("textDocument/rangeFormatting".equals(reg.getMethod())) {
// $NON-NLS-1$
Either<Boolean, DocumentRangeFormattingOptions> documentRangeFormattingProvider = serverCapabilities.getDocumentRangeFormattingProvider();
if (documentRangeFormattingProvider == null || documentRangeFormattingProvider.isLeft()) {
serverCapabilities.setDocumentRangeFormattingProvider(Boolean.TRUE);
addRegistration(reg, () -> serverCapabilities.setDocumentRangeFormattingProvider(documentRangeFormattingProvider));
} else {
serverCapabilities.setDocumentRangeFormattingProvider(documentRangeFormattingProvider.getRight());
addRegistration(reg, () -> serverCapabilities.setDocumentRangeFormattingProvider(documentRangeFormattingProvider));
}
} else if ("textDocument/codeAction".equals(reg.getMethod())) {
// $NON-NLS-1$
final Either<Boolean, CodeActionOptions> beforeRegistration = serverCapabilities.getCodeActionProvider();
serverCapabilities.setCodeActionProvider(Boolean.TRUE);
addRegistration(reg, () -> serverCapabilities.setCodeActionProvider(beforeRegistration));
}
});
}
use of org.eclipse.lsp4j.CodeActionOptions in project vscode-as3mxml by BowlerHatLLC.
the class ActionScriptLanguageServer method initialize.
/**
* Tells Visual Studio Code about the language server's capabilities.
*
* Optional initialization options:
*
* - supportsSimpleSnippets: The client offers partial support for snippets,
* such as $0
*/
@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
actionScriptServices.setClientCapabilities(params.getCapabilities());
actionScriptServices.setLanguageClient(languageClient);
// setting everything above must happen before adding workspace folders
List<WorkspaceFolder> folders = params.getWorkspaceFolders();
if (folders != null) {
for (WorkspaceFolder folder : params.getWorkspaceFolders()) {
actionScriptServices.addWorkspaceFolder(folder);
}
} else if (params.getRootUri() != null) {
// some clients don't support workspace folders, but if they pass in
// a root URI, we can treat it like a workspace folder
WorkspaceFolder folder = new WorkspaceFolder();
folder.setUri(params.getRootUri());
actionScriptServices.addWorkspaceFolder(folder);
}
boolean supportsSimpleSnippets = false;
if (params.getInitializationOptions() != null) {
JsonObject initializationOptions = (JsonObject) params.getInitializationOptions();
if (initializationOptions.has("supportsSimpleSnippets")) {
supportsSimpleSnippets = initializationOptions.get("supportsSimpleSnippets").getAsBoolean();
}
}
actionScriptServices.setClientSupportsSimpleSnippets(supportsSimpleSnippets);
InitializeResult result = new InitializeResult();
ServerCapabilities serverCapabilities = new ServerCapabilities();
serverCapabilities.setTextDocumentSync(TextDocumentSyncKind.Incremental);
serverCapabilities.setCodeActionProvider(new CodeActionOptions(Lists.newArrayList(CodeActionKind.QuickFix, CodeActionKind.Refactor, CodeActionKind.RefactorRewrite, CodeActionKind.SourceOrganizeImports)));
CompletionOptions completionOptions = new CompletionOptions();
completionOptions.setTriggerCharacters(Arrays.asList(".", ":", " ", "<"));
serverCapabilities.setCompletionProvider(completionOptions);
serverCapabilities.setDefinitionProvider(true);
serverCapabilities.setTypeDefinitionProvider(true);
serverCapabilities.setImplementationProvider(true);
serverCapabilities.setDocumentSymbolProvider(true);
serverCapabilities.setDocumentHighlightProvider(false);
serverCapabilities.setDocumentFormattingProvider(true);
serverCapabilities.setDocumentRangeFormattingProvider(false);
serverCapabilities.setHoverProvider(true);
serverCapabilities.setReferencesProvider(true);
serverCapabilities.setRenameProvider(true);
SignatureHelpOptions signatureHelpOptions = new SignatureHelpOptions();
signatureHelpOptions.setTriggerCharacters(Arrays.asList("(", ","));
serverCapabilities.setSignatureHelpProvider(signatureHelpOptions);
serverCapabilities.setWorkspaceSymbolProvider(true);
WorkspaceServerCapabilities workspaceCapabilities = new WorkspaceServerCapabilities();
WorkspaceFoldersOptions workspaceFoldersOptions = new WorkspaceFoldersOptions();
workspaceFoldersOptions.setSupported(true);
workspaceFoldersOptions.setChangeNotifications(true);
workspaceCapabilities.setWorkspaceFolders(workspaceFoldersOptions);
serverCapabilities.setWorkspace(workspaceCapabilities);
ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions();
executeCommandOptions.setCommands(Arrays.asList(ICommandConstants.ADD_IMPORT, ICommandConstants.ADD_MXML_NAMESPACE, ICommandConstants.ORGANIZE_IMPORTS_IN_URI, ICommandConstants.ORGANIZE_IMPORTS_IN_DIRECTORY, ICommandConstants.QUICK_COMPILE, ICommandConstants.GET_ACTIVE_PROJECT_URIS));
serverCapabilities.setExecuteCommandProvider(executeCommandOptions);
result.setCapabilities(serverCapabilities);
return CompletableFuture.completedFuture(result);
}
Aggregations