org.eclipse.lsp4j.ClientCapabilities Java Examples

The following examples show how to use org.eclipse.lsp4j.ClientCapabilities. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@code true} if the {@code TextDocumentClientCapabilities} explicitly declares the hierarchical document symbol
 * support at LS initialization time. Otherwise, false.
 */
protected boolean isHierarchicalDocumentSymbolSupport() {
	ClientCapabilities capabilities = initializeParams.getCapabilities();
	if (capabilities == null) {
		return false;
	}
	TextDocumentClientCapabilities textDocument = capabilities.getTextDocument();
	if (textDocument == null) {
		return false;
	}
	DocumentSymbolCapabilities documentSymbol = textDocument.getDocumentSymbol();
	if (documentSymbol == null) {
		return false;
	}
	Boolean hierarchicalDocumentSymbolSupport = documentSymbol.getHierarchicalDocumentSymbolSupport();
	if (hierarchicalDocumentSymbolSupport == null) {
		return false;
	}
	return hierarchicalDocumentSymbolSupport;
}
 
Example #2
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public void setClientCapabilities(ClientCapabilities value)
{
    completionSupportsSnippets = false;

    clientCapabilities = value;
    TextDocumentClientCapabilities textDocument = clientCapabilities.getTextDocument();
    if(textDocument != null)
    {
        CompletionCapabilities completion = textDocument.getCompletion();
        if(completion != null)
        {
            CompletionItemCapabilities completionItem = completion.getCompletionItem();
            if(completionItem != null)
            {
                completionSupportsSnippets = completionItem.getSnippetSupport();
            }
        }
    }
}
 
Example #3
Source File: AbstractIdeTest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** Connects, initializes and waits for the initial build of the test project. */
protected void startLspServer(File root) {
	ClientCapabilities capabilities = new ClientCapabilities();
	WorkspaceClientCapabilities wcc = new WorkspaceClientCapabilities();
	wcc.setExecuteCommand(new ExecuteCommandCapabilities());
	capabilities.setWorkspace(wcc);
	InitializeParams initParams = new InitializeParams();
	initParams.setCapabilities(capabilities);
	initParams.setRootUri(new FileURI(root).toString());

	languageClient.addListener(this);

	languageServer.connect(languageClient);
	languageServer.initialize(initParams);
	languageServer.initialized(null);
	joinServerRequests();
}
 
Example #4
Source File: InitHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private InitializeResult initialize(boolean dynamicRegistration) throws InterruptedException, ExecutionException {
	InitializeParams params = new InitializeParams();
	ClientCapabilities capabilities = new ClientCapabilities();
	WorkspaceClientCapabilities workspaceCapabilities = new WorkspaceClientCapabilities();
	workspaceCapabilities.setDidChangeConfiguration(new DidChangeConfigurationCapabilities(dynamicRegistration));
	ExecuteCommandCapabilities executeCommand = new ExecuteCommandCapabilities(dynamicRegistration);
	workspaceCapabilities.setExecuteCommand(executeCommand);
	capabilities.setWorkspace(workspaceCapabilities);
	TextDocumentClientCapabilities textDocument = new TextDocumentClientCapabilities();
	SynchronizationCapabilities synchronizationCapabilities = new SynchronizationCapabilities();
	synchronizationCapabilities.setWillSave(Boolean.TRUE);
	synchronizationCapabilities.setWillSaveWaitUntil(Boolean.TRUE);
	capabilities.setTextDocument(textDocument);
	params.setCapabilities(capabilities);
	CompletableFuture<InitializeResult> result = server.initialize(params);
	return result.get();
}
 
Example #5
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@code true} if the {@code TextDocumentClientCapabilities} explicitly declares the hierarchical document symbol
 * support at LS initialization time. Otherwise, false.
 */
protected boolean isHierarchicalDocumentSymbolSupport() {
	ClientCapabilities capabilities = initializeParams.getCapabilities();
	if (capabilities != null) {
		TextDocumentClientCapabilities textDocument = capabilities.getTextDocument();
		if (textDocument != null) {
			DocumentSymbolCapabilities documentSymbol = textDocument.getDocumentSymbol();
			if (documentSymbol != null) {
				Boolean hierarchicalDocumentSymbolSupport = documentSymbol.getHierarchicalDocumentSymbolSupport();
				if (hierarchicalDocumentSymbolSupport != null) {
					return hierarchicalDocumentSymbolSupport;
				}
			}
		}
	}
	return false;
}
 
Example #6
Source File: XMLTextDocumentService.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
public void updateClientCapabilities(ClientCapabilities capabilities,
		ExtendedClientCapabilities extendedClientCapabilities) {
	TextDocumentClientCapabilities textDocumentClientCapabilities = capabilities.getTextDocument();
	if (textDocumentClientCapabilities != null) {
		sharedSettings.getCompletionSettings().setCapabilities(textDocumentClientCapabilities.getCompletion());
		sharedSettings.getFoldingSettings().setCapabilities(textDocumentClientCapabilities.getFoldingRange());
		sharedSettings.getHoverSettings().setCapabilities(textDocumentClientCapabilities.getHover());
		codeActionLiteralSupport = textDocumentClientCapabilities.getCodeAction() != null
				&& textDocumentClientCapabilities.getCodeAction().getCodeActionLiteralSupport() != null;
		hierarchicalDocumentSymbolSupport = textDocumentClientCapabilities.getDocumentSymbol() != null
				&& textDocumentClientCapabilities.getDocumentSymbol().getHierarchicalDocumentSymbolSupport() != null
				&& textDocumentClientCapabilities.getDocumentSymbol().getHierarchicalDocumentSymbolSupport();
		definitionLinkSupport = textDocumentClientCapabilities.getDefinition() != null
				&& textDocumentClientCapabilities.getDefinition().getLinkSupport() != null
				&& textDocumentClientCapabilities.getDefinition().getLinkSupport();
		typeDefinitionLinkSupport = textDocumentClientCapabilities.getTypeDefinition() != null
				&& textDocumentClientCapabilities.getTypeDefinition().getLinkSupport() != null
				&& textDocumentClientCapabilities.getTypeDefinition().getLinkSupport();
	}
	if (extendedClientCapabilities != null) {
		// Extended client capabilities
		sharedSettings.getCodeLensSettings().setCodeLens(extendedClientCapabilities.getCodeLens());
		sharedSettings
				.setActionableNotificationSupport(extendedClientCapabilities.isActionableNotificationSupport());
		sharedSettings.setOpenSettingsCommandSupport(extendedClientCapabilities.isOpenSettingsCommandSupport());
	}
	// Workspace settings
	sharedSettings.getWorkspaceSettings().setCapabilities(capabilities.getWorkspace());
}
 
Example #7
Source File: ChangeConverter2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected ChangeConverter2(IResourceServiceProvider.Registry registry, WorkspaceEdit edit,
		ILanguageServerAccess access, UriExtensions uriExtensions) {
	this.registry = registry;
	this.uriExtensions = uriExtensions;
	this.edit = edit;
	this.access = access;
	Boolean documentChanges = null;
	if (access != null) {
		InitializeParams initializeParams = access.getInitializeParams();
		if (initializeParams != null) {
			ClientCapabilities clientCapabilities = initializeParams.getCapabilities();
			if (clientCapabilities != null) {
				WorkspaceClientCapabilities workspaceClientCapabilities = clientCapabilities.getWorkspace();
				if (workspaceClientCapabilities != null) {
					WorkspaceEditCapabilities workspaceEditCapabilities = workspaceClientCapabilities
							.getWorkspaceEdit();
					if (workspaceEditCapabilities != null) {
						documentChanges = workspaceEditCapabilities.getDocumentChanges();
					}
				}
			}
		}
	}
	this.useDocumentChanges = documentChanges == Boolean.TRUE;
	if (this.useDocumentChanges) {
		this.edit.setDocumentChanges(new ArrayList<>());
	} else {
		this.edit.setChanges(new LinkedHashMap<>());
	}
}
 
Example #8
Source File: ExecutableCommandRegistry.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void initialize(Iterable<? extends IResourceServiceProvider> allLanguages, ClientCapabilities capabilities,
		LanguageClient client) {
	this.client = client;
	this.registeredCommands = HashMultimap.create();
	boolean hasDynamicRegistration = false;
	WorkspaceClientCapabilities workspace = capabilities.getWorkspace();
	if (workspace != null) {
		ExecuteCommandCapabilities executeCommandCapabilities = workspace.getExecuteCommand();
		if (executeCommandCapabilities != null) {
			Boolean dynamicRegistration = executeCommandCapabilities.getDynamicRegistration();
			if (dynamicRegistration != null) {
				hasDynamicRegistration = dynamicRegistration.booleanValue();
			}
		}
	}
	for (IResourceServiceProvider lang : allLanguages) {
		IExecutableCommandService service = lang.get(IExecutableCommandService.class);
		if (service != null) {
			List<String> commands = service.initialize();
			for (String c : commands) {
				registeredCommands.put(c, service);
			}
			if (hasDynamicRegistration) {
				service.initializeDynamicRegistration((String command) -> {
					return register(command, service);
				});
			}
		}
	}
}
 
Example #9
Source File: CommandRegistryTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRegistration() {
	ExecutableCommandRegistry reg = new ExecutableCommandRegistry();
	ClientCapabilities cap = new ClientCapabilities();
	WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
	ExecuteCommandCapabilities executeCommandCapabilities = new ExecuteCommandCapabilities();
	executeCommandCapabilities.setDynamicRegistration(true);
	workspaceClientCapabilities.setExecuteCommand(executeCommandCapabilities);
	cap.setWorkspace(workspaceClientCapabilities);

	reg.initialize(Collections.unmodifiableList(Lists.newArrayList(this)), cap, this);
	Assert.assertEquals("static-command", Iterables.getFirst(reg.getCommands(), null));
	ExecuteCommandParams staticCommandParams = new ExecuteCommandParams();
	staticCommandParams.setCommand("static-command");
	reg.executeCommand(staticCommandParams, null, null);

	ExecuteCommandParams dynamicCommandParams = new ExecuteCommandParams();
	dynamicCommandParams.setCommand("dynamic-command");
	reg.executeCommand(dynamicCommandParams, null, null);
	Assert.assertEquals(Collections.unmodifiableSet(Sets.newHashSet("static-command")), commandsExecuted);
	commandsExecuted.clear();
	IDisposable disposable = register.apply("dynamic-command");

	ExecuteCommandParams dynamicCommandParams2 = new ExecuteCommandParams();
	dynamicCommandParams2.setCommand("dynamic-command");
	reg.executeCommand(dynamicCommandParams2, null, null);
	Assert.assertEquals(Collections.unmodifiableSet(Sets.newHashSet("dynamic-command")), commandsExecuted);
	commandsExecuted.clear();
	disposable.dispose();
	
	ExecuteCommandParams dynamicCommandParams3 = new ExecuteCommandParams();
	dynamicCommandParams3.setCommand("dynamic-command");
	reg.executeCommand(dynamicCommandParams3, null, null);
	Assert.assertEquals(Collections.unmodifiableSet(new HashSet<>()), commandsExecuted);
}
 
Example #10
Source File: ClientPreferencesTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testIsV3Supported() throws Exception {
	assertTrue(prefs.isV3Supported());

	prefs = new ClientPreferences(new ClientCapabilities());
	assertFalse(prefs.isV3Supported());
}
 
Example #11
Source File: InitHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMissingResourceOperations() throws Exception {
	ClientCapabilities capabilities = new ClientCapabilities();
	WorkspaceClientCapabilities worspaceCapabilities = new WorkspaceClientCapabilities();
	worspaceCapabilities.setWorkspaceEdit(new WorkspaceEditCapabilities());
	capabilities.setWorkspace(worspaceCapabilities);
	ClientPreferences preferences = new ClientPreferences(capabilities);
	assertFalse(preferences.isResourceOperationSupported());
}
 
Example #12
Source File: ClientPreferences.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param clientCapabilities
 * @param extendedClientCapabilities
 */
public ClientPreferences(ClientCapabilities caps, Map<String, Object> extendedClientCapabilities) {
	if (caps == null) {
		throw new IllegalArgumentException("ClientCapabilities can not be null");
	}
	this.capabilities = caps;
	this.v3supported = capabilities.getTextDocument() != null;
	this.extendedClientCapabilities = extendedClientCapabilities == null ? Collections.emptyMap() : extendedClientCapabilities;
}
 
Example #13
Source File: LSPBindings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static InitializeResult initServer(Process p, LanguageServer server, FileObject root) throws InterruptedException, ExecutionException {
   InitializeParams initParams = new InitializeParams();
   initParams.setRootUri(Utils.toURI(root));
   initParams.setRootPath(FileUtil.toFile(root).getAbsolutePath()); //some servers still expect root path
   initParams.setProcessId(0);
   TextDocumentClientCapabilities tdcc = new TextDocumentClientCapabilities();
   DocumentSymbolCapabilities dsc = new DocumentSymbolCapabilities();
   dsc.setHierarchicalDocumentSymbolSupport(true);
   dsc.setSymbolKind(new SymbolKindCapabilities(Arrays.asList(SymbolKind.values())));
   tdcc.setDocumentSymbol(dsc);
   WorkspaceClientCapabilities wcc = new WorkspaceClientCapabilities();
   wcc.setWorkspaceEdit(new WorkspaceEditCapabilities());
   wcc.getWorkspaceEdit().setDocumentChanges(true);
   wcc.getWorkspaceEdit().setResourceOperations(Arrays.asList(ResourceOperationKind.Create, ResourceOperationKind.Delete, ResourceOperationKind.Rename));
   initParams.setCapabilities(new ClientCapabilities(wcc, tdcc, null));
   CompletableFuture<InitializeResult> initResult = server.initialize(initParams);
   while (true) {
       try {
           return initResult.get(100, TimeUnit.MILLISECONDS);
       } catch (TimeoutException ex) {
           if (p != null && !p.isAlive()) {
               InitializeResult emptyResult = new InitializeResult();
               emptyResult.setCapabilities(new ServerCapabilities());
               return emptyResult;
           }
       }
   }
}
 
Example #14
Source File: XMLCapabilitiesTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@BeforeEach
public void startup() {

	textDocumentService = new XMLTextDocumentService(null);
	textDocumentService.getSharedSettings().getFormattingSettings().setEnabled(true);

	textDocument = new TextDocumentClientCapabilities();
	workspace = new WorkspaceClientCapabilities();
	manager = new XMLCapabilityManager(languageClient, textDocumentService);
	clientCapabilities = new ClientCapabilities();
	capabilityIDs = null;

}
 
Example #15
Source File: LanguageServerWrapper.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
private InitializeParams getInitParams() {
    InitializeParams initParams = new InitializeParams();
    initParams.setRootUri(FileUtils.pathToUri(projectRootPath));
    //TODO update capabilities when implemented
    WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
    workspaceClientCapabilities.setApplyEdit(true);
    workspaceClientCapabilities.setDidChangeWatchedFiles(new DidChangeWatchedFilesCapabilities());
    workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities());
    workspaceClientCapabilities.setWorkspaceEdit(new WorkspaceEditCapabilities());
    workspaceClientCapabilities.setSymbol(new SymbolCapabilities());
    workspaceClientCapabilities.setWorkspaceFolders(false);
    workspaceClientCapabilities.setConfiguration(false);

    TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
    textDocumentClientCapabilities.setCodeAction(new CodeActionCapabilities());
    textDocumentClientCapabilities.setCompletion(new CompletionCapabilities(new CompletionItemCapabilities(true)));
    textDocumentClientCapabilities.setDefinition(new DefinitionCapabilities());
    textDocumentClientCapabilities.setDocumentHighlight(new DocumentHighlightCapabilities());
    textDocumentClientCapabilities.setFormatting(new FormattingCapabilities());
    textDocumentClientCapabilities.setHover(new HoverCapabilities());
    textDocumentClientCapabilities.setOnTypeFormatting(new OnTypeFormattingCapabilities());
    textDocumentClientCapabilities.setRangeFormatting(new RangeFormattingCapabilities());
    textDocumentClientCapabilities.setReferences(new ReferencesCapabilities());
    textDocumentClientCapabilities.setRename(new RenameCapabilities());
    textDocumentClientCapabilities.setSemanticHighlightingCapabilities(new SemanticHighlightingCapabilities(false));
    textDocumentClientCapabilities.setSignatureHelp(new SignatureHelpCapabilities());
    textDocumentClientCapabilities.setSynchronization(new SynchronizationCapabilities(true, true, true));
    initParams.setCapabilities(
            new ClientCapabilities(workspaceClientCapabilities, textDocumentClientCapabilities, null));
    initParams.setInitializationOptions(
            serverDefinition.getInitializationOptions(URI.create(initParams.getRootUri())));

    return initParams;
}
 
Example #16
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected InitializeResult initialize(final Procedure1<? super InitializeParams> initializer, final boolean callInitialized) {
  try {
    InitializeParams _initializeParams = new InitializeParams();
    final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
      it.setProcessId(Integer.valueOf(1));
      it.setRootUri(this._uriExtensions.toUriString(this.root.toURI().normalize()));
      String _rootUri = it.getRootUri();
      WorkspaceFolder _workspaceFolder = new WorkspaceFolder(_rootUri, "");
      it.setWorkspaceFolders(Collections.<WorkspaceFolder>unmodifiableList(CollectionLiterals.<WorkspaceFolder>newArrayList(_workspaceFolder)));
    };
    final InitializeParams params = ObjectExtensions.<InitializeParams>operator_doubleArrow(_initializeParams, _function);
    if (initializer!=null) {
      initializer.apply(params);
    }
    Boolean _elvis = null;
    ClientCapabilities _capabilities = params.getCapabilities();
    TextDocumentClientCapabilities _textDocument = null;
    if (_capabilities!=null) {
      _textDocument=_capabilities.getTextDocument();
    }
    DocumentSymbolCapabilities _documentSymbol = null;
    if (_textDocument!=null) {
      _documentSymbol=_textDocument.getDocumentSymbol();
    }
    Boolean _hierarchicalDocumentSymbolSupport = null;
    if (_documentSymbol!=null) {
      _hierarchicalDocumentSymbolSupport=_documentSymbol.getHierarchicalDocumentSymbolSupport();
    }
    if (_hierarchicalDocumentSymbolSupport != null) {
      _elvis = _hierarchicalDocumentSymbolSupport;
    } else {
      _elvis = Boolean.valueOf(false);
    }
    this.hierarchicalDocumentSymbolSupport = (_elvis).booleanValue();
    final InitializeResult result = this.languageServer.initialize(params).get();
    if (callInitialized) {
      this.languageServer.initialized(null);
    }
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #17
Source File: InitializeParamsTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
protected void writeCapabilities(final JsonWriter out, final ClientCapabilities value) throws IOException {
  gson.toJson(value, ClientCapabilities.class, out);
}
 
Example #18
Source File: InitializeParamsTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
protected ClientCapabilities readCapabilities(final JsonReader in) throws IOException {
  return gson.fromJson(in, ClientCapabilities.class);
}
 
Example #19
Source File: InitializeParams.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The capabilities provided by the client (editor)
 */
public void setCapabilities(final ClientCapabilities capabilities) {
  this.capabilities = capabilities;
}
 
Example #20
Source File: InitializeParams.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The capabilities provided by the client (editor)
 */
@Pure
public ClientCapabilities getCapabilities() {
  return this.capabilities;
}
 
Example #21
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * 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;
	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 (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);
	}
	semanticHighlightingRegistry.initialize(allLanguages, clientCapabilities, client);
	serverCapabilities.setSemanticHighlighting(
			new SemanticHighlightingServerCapabilities(semanticHighlightingRegistry.getAllScopes()));

	for (IResourceServiceProvider language : allLanguages) {
		ICapabilitiesContributor capabilitiesContributor = language.get(ICapabilitiesContributor.class);
		if (capabilitiesContributor != null) {
			capabilitiesContributor.contribute(serverCapabilities, params);
		}
	}
	return serverCapabilities;
}
 
Example #22
Source File: ClientCapabilitiesWrapper.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public ClientCapabilitiesWrapper() {
	this(new ClientCapabilities(), null);
}
 
Example #23
Source File: ClientCapabilitiesWrapper.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public ClientCapabilitiesWrapper(ClientCapabilities capabilities, ExtendedClientCapabilities extendedCapabilities) {
	this.capabilities = capabilities;
	this.v3Supported = capabilities != null ? capabilities.getTextDocument() != null : false;
	this.extendedCapabilities = extendedCapabilities;
}
 
Example #24
Source File: AbstractNotifierTest.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
protected void setSupportCapabilities(boolean supportActionableNotification, boolean supportOpenSettings) {
	ExtendedClientCapabilities capabilities = new ExtendedClientCapabilities();
	capabilities.setActionableNotificationSupport(supportActionableNotification);
	capabilities.setOpenSettingsCommandSupport(supportOpenSettings);
	getTextDocumentService().updateClientCapabilities(new ClientCapabilities(), capabilities);
}
 
Example #25
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
public ClientCapabilities getClientCapabilities()
{
    return clientCapabilities;
}
 
Example #26
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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(ICodeActionService.class) != null
					|| 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(IRenameService.class) != null
						|| 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);
	}
	semanticHighlightingRegistry.initialize(allLanguages, clientCapabilities, client);
	serverCapabilities.setSemanticHighlighting(new SemanticHighlightingServerCapabilities(
			semanticHighlightingRegistry.getAllScopes()));

	for (IResourceServiceProvider language : allLanguages) {
		ICapabilitiesContributor capabilitiesContributor = language.get(ICapabilitiesContributor.class);
		if (capabilitiesContributor != null) {
			capabilitiesContributor.contribute(serverCapabilities, params);
		}
	}
	return serverCapabilities;
}
 
Example #27
Source File: DefaultLanguageServerWrapper.java    From MSPaintIDE with MIT License 4 votes vote down vote up
@Override
    public InitializeParams getInitParams() {
        InitializeParams initParams = new InitializeParams();
        if (this.rootPath != null) {
            var root = rootPath.toURI().toString();
            if (this.useInputForWorkspace) {
                root = rootPath.toPath().relativize(inputFile.toPath()).toUri().toString();
            }

            initParams.setRootUri(root);
            LOGGER.info("Workspace root is {}", root);
        }
        WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
        workspaceClientCapabilities.setApplyEdit(true);
        workspaceClientCapabilities.setDidChangeWatchedFiles(new DidChangeWatchedFilesCapabilities());
        workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities());
        workspaceClientCapabilities.setWorkspaceEdit(new WorkspaceEditCapabilities());
//        workspaceClientCapabilities.setSymbol(new SymbolCapabilities());
        workspaceClientCapabilities.setWorkspaceFolders(true);
        workspaceClientCapabilities.setConfiguration(true);

        TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
        textDocumentClientCapabilities.setCodeAction(new CodeActionCapabilities());
        textDocumentClientCapabilities.setCompletion(new CompletionCapabilities(new CompletionItemCapabilities(false)));
        textDocumentClientCapabilities.setDefinition(new DefinitionCapabilities());
//        textDocumentClientCapabilities.setDocumentHighlight(new DocumentHighlightCapabilities());
        textDocumentClientCapabilities.setFormatting(new FormattingCapabilities());
//        textDocumentClientCapabilities.setHover(new HoverCapabilities());
//        textDocumentClientCapabilities.setOnTypeFormatting(new OnTypeFormattingCapabilities());
//        textDocumentClientCapabilities.setRangeFormatting(new RangeFormattingCapabilities());
        textDocumentClientCapabilities.setReferences(new ReferencesCapabilities());
        textDocumentClientCapabilities.setRename(new RenameCapabilities());
        textDocumentClientCapabilities.setSemanticHighlightingCapabilities(new SemanticHighlightingCapabilities(false));
        textDocumentClientCapabilities.setSignatureHelp(new SignatureHelpCapabilities());
        textDocumentClientCapabilities.setSynchronization(new SynchronizationCapabilities(true, true, true));
        initParams.setCapabilities(
                new ClientCapabilities(workspaceClientCapabilities, textDocumentClientCapabilities, null));
//        initParams.setInitializationOptions(null);
//        initParams.setInitializationOptions(
//                serverDefinition.getInitializationOptions(URI.create(initParams.getRootUri())));

        return initParams;
    }
 
Example #28
Source File: ClientPreferences.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public ClientPreferences(ClientCapabilities caps) {
	this(caps, null);
}
 
Example #29
Source File: PreferenceManager.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @param clientCapabilities
 *                                       the clientCapabilities to set
 * @param extendedClientCapabilities
 */
public void updateClientPrefences(ClientCapabilities clientCapabilities, Map<String, Object> extendedClientCapabilities) {
	this.clientPreferences = new ClientPreferences(clientCapabilities, extendedClientCapabilities);
}
 
Example #30
Source File: XMLCapabilityManager.java    From lemminx with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Creates and sets a {@link ClientCapabilitiesWrapper} instance formed from
 * clientCapabilities
 * 
 * @param clientCapabilities
 * @param extendedClientCapabilities
 */
public void setClientCapabilities(ClientCapabilities clientCapabilities,
		ExtendedClientCapabilities extendedClientCapabilities) {
	this.clientWrapper = new ClientCapabilitiesWrapper(clientCapabilities, extendedClientCapabilities);
}