org.eclipse.lsp4j.RenameCapabilities Java Examples

The following examples show how to use org.eclipse.lsp4j.RenameCapabilities. 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: XMLCapabilitiesTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
private void setAllCapabilities(boolean areAllDynamic) {
	textDocument.setRangeFormatting(new RangeFormattingCapabilities(areAllDynamic));
	textDocument.setFormatting(new FormattingCapabilities(areAllDynamic));
	CompletionCapabilities completion = new CompletionCapabilities();
	completion.setDynamicRegistration(areAllDynamic);
	textDocument.setCompletion(completion);
	textDocument.setDocumentSymbol(new DocumentSymbolCapabilities(areAllDynamic));
	textDocument.setHover(new HoverCapabilities(areAllDynamic));
	textDocument.setDocumentHighlight(new DocumentHighlightCapabilities(areAllDynamic));
	textDocument.setRename(new RenameCapabilities(areAllDynamic));
	FoldingRangeCapabilities folding = new FoldingRangeCapabilities();
	folding.setDynamicRegistration(areAllDynamic);
	textDocument.setFoldingRange(folding);
	textDocument.setDocumentLink(new DocumentLinkCapabilities(areAllDynamic));
	textDocument.setCodeAction(new CodeActionCapabilities(areAllDynamic));
	workspace.setDidChangeWatchedFiles(new DidChangeWatchedFilesCapabilities(areAllDynamic));
}
 
Example #2
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 #3
Source File: ClientPreferencesTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testIsRenameDynamicRegistrationSupported() throws Exception {
	assertFalse(prefs.isRenameDynamicRegistrationSupported());
	when(text.getRename()).thenReturn(new RenameCapabilities());
	assertFalse(prefs.isRenameDynamicRegistrationSupported());
	when(text.getRename()).thenReturn(new RenameCapabilities(true));
	assertTrue(prefs.isRenameDynamicRegistrationSupported());
}
 
Example #4
Source File: XMLCapabilitiesTest.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testBothCapabilityTypes() {
	// Dynamic capabilities
	textDocument.setRangeFormatting(new RangeFormattingCapabilities(true));
	textDocument.setFormatting(new FormattingCapabilities(true));
	CompletionCapabilities completion = new CompletionCapabilities();
	completion.setDynamicRegistration(true);
	textDocument.setCompletion(completion);
	textDocument.setDocumentSymbol(new DocumentSymbolCapabilities(true));
	workspace.setDidChangeWatchedFiles(new DidChangeWatchedFilesCapabilities(true));

	// Non dynamic capabilities
	textDocument.setHover(new HoverCapabilities(false));
	textDocument.setDocumentHighlight(new DocumentHighlightCapabilities(false));
	textDocument.setRename(new RenameCapabilities(false));
	FoldingRangeCapabilities folding = new FoldingRangeCapabilities();
	folding.setDynamicRegistration(false);
	textDocument.setFoldingRange(folding);
	textDocument.setDocumentLink(new DocumentLinkCapabilities(false));
	textDocument.setCodeAction(new CodeActionCapabilities(false));

	setAndInitializeCapabilities();

	assertEquals(5, capabilityIDs.size());
	assertEquals(true, capabilityIDs.contains(FORMATTING_ID));
	assertEquals(true, capabilityIDs.contains(FORMATTING_RANGE_ID));
	assertEquals(true, capabilityIDs.contains(COMPLETION_ID));
	assertEquals(true, capabilityIDs.contains(DOCUMENT_SYMBOL_ID));

	ServerCapabilities serverCapabilities = ServerCapabilitiesInitializer
			.getNonDynamicServerCapabilities(manager.getClientCapabilities(), false);
	assertEquals(false, serverCapabilities.getDocumentRangeFormattingProvider());
	assertEquals(false, serverCapabilities.getDocumentFormattingProvider());
	assertEquals(false, serverCapabilities.getDocumentSymbolProvider());
	assertEquals(true, serverCapabilities.getHoverProvider());
	assertEquals(true, serverCapabilities.getDocumentHighlightProvider());
	assertEquals(true, serverCapabilities.getRenameProvider().getLeft());
	assertEquals(true, serverCapabilities.getFoldingRangeProvider().getLeft());
	assertEquals(true, serverCapabilities.getCodeActionProvider().getLeft());
	assertEquals(null, serverCapabilities.getCompletionProvider());
	assertEquals(DEFAULT_LINK_OPTIONS, serverCapabilities.getDocumentLinkProvider());
}
 
Example #5
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 #6
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 #7
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 #8
Source File: TextDocumentClientCapabilities.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Capabilities specific to the `textDocument/rename`
 */
@Pure
public RenameCapabilities getRename() {
  return this.rename;
}
 
Example #9
Source File: TextDocumentClientCapabilities.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Capabilities specific to the `textDocument/rename`
 */
public void setRename(final RenameCapabilities rename) {
  this.rename = rename;
}