下面列出了怎么用org.eclipse.lsp4j.InitializedParams的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testRegisterDelayedCapability() throws Exception {
ClientPreferences mockCapabilies = mock(ClientPreferences.class);
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
when(mockCapabilies.isDocumentSymbolDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isWorkspaceSymbolDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isDocumentSymbolDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isCodeActionDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isDefinitionDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isHoverDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isReferencesDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isDocumentHighlightDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isFoldgingRangeDynamicRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isCompletionDynamicRegistered()).thenReturn(Boolean.TRUE);
InitializeResult result = initialize(true);
assertNull(result.getCapabilities().getDocumentSymbolProvider());
server.initialized(new InitializedParams());
verify(client, times(9)).registerCapability(any());
}
private void performCompile() {
if (options.isClean()) {
performClean();
callback.resetCounters();
}
Stopwatch compilationTime = Stopwatch.createStarted();
try (Measurement m = N4JSDataCollectors.dcBuild.getMeasurement()) {
languageServer.initialized(new InitializedParams());
languageServer.joinServerRequests();
}
printCompileResults(compilationTime.stop());
}
@Override
public CompletableFuture<Void> start(File rootPath) {
setStatus(STARTING);
this.client = new LSPClient(this.startupLogic);
this.rootPath = rootPath;
try {
var processedArgs = this.argumentPreprocessor.apply(this, new ArrayList<>(this.lspArgs));
var streamConnectionProvider = new LSPProvider(
() -> requestManager,
processedArgs,
serverPath.get());
streamConnectionProvider.start();
Launcher<LanguageServer> launcher =
Launcher.createLauncher(client, LanguageServer.class, streamConnectionProvider.getInputStream(), streamConnectionProvider.getOutputStream());
languageServer = launcher.getRemoteProxy();
client.connect(languageServer);
launcherFuture = launcher.startListening();
return (startingFuture = languageServer.initialize(getInitParams()).thenApply(res -> {
LOGGER.info("Started LSP");
requestManager = new DefaultRequestManager(this, languageServer, client, res.getCapabilities());
setStatus(STARTED);
requestManager.initialized(new InitializedParams());
setStatus(INITIALIZED);
return res;
}).thenRun(() -> LOGGER.info("Done starting LSP!")));
} catch (Exception e) {
LOGGER.error("Can't launch language server for project", e);
}
return CompletableFuture.runAsync(() -> {});
}
@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 void initialized(InitializedParams params) {
capabilityManager.initializeCapabilities();
}
@Override
public void initialized(InitializedParams params) {
lspBuilder.initialBuild();
clientInitialized.complete(params);
}
@Override
public void initialized(InitializedParams params) {
initialized.complete(params);
}
/**
* The initialized notification is sent from the client to the server after
* the client received the result of the initialize request but before the
* client is sending any other request or notification to the server. The
* server can use the initialized notification for example to dynamically
* register capabilities.
*/
@JsonNotification
default void initialized(InitializedParams params) {
initialized();
}