org.eclipse.lsp4j.WorkspaceClientCapabilities Java Examples

The following examples show how to use org.eclipse.lsp4j.WorkspaceClientCapabilities. 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: 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 #2
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 #3
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 #4
Source File: XMLSchemaDiagnosticsTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void localSchemaFileMissingCodeAction() throws Exception {
	String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //
			"<invoice xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + //
			"  xsi:noNamespaceSchemaLocation=\"/salad.xsd\">\n" + //
			"</invoice>";
	Diagnostic missingSchemaDiagnostic = d(2, 32, 44, XMLSchemaErrorCode.schema_reference_4);
	missingSchemaDiagnostic.setMessage("schema_reference.4: Failed to read schema document "
			+ "'file:///salad.xsd',"
			+ " because 1) could not find the document; 2) the document could not be read;"
			+ " 3) the root element of the document is not <xsd:schema>.");
	Diagnostic eltDiagnostic = d(1, 1, 8, XMLSchemaErrorCode.cvc_elt_1_a);
	eltDiagnostic.setMessage("cvc-elt.1.a: Cannot find the declaration of element 'invoice'.");
	XMLAssert.testDiagnosticsFor(xml, missingSchemaDiagnostic, eltDiagnostic);

	SharedSettings settings = new SharedSettings();
	WorkspaceClientCapabilities workspace = new WorkspaceClientCapabilities();
	WorkspaceEditCapabilities workspaceEdit = new WorkspaceEditCapabilities();
	workspaceEdit.setResourceOperations(Arrays.asList(ResourceOperationKind.Create));
	workspace.setWorkspaceEdit(workspaceEdit);
	settings.getWorkspaceSettings().setCapabilities(workspace);

	XMLAssert.testCodeActionsFor(xml, //
			missingSchemaDiagnostic, //
			settings, //
			ca(missingSchemaDiagnostic, //
					createFile("file:///salad.xsd", false), //
					teOp("file:///salad.xsd", 0, 0, 0, 0, //
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + lineSeparator() + //
									"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">" + lineSeparator() + //
									"  <xs:element name=\"invoice\" type=\"xs:string\" />" + lineSeparator() + //
									"</xs:schema>")));
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: ClientCapabilities.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Workspace specific client capabilities.
 */
public void setWorkspace(final WorkspaceClientCapabilities workspace) {
  this.workspace = workspace;
}
 
Example #12
Source File: ClientCapabilities.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Workspace specific client capabilities.
 */
@Pure
public WorkspaceClientCapabilities getWorkspace() {
  return this.workspace;
}
 
Example #13
Source File: ClientCapabilities.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public ClientCapabilities(final WorkspaceClientCapabilities workspace, final TextDocumentClientCapabilities textDocument, final Object experimental) {
  this.workspace = workspace;
  this.textDocument = textDocument;
  this.experimental = experimental;
}
 
Example #14
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 #15
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 #16
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 #17
Source File: XMLWorkspaceSettings.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public void setCapabilities(WorkspaceClientCapabilities workspace) {
	this.workspace = workspace;
}