use of org.eclipse.lsp4j.InitializeParams in project xtext-core by eclipse.
the class AbstractLanguageServerTest method initialize.
protected InitializeResult initialize(final Procedure1<? super InitializeParams> initializer, final boolean callInitialized) {
try {
InitializeParams _initializeParams = new InitializeParams();
final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
it.setProcessId(Integer.valueOf(1));
String _uriString = this._uriExtensions.toUriString(this.root.toURI().normalize());
WorkspaceFolder _workspaceFolder = new WorkspaceFolder(_uriString, "");
it.setWorkspaceFolders(Collections.<WorkspaceFolder>unmodifiableList(CollectionLiterals.<WorkspaceFolder>newArrayList(_workspaceFolder)));
};
final InitializeParams params = ObjectExtensions.<InitializeParams>operator_doubleArrow(_initializeParams, _function);
if (initializer != null) {
initializer.apply(params);
}
Boolean _elvis = null;
ClientCapabilities _capabilities = params.getCapabilities();
TextDocumentClientCapabilities _textDocument = null;
if (_capabilities != null) {
_textDocument = _capabilities.getTextDocument();
}
DocumentSymbolCapabilities _documentSymbol = null;
if (_textDocument != null) {
_documentSymbol = _textDocument.getDocumentSymbol();
}
Boolean _hierarchicalDocumentSymbolSupport = null;
if (_documentSymbol != null) {
_hierarchicalDocumentSymbolSupport = _documentSymbol.getHierarchicalDocumentSymbolSupport();
}
if (_hierarchicalDocumentSymbolSupport != null) {
_elvis = _hierarchicalDocumentSymbolSupport;
} else {
_elvis = Boolean.valueOf(false);
}
this.hierarchicalDocumentSymbolSupport = (_elvis).booleanValue();
final InitializeResult result = this.languageServer.initialize(params).get();
if (callInitialized) {
this.languageServer.initialized(null);
}
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.InitializeParams in project sts4 by spring-projects.
the class SimpleLanguageServer method initialize.
@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
Log.debug("Initializing: " + params);
// multi-root workspace handling
List<WorkspaceFolder> workspaceFolders = getWorkspaceFolders(params);
if (!workspaceFolders.isEmpty()) {
this.getWorkspaceService().setWorkspaceFolders(workspaceFolders);
} else {
String rootUri = params.getRootUri();
if (rootUri == null) {
Log.debug("workspaceRoot NOT SET");
} else {
List<WorkspaceFolder> singleRootFolder = new ArrayList<>();
String name;
try {
name = Paths.get(new URI(rootUri).getPath()).getFileName().toString();
} catch (Exception e) {
name = "";
}
WorkspaceFolder folder = new WorkspaceFolder();
folder.setName(name);
folder.setUri(rootUri);
singleRootFolder.add(folder);
this.getWorkspaceService().setWorkspaceFolders(singleRootFolder);
}
}
this.hasCompletionSnippetSupport = safeGet(false, () -> params.getCapabilities().getTextDocument().getCompletion().getCompletionItem().getSnippetSupport());
this.hasExecuteCommandSupport = safeGet(false, () -> params.getCapabilities().getWorkspace().getExecuteCommand() != null);
this.hasFileWatcherRegistrationSupport = safeGet(false, () -> params.getCapabilities().getWorkspace().getDidChangeWatchedFiles().getDynamicRegistration());
Log.debug("workspaceRoots = " + getWorkspaceService().getWorkspaceRoots());
Log.debug("hasCompletionSnippetSupport = " + hasCompletionSnippetSupport);
Log.debug("hasExecuteCommandSupport = " + hasExecuteCommandSupport);
InitializeResult result = new InitializeResult();
if (hasExecuteCommandSupport) {
getWorkspaceService().onExecuteCommand(this::executeCommand);
}
ServerCapabilities cap = getServerCapabilities();
result.setCapabilities(cap);
Consumer<InitializeParams> ih = this.initializeHandler;
if (ih != null) {
ih.accept(params);
}
return CompletableFuture.completedFuture(result);
}
use of org.eclipse.lsp4j.InitializeParams in project eclipse.jdt.ls by eclipse.
the class InitHandlerTest method testConfigureJVMs.
@Test
public void testConfigureJVMs() throws Exception {
InitHandler handler = new InitHandler(projectsManager, preferenceManager, server.getClientConnection(), commandHandler);
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(IConstants.PLUGIN_ID);
boolean isWorkspaceInitialized = isWorkspaceInitialized(prefs);
boolean[] changed = new boolean[] { false };
IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
IVMInstallChangedListener listener = new IVMInstallChangedListener() {
@Override
public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
changed[0] = true;
}
@Override
public void vmChanged(PropertyChangeEvent event) {
}
@Override
public void vmAdded(IVMInstall vm) {
}
@Override
public void vmRemoved(IVMInstall vm) {
}
};
try {
prefs.putBoolean(IConstants.WORKSPACE_INITIALIZED, false);
InitializeParams params = new InitializeParams();
Map<String, Object> initializationOptions = new HashMap<>();
String javaHome = new File(TestVMType.getFakeJDKsLocation(), "9").getAbsolutePath();
HashMap<String, Object> homeMap = getMap("home", javaHome);
Map<String, Object> javaMap = getMap("java", homeMap);
initializationOptions.put(InitHandler.SETTINGS_KEY, javaMap);
params.setInitializationOptions(initializationOptions);
assertFalse(isWorkspaceInitialized(prefs));
JavaRuntime.addVMInstallChangedListener(listener);
handler.handleInitializationOptions(params);
assertTrue(isWorkspaceInitialized(prefs));
assertTrue(changed[0]);
changed[0] = false;
handler.handleInitializationOptions(params);
assertFalse(changed[0]);
} finally {
prefs.putBoolean(IConstants.WORKSPACE_INITIALIZED, isWorkspaceInitialized);
JavaRuntime.removeVMInstallChangedListener(listener);
JavaRuntime.setDefaultVMInstall(defaultVM, new NullProgressMonitor());
}
}
use of org.eclipse.lsp4j.InitializeParams in project eclipse.jdt.ls by eclipse.
the class InitHandlerTest method initialize.
private InitializeResult initialize(boolean dynamicRegistration) throws InterruptedException, ExecutionException {
InitializeParams params = new InitializeParams();
ClientCapabilities capabilities = new ClientCapabilities();
WorkspaceClientCapabilities workspaceCapabilities = new WorkspaceClientCapabilities();
workspaceCapabilities.setDidChangeConfiguration(new DidChangeConfigurationCapabilities(dynamicRegistration));
ExecuteCommandCapabilities executeCommand = new ExecuteCommandCapabilities(dynamicRegistration);
workspaceCapabilities.setExecuteCommand(executeCommand);
capabilities.setWorkspace(workspaceCapabilities);
TextDocumentClientCapabilities textDocument = new TextDocumentClientCapabilities();
SynchronizationCapabilities synchronizationCapabilities = new SynchronizationCapabilities();
synchronizationCapabilities.setWillSave(Boolean.TRUE);
synchronizationCapabilities.setWillSaveWaitUntil(Boolean.TRUE);
capabilities.setTextDocument(textDocument);
params.setCapabilities(capabilities);
CompletableFuture<InitializeResult> result = server.initialize(params);
return result.get();
}
Aggregations