下面列出了怎么用org.eclipse.lsp4j.RegistrationParams的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);
};
}
@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));
}));
}
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));
}
});
}
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) {
return CompletableFuture.runAsync(() -> wrapper.registerCapability(params));
}
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
return null;
}
/**
* @see {@link org.eclipse.lsp4j.services.LanguageClient#registerCapability(RegistrationParams)}
*/
public void registerCapability(RegistrationParams params) {
client.registerCapability(params);
}
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
Registration reg = Iterables.getFirst(params.getRegistrations(), null);
registered.put(reg.getId(), reg);
return CompletableFuture.completedFuture(null);
}
/**
* 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();
}