use of org.eclipse.lsp4j.Registration in project xtext-core by eclipse.
the class CommandRegistryTest method registerCapability.
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
Registration reg = Iterables.getFirst(params.getRegistrations(), null);
registered.put(reg.getId(), reg);
return CompletableFuture.completedFuture(null);
}
use of org.eclipse.lsp4j.Registration in project eclipse.jdt.ls by eclipse.
the class JDTLanguageServer method registerCapability.
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);
}
}
use of org.eclipse.lsp4j.Registration in project xtext-core by eclipse.
the class ExecutableCommandRegistry method register.
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);
};
}
use of org.eclipse.lsp4j.Registration in project sts4 by spring-projects.
the class ClasspathListenerManager method addClasspathListener.
public Disposable addClasspathListener(ClasspathListener classpathListener) {
String callbackCommandId = "sts4.classpath." + RandomStringUtils.randomAlphabetic(8);
// 1. register callback command handler in SimpleLanguageServer
Disposable unregisterCommand = server.onCommand(callbackCommandId, (ExecuteCommandParams callbackParams) -> async.invoke(() -> {
List<Object> args = callbackParams.getArguments();
// Note: not sure... but args might be deserialized as com.google.gson.JsonElement's.
// If so the code below is not correct (casts will fail).
String projectUri = ((JsonElement) args.get(0)).getAsString();
String name = ((JsonElement) args.get(1)).getAsString();
boolean deleted = ((JsonElement) args.get(2)).getAsBoolean();
Classpath classpath = gson.fromJson((JsonElement) args.get(3), Classpath.class);
classpathListener.changed(new ClasspathListener.Event(projectUri, name, deleted, classpath));
return "done";
}));
// 2. register the callback command with the client
String registrationId = UUID.randomUUID().toString();
RegistrationParams params = new RegistrationParams(ImmutableList.of(new Registration(registrationId, WORKSPACE_EXECUTE_COMMAND, ImmutableMap.of("commands", ImmutableList.of(callbackCommandId)))));
server.getClient().registerCapability(params).join();
// 3. call the client to ask it to call that callback
server.getClient().addClasspathListener(new ClasspathListenerParams(callbackCommandId)).join();
// Cleanups:
return () -> {
try {
log.info("Unregistering classpath callback " + callbackCommandId + " ...");
this.server.getClient().removeClasspathListener(new ClasspathListenerParams(callbackCommandId)).join();
log.info("Unregistering classpath callback " + callbackCommandId + " OK");
this.server.getClient().unregisterCapability(new UnregistrationParams(ImmutableList.of(new Unregistration(registrationId, WORKSPACE_EXECUTE_COMMAND)))).join();
unregisterCommand.dispose();
} catch (Exception e) {
log.error("", e);
}
};
}
use of org.eclipse.lsp4j.Registration in project sts4 by spring-projects.
the class SimpleLanguageServer method initialized.
@Override
public void initialized() {
async.withLog(log, () -> {
Registration registration = new Registration(WORKSPACE_FOLDERS_CAPABILITY_ID, WORKSPACE_FOLDERS_CAPABILITY_NAME, null);
RegistrationParams registrationParams = new RegistrationParams(Collections.singletonList(registration));
getClient().registerCapability(registrationParams);
// triggers onInitialized handlers.
this.initialized.complete(null);
});
}
Aggregations