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());
}
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());
}
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);
}
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;
}
});
}
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());
}
Aggregations