use of org.eclipse.lsp4j.DidChangeWatchedFilesParams in project eclipse.jdt.ls by eclipse.
the class InitHandlerTest method testWatchers.
@Test
public void testWatchers() throws Exception {
ClientPreferences mockCapabilies = mock(ClientPreferences.class);
when(mockCapabilies.isWorkspaceChangeWatchedFilesDynamicRegistered()).thenReturn(Boolean.TRUE);
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
importProjects(Arrays.asList("maven/salut", "gradle/simple-gradle"));
newEmptyProject();
List<FileSystemWatcher> watchers = projectsManager.registerWatchers();
Collections.sort(watchers, new Comparator<FileSystemWatcher>() {
@Override
public int compare(FileSystemWatcher o1, FileSystemWatcher o2) {
return o1.getGlobPattern().compareTo(o2.getGlobPattern());
}
});
assertEquals(watchers.size(), 5);
assertEquals(watchers.get(0).getGlobPattern(), ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + "/TestProject/src/**");
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("simple-gradle");
String location = project.getLocation().toString();
assertEquals(watchers.get(1).getGlobPattern(), location + "/src/main/java/**");
assertEquals(watchers.get(2).getGlobPattern(), location + "/src/test/java/**");
project = ResourcesPlugin.getWorkspace().getRoot().getProject("salut");
location = project.getLocation().toString();
assertEquals(watchers.get(3).getGlobPattern(), location + "/src/main/java/**");
assertEquals(watchers.get(4).getGlobPattern(), location + "/src/main/resources/**");
IJavaProject javaProject = JavaCore.create(project);
// for test purposes only
removeExclusionPattern(javaProject);
File outputDir = new File(new File(location), javaProject.getOutputLocation().removeFirstSegments(1).toOSString());
File outputFile = new File(outputDir, "test.properties");
String resourceName = location + "/src/main/resources/test.properties";
String uri = "file://" + resourceName;
File sourceFile = new Path(resourceName).toFile();
assertTrue(FileUtils.contentEquals(sourceFile, outputFile));
FileUtils.writeStringToFile(sourceFile, TEST_CONTENT);
FileEvent fileEvent = new FileEvent(uri, FileChangeType.Changed);
DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams();
params.getChanges().add(fileEvent);
server.didChangeWatchedFiles(params);
JobHelpers.waitForJobsToComplete();
assertTrue(FileUtils.contentEquals(sourceFile, outputFile));
verify(client, times(1)).registerCapability(any());
List<FileSystemWatcher> newWatchers = projectsManager.registerWatchers();
verify(client, times(1)).registerCapability(any());
Collections.sort(newWatchers, new Comparator<FileSystemWatcher>() {
@Override
public int compare(FileSystemWatcher o1, FileSystemWatcher o2) {
return o1.getGlobPattern().compareTo(o2.getGlobPattern());
}
});
assertEquals(newWatchers, watchers);
}
use of org.eclipse.lsp4j.DidChangeWatchedFilesParams in project sts4 by spring-projects.
the class ResourceListener method sendFileEvents.
private void sendFileEvents(List<FileEvent> fileEvents) {
if (!fileEvents.isEmpty()) {
DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(fileEvents);
server.getWorkspaceService().didChangeWatchedFiles(params);
}
}
use of org.eclipse.lsp4j.DidChangeWatchedFilesParams in project sts4 by spring-projects.
the class LanguageServerHarness method createFile.
public synchronized void createFile(String uri) {
FileEvent fileEvent = new FileEvent(uri, FileChangeType.Created);
getServer().getWorkspaceService().didChangeWatchedFiles(new DidChangeWatchedFilesParams(Arrays.asList(fileEvent)));
}
use of org.eclipse.lsp4j.DidChangeWatchedFilesParams in project sts4 by spring-projects.
the class LanguageServerHarness method deleteFile.
public synchronized void deleteFile(String uri) {
FileEvent fileEvent = new FileEvent(uri, FileChangeType.Deleted);
getServer().getWorkspaceService().didChangeWatchedFiles(new DidChangeWatchedFilesParams(Arrays.asList(fileEvent)));
}
use of org.eclipse.lsp4j.DidChangeWatchedFilesParams in project xtext-core by eclipse.
the class OpenDocumentTest method testOpenedDocumentShadowsPersistedFile.
@Test
public void testOpenedDocumentShadowsPersistedFile() {
String model = "type Test {\n" + " NonExisting foo\n" + "}";
String firstFile = writeFile("MyType1.testlang", model);
initialize();
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", Iterables.getFirst(getDiagnostics().get(firstFile), null).getMessage());
String path = writeFile("MyType2.testlang", "\n type Foo {\n }\n ");
languageServer.getWorkspaceService().didChangeWatchedFiles(new DidChangeWatchedFilesParams(Lists.newArrayList(new FileEvent(path, FileChangeType.Created))));
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", Iterables.getFirst(getDiagnostics().get(firstFile), null).getMessage());
String model2 = "type NonExisting {}";
open(path, model2);
Assert.assertNull(Iterables.getFirst(getDiagnostics().get(firstFile), null));
close(path);
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", Iterables.getFirst(getDiagnostics().get(firstFile), null).getMessage());
}
Aggregations