Search in sources :

Example 1 with DidChangeWatchedFilesParams

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);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) FileEvent(org.eclipse.lsp4j.FileEvent) FileSystemWatcher(org.eclipse.jdt.ls.core.internal.FileSystemWatcher) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) IJavaProject(org.eclipse.jdt.core.IJavaProject) File(java.io.File) IProject(org.eclipse.core.resources.IProject) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 2 with DidChangeWatchedFilesParams

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);
    }
}
Also used : DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams)

Example 3 with DidChangeWatchedFilesParams

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)));
}
Also used : FileEvent(org.eclipse.lsp4j.FileEvent) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams)

Example 4 with DidChangeWatchedFilesParams

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)));
}
Also used : FileEvent(org.eclipse.lsp4j.FileEvent) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams)

Example 5 with DidChangeWatchedFilesParams

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());
}
Also used : FileEvent(org.eclipse.lsp4j.FileEvent) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) Test(org.junit.Test)

Aggregations

DidChangeWatchedFilesParams (org.eclipse.lsp4j.DidChangeWatchedFilesParams)11 FileEvent (org.eclipse.lsp4j.FileEvent)10 Test (org.junit.Test)6 File (java.io.File)1 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 FileSystemWatcher (org.eclipse.jdt.ls.core.internal.FileSystemWatcher)1 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)1 ClientPreferences (org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1