use of org.eclipse.lsp4j.WorkspaceFolder in project sts4 by spring-projects.
the class PropertyReferenceFinderTest method wsFolder.
private Collection<WorkspaceFolder> wsFolder(Path directory) {
if (directory != null) {
WorkspaceFolder folder = new WorkspaceFolder();
folder.setName(directory.getFileName().toString());
folder.setUri(directory.toUri().toString());
return ImmutableList.of(folder);
}
return ImmutableList.of();
}
use of org.eclipse.lsp4j.WorkspaceFolder in project sts4 by spring-projects.
the class SimpleLanguageServer method getWorkspaceFolders.
private List<WorkspaceFolder> getWorkspaceFolders(InitializeParams params) {
List<WorkspaceFolder> initialFolders = new ArrayList<>();
Object initOptions = params.getInitializationOptions();
if (initOptions != null && initOptions instanceof JsonObject) {
JsonObject initializationOptions = (JsonObject) initOptions;
JsonElement folders = initializationOptions.get("workspaceFolders");
if (folders != null && folders instanceof JsonArray) {
JsonArray workspaceFolders = (JsonArray) folders;
for (JsonElement object : workspaceFolders) {
String folderUri = object.getAsString();
String folderName = null;
int folderNameStart = folderUri.lastIndexOf("/");
if (folderNameStart > 0) {
folderName = folderUri.substring(folderUri.lastIndexOf("/") + 1);
}
WorkspaceFolder folder = new WorkspaceFolder();
folder.setName(folderName);
folder.setUri(folderUri);
initialFolders.add(folder);
}
}
}
return initialFolders;
}
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);
}
}
use of org.eclipse.lsp4j.WorkspaceFolder in project eclipse.jdt.ls by eclipse.
the class WorkspaceFolderChangeHandlerTest method testUpdateWorkspaceFolder.
@Test
public void testUpdateWorkspaceFolder() throws Exception {
File rootFolder = copyFiles("maven/salut", true);
String rootFolderUri = rootFolder.toURI().toString();
IPath rootFolderPath = ResourceUtils.canonicalFilePathFromURI(rootFolderUri);
WorkspaceFolder workspaceFolder = new WorkspaceFolder(rootFolder.toURI().toString());
WorkspaceFoldersChangeEvent event = new WorkspaceFoldersChangeEvent(Arrays.asList(workspaceFolder), Collections.emptyList());
DidChangeWorkspaceFoldersParams params = new DidChangeWorkspaceFoldersParams(event);
workspaceFolderChangeHander.update(params);
assertTrue(preferenceManager.getPreferences().getRootPaths().contains(rootFolderPath));
waitForBackgroundJobs();
event = new WorkspaceFoldersChangeEvent(Collections.emptyList(), Arrays.asList(workspaceFolder));
params = new DidChangeWorkspaceFoldersParams(event);
workspaceFolderChangeHander.update(params);
assertFalse(preferenceManager.getPreferences().getRootPaths().contains(rootFolderPath));
}
Aggregations