org.eclipse.lsp4j.RegistrationParams Java Examples

The following examples show how to use org.eclipse.lsp4j.RegistrationParams. 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: ExecutableCommandRegistry.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected IDisposable register(String command, IExecutableCommandService service) {
	String requestId = UUID.randomUUID().toString();
	Registration reg = new Registration();
	reg.setId(requestId);
	reg.setMethod(ExecutableCommandRegistry.METHOD);
	ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions();
	executeCommandOptions.setCommands(Collections.unmodifiableList(Lists.newArrayList(command)));
	reg.setRegisterOptions(executeCommandOptions);
	RegistrationParams registrationParams = new RegistrationParams();
	registrationParams.setRegistrations(Lists.newArrayList(reg));
	client.registerCapability(registrationParams);
	registeredCommands.put(command, service);
	return () -> {
		Unregistration unReg = new Unregistration();
		unReg.setId(requestId);
		unReg.setMethod(ExecutableCommandRegistry.METHOD);
		UnregistrationParams unregistrationParams = new UnregistrationParams();
		unregistrationParams.setUnregisterations(Lists.newArrayList(unReg));
		this.client.unregisterCapability(unregistrationParams);
		this.registeredCommands.remove(command, service);
	};
}
 
Example #2
Source File: DefaultLanguageClient.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
    return CompletableFuture.runAsync(() -> params.getRegistrations().forEach(r -> {
        String id = r.getId();
        Optional<DynamicRegistrationMethods> method = DynamicRegistrationMethods.forName(r.getMethod());
        method.ifPresent(dynamicRegistrationMethods -> registrations.put(id, dynamicRegistrationMethods));

    }));
}
 
Example #3
Source File: LanguageServerWrapper.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
void registerCapability(RegistrationParams params) {
    params.getRegistrations().forEach(reg -> {
        if ("workspace/didChangeWorkspaceFolders".equals(reg.getMethod())) { //$NON-NLS-1$
            assert serverCapabilities != null :
                    "Dynamic capability registration failed! Server not yet initialized?"; //$NON-NLS-1$
            if (initiallySupportsWorkspaceFolders) {
                // Can treat this as a NOP since nothing can disable it dynamically if it was
                // enabled on initialization.
            } else if (supportsWorkspaceFolders(serverCapabilities)) {
                LOGGER.warn(
                        "Dynamic registration of 'workspace/didChangeWorkspaceFolders' ignored. It was already enabled before"); //$NON-NLS-1$);
            } else {
                addRegistration(reg, () -> setWorkspaceFoldersEnablement(false));
                setWorkspaceFoldersEnablement(true);
            }
        } else if ("workspace/executeCommand".equals(reg.getMethod())) { //$NON-NLS-1$
            Gson gson = new Gson(); // TODO? retrieve the GSon used by LS
            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$
            final Boolean beforeRegistration = serverCapabilities.getDocumentFormattingProvider();
            serverCapabilities.setDocumentFormattingProvider(Boolean.TRUE);
            addRegistration(reg, () -> serverCapabilities.setDocumentFormattingProvider(beforeRegistration));
        } else if ("textDocument/rangeFormatting".equals(reg.getMethod())) { //$NON-NLS-1$
            final Boolean beforeRegistration = serverCapabilities.getDocumentRangeFormattingProvider();
            serverCapabilities.setDocumentRangeFormattingProvider(Boolean.TRUE);
            addRegistration(reg, () -> serverCapabilities.setDocumentRangeFormattingProvider(beforeRegistration));
        }
    });
}
 
Example #4
Source File: XMLCapabilityManager.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
public void registerCapability(String id, String method, Object options) {
	if (registeredCapabilities.add(id)) {
		Registration registration = new Registration(id, method, options);
		RegistrationParams registrationParams = new RegistrationParams(Collections.singletonList(registration));
		languageClient.registerCapability(registrationParams);
	}
}
 
Example #5
Source File: BaseJDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void registerCapability(String id, String method, Object options) {
	if (registeredCapabilities.add(id)) {
		Registration registration = new Registration(id, method, options);
		RegistrationParams registrationParams = new RegistrationParams(Collections.singletonList(registration));
		client.registerCapability(registrationParams);
	}
}
 
Example #6
Source File: ActionScriptLanguageServer.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
@Override
public void initialized(InitializedParams params)
{
    boolean canRegisterDidChangeWatchedFiles = false;
    try
    {
        canRegisterDidChangeWatchedFiles = actionScriptServices.getClientCapabilities().getWorkspace().getDidChangeWatchedFiles().getDynamicRegistration();
    }
    catch(NullPointerException e)
    {
        canRegisterDidChangeWatchedFiles = false;
    }
    if(canRegisterDidChangeWatchedFiles)
    {
        List<FileSystemWatcher> watchers = new ArrayList<>();
        //ideally, we'd only check .as, .mxml, asconfig.json, and directories
        //but there's no way to target directories without *
        watchers.add(new FileSystemWatcher("**/*"));

        String id = "as3mxml-language-server-" + Math.random();
        DidChangeWatchedFilesRegistrationOptions options = new DidChangeWatchedFilesRegistrationOptions(watchers);
        Registration registration = new Registration(id, "workspace/didChangeWatchedFiles", options);
        List<Registration> registrations = new ArrayList<>();
        registrations.add(registration);

        RegistrationParams registrationParams = new RegistrationParams(registrations);
        languageClient.registerCapability(registrationParams);
    }

    //we can't notify the client about problems until we receive this
    //initialized notification. this is the first time that we'll start
    //checking for errors.
    actionScriptServices.setInitialized();
}
 
Example #7
Source File: LanguageClientImpl.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
    return CompletableFuture.runAsync(() -> wrapper.registerCapability(params));
}
 
Example #8
Source File: XMLCapabilitiesTest.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
	return null;
}
 
Example #9
Source File: JavaClientConnection.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @see {@link org.eclipse.lsp4j.services.LanguageClient#registerCapability(RegistrationParams)}
 */
public void registerCapability(RegistrationParams params) {
	client.registerCapability(params);
}
 
Example #10
Source File: CommandRegistryTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
	Registration reg = Iterables.getFirst(params.getRegistrations(), null);
	registered.put(reg.getId(), reg);
	return CompletableFuture.completedFuture(null);
}
 
Example #11
Source File: LanguageClient.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * The client/registerCapability request is sent from the server to the client
 * to register for a new capability on the client side.
 * Not all clients need to support dynamic capability registration.
 * A client opts in via the ClientCapabilities.dynamicRegistration property
 */
@JsonRequest("client/registerCapability")
default CompletableFuture<Void> registerCapability(RegistrationParams params) {
	throw new UnsupportedOperationException();
}