下面列出了怎么用org.eclipse.lsp4j.Registration的API类实例代码及写法,或者点击链接到github查看源代码。
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);
};
}
private void addRegistration(@Nonnull Registration reg, @Nonnull Runnable unregistrationHandler) {
String regId = reg.getId();
synchronized (dynamicRegistrations) {
assert !dynamicRegistrations.containsKey(regId):"Registration id is not unique"; //$NON-NLS-1$
dynamicRegistrations.put(regId, unregistrationHandler);
}
}
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);
}
}
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);
}
}
@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();
}
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
Registration reg = Iterables.getFirst(params.getRegistrations(), null);
registered.put(reg.getId(), reg);
return CompletableFuture.completedFuture(null);
}
public RegistrationParams() {
this(new ArrayList<Registration>());
}
public RegistrationParams(@NonNull final List<Registration> registrations) {
this.registrations = Preconditions.<List<Registration>>checkNotNull(registrations, "registrations");
}
@Pure
@NonNull
public List<Registration> getRegistrations() {
return this.registrations;
}
public void setRegistrations(@NonNull final List<Registration> registrations) {
this.registrations = Preconditions.checkNotNull(registrations, "registrations");
}