Search in sources :

Example 1 with ClientPreferences

use of org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences in project eclipse.jdt.ls by eclipse.

the class CompletionHandlerTest method testCompletion_package.

@Test
public void testCompletion_package() throws JavaModelException {
    ClientPreferences mockCapabilies = Mockito.mock(ClientPreferences.class);
    Mockito.when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
    ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", "package o" + "public class Baz {\n" + "}\n");
    int[] loc = findCompletionLocation(unit, "package o");
    CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
    assertNotNull(list);
    List<CompletionItem> items = new ArrayList<>(list.getItems());
    assertTrue(items.size() > 1);
    items.sort((i1, i2) -> i1.getSortText().compareTo(i2.getSortText()));
    CompletionItem item = items.get(0);
    // current package should appear 1st
    assertEquals("org.sample", item.getLabel());
    CompletionItem resolvedItem = server.resolveCompletionItem(item).join();
    assertNotNull(resolvedItem);
    TextEdit te = item.getTextEdit();
    assertNotNull(te);
    assertEquals("org.sample", te.getNewText());
    assertNotNull(te.getRange());
    Range range = te.getRange();
    assertEquals(0, range.getStart().getLine());
    assertEquals(8, range.getStart().getCharacter());
    assertEquals(0, range.getEnd().getLine());
    assertEquals(15, range.getEnd().getCharacter());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompletionList(org.eclipse.lsp4j.CompletionList) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) CompletionItem(org.eclipse.lsp4j.CompletionItem) TextEdit(org.eclipse.lsp4j.TextEdit) Lsp4jAssertions.assertTextEdit(org.eclipse.jdt.ls.core.internal.Lsp4jAssertions.assertTextEdit) ArrayList(java.util.ArrayList) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Example 2 with ClientPreferences

use of org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences in project eclipse.jdt.ls by eclipse.

the class InitHandlerTest method testRegisterDelayedCapability.

@Test
public void testRegisterDelayedCapability() throws Exception {
    ClientPreferences mockCapabilies = mock(ClientPreferences.class);
    when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
    when(mockCapabilies.isDocumentSymbolDynamicRegistered()).thenReturn(Boolean.TRUE);
    when(mockCapabilies.isWorkspaceSymbolDynamicRegistered()).thenReturn(Boolean.TRUE);
    when(mockCapabilies.isDocumentSymbolDynamicRegistered()).thenReturn(Boolean.TRUE);
    when(mockCapabilies.isCodeActionDynamicRegistered()).thenReturn(Boolean.TRUE);
    when(mockCapabilies.isDefinitionDynamicRegistered()).thenReturn(Boolean.TRUE);
    when(mockCapabilies.isHoverDynamicRegistered()).thenReturn(Boolean.TRUE);
    when(mockCapabilies.isReferencesDynamicRegistered()).thenReturn(Boolean.TRUE);
    when(mockCapabilies.isDocumentHighlightDynamicRegistered()).thenReturn(Boolean.TRUE);
    InitializeResult result = initialize(true);
    assertNull(result.getCapabilities().getDocumentSymbolProvider());
    server.initialized(new InitializedParams());
    verify(client, times(7)).registerCapability(any());
}
Also used : InitializeResult(org.eclipse.lsp4j.InitializeResult) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) InitializedParams(org.eclipse.lsp4j.InitializedParams) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 3 with ClientPreferences

use of org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences 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 4 with ClientPreferences

use of org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences in project eclipse.jdt.ls by eclipse.

the class AbstractProjectsManagerBasedTest method initProjectManager.

@Before
public void initProjectManager() throws CoreException {
    clientRequests.clear();
    logListener = new SimpleLogListener();
    Platform.addLogListener(logListener);
    preferences = new Preferences();
    if (preferenceManager != null) {
        when(preferenceManager.getPreferences()).thenReturn(preferences);
        ClientPreferences clientPreferences = mock(ClientPreferences.class);
        when(clientPreferences.isProgressReportSupported()).thenReturn(true);
        when(preferenceManager.getClientPreferences()).thenReturn(clientPreferences);
    }
    projectsManager = new ProjectsManager(preferenceManager);
    ProgressReporterManager progressManager = new ProgressReporterManager(this.client, preferenceManager);
    // disable throttling to ensure we capture all events
    progressManager.setReportThrottle(0);
    Job.getJobManager().setProgressProvider(progressManager);
    monitor = progressManager.getDefaultMonitor();
    WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {

        @Override
        public IBuffer createBuffer(ICompilationUnit workingCopy) {
            ICompilationUnit original = workingCopy.getPrimary();
            IResource resource = original.getResource();
            if (resource instanceof IFile) {
                return new DocumentAdapter(workingCopy, (IFile) resource);
            }
            return DocumentAdapter.Null;
        }
    });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SimpleLogListener(org.eclipse.jdt.ls.core.internal.SimpleLogListener) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) IFile(org.eclipse.core.resources.IFile) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) ProgressReporterManager(org.eclipse.jdt.ls.core.internal.handlers.ProgressReporterManager) DocumentAdapter(org.eclipse.jdt.ls.core.internal.DocumentAdapter) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) IBuffer(org.eclipse.jdt.core.IBuffer) IResource(org.eclipse.core.resources.IResource) Before(org.junit.Before)

Example 5 with ClientPreferences

use of org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences in project eclipse.jdt.ls by eclipse.

the class InitHandlerTest method testWillSaveAndWillSaveWaitUntilCapabilities.

@Test
public void testWillSaveAndWillSaveWaitUntilCapabilities() throws Exception {
    ClientPreferences mockCapabilies = mock(ClientPreferences.class);
    when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.TRUE);
    when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
    when(mockCapabilies.isWillSaveRegistered()).thenReturn(Boolean.TRUE);
    when(mockCapabilies.isWillSaveWaitUntilRegistered()).thenReturn(Boolean.TRUE);
    InitializeResult result = initialize(true);
    Either<TextDocumentSyncKind, TextDocumentSyncOptions> o = result.getCapabilities().getTextDocumentSync();
    assertTrue(o.isRight());
    assertTrue(o.getRight().getWillSave());
    assertTrue(o.getRight().getWillSaveWaitUntil());
}
Also used : InitializeResult(org.eclipse.lsp4j.InitializeResult) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) TextDocumentSyncKind(org.eclipse.lsp4j.TextDocumentSyncKind) TextDocumentSyncOptions(org.eclipse.lsp4j.TextDocumentSyncOptions) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

ClientPreferences (org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences)9 Test (org.junit.Test)6 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)5 InitializeResult (org.eclipse.lsp4j.InitializeResult)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IBuffer (org.eclipse.jdt.core.IBuffer)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 WorkingCopyOwner (org.eclipse.jdt.core.WorkingCopyOwner)1 DocumentAdapter (org.eclipse.jdt.ls.core.internal.DocumentAdapter)1 FileSystemWatcher (org.eclipse.jdt.ls.core.internal.FileSystemWatcher)1 Lsp4jAssertions.assertTextEdit (org.eclipse.jdt.ls.core.internal.Lsp4jAssertions.assertTextEdit)1 SimpleLogListener (org.eclipse.jdt.ls.core.internal.SimpleLogListener)1 ProgressReporterManager (org.eclipse.jdt.ls.core.internal.handlers.ProgressReporterManager)1