use of org.eclipse.lsp4j.WorkspaceFolder 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.WorkspaceFolder in project sts4 by spring-projects.
the class SimpleWorkspaceService method didChangeWorkspaceFolders.
@Override
public synchronized void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) {
WorkspaceFoldersChangeEvent evt = params.getEvent();
boolean changed = false;
for (WorkspaceFolder r : evt.getAdded()) {
workspaceRoots.add(r);
changed = true;
}
for (WorkspaceFolder r : evt.getRemoved()) {
workspaceRoots.remove(r);
changed = true;
}
if (changed) {
workspaceFolderListeners.fire(params);
}
}
Aggregations