use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.
the class CompilationUnitCacheTest method cu_cache_invalidated_by_doc_close.
@Test
public void cu_cache_invalidated_by_doc_close() throws Exception {
harness = BootJavaLanguageServerHarness.builder().mockDefaults().build();
harness.useProject(new IJavaProject() {
@Override
public IClasspath getClasspath() {
return new DelegatingCachedClasspath<>(() -> null, null);
}
});
harness.intialize(null);
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" + "\n" + "public class SomeClass {\n" + "\n" + "}\n");
harness.newEditorFromFileUri(doc.getUri(), doc.getLanguageId());
CompilationUnit cu = getCompilationUnit(doc);
assertNotNull(cu);
harness.closeDocument(doc.getId());
CompilationUnit cuAnother = getCompilationUnit(doc);
assertNotNull(cuAnother);
assertFalse(cu == cuAnother);
CompilationUnit cuYetAnother = getCompilationUnit(doc);
assertTrue(cuAnother == cuYetAnother);
}
use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.
the class SpringPropertyIndexTest method testPropertiesIndexRefreshOnProjectChange.
@Test
public void testPropertiesIndexRefreshOnProjectChange() throws Exception {
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI()));
propertyIndexProvider = (DefaultSpringPropertyIndexProvider) harness.getServerWrapper().getComponents().getSpringPropertyIndexProvider();
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI());
File javaFile = new File(directory, "/src/main/java/org/test/SimpleMappingClass.java");
TextDocument doc = new TextDocument(javaFile.toURI().toString(), LanguageId.JAVA);
// Not cached yet, hence progress service invoked
ProgressService progressService = mock(ProgressService.class);
propertyIndexProvider.setProgressService(progressService);
propertyIndexProvider.getIndex(doc);
verify(progressService, atLeastOnce()).progressEvent(anyObject(), anyObject());
// Should be cached now, so progress service should not be touched
progressService = mock(ProgressService.class);
propertyIndexProvider.setProgressService(progressService);
propertyIndexProvider.getIndex(doc);
verify(progressService, never()).progressEvent(anyObject(), anyObject());
// Change POM file for the project
harness.changeFile(new File(directory, MavenCore.POM_XML).toURI().toString());
// POM has changed, hence project needs to be reloaded, cached value is cleared
progressService = mock(ProgressService.class);
propertyIndexProvider.setProgressService(progressService);
propertyIndexProvider.getIndex(doc);
verify(progressService, atLeastOnce()).progressEvent(anyObject(), anyObject());
}
use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.
the class VscodeHoverEngineAdapter method handle.
@Override
public Hover handle(TextDocumentPositionParams params) {
// a trivial pre-resolved future.
try {
SimpleTextDocumentService documents = server.getTextDocumentService();
TextDocument doc = documents.get(params);
if (doc != null) {
int offset = doc.toOffset(params.getPosition());
Tuple2<Renderable, IRegion> hoverTuple = hoverInfoProvider.getHoverInfo(doc, offset);
if (hoverTuple != null) {
Renderable hoverInfo = hoverTuple.getT1();
IRegion region = hoverTuple.getT2();
Range range = doc.toRange(region.getOffset(), region.getLength());
String rendered = render(hoverInfo, type);
if (StringUtil.hasText(rendered)) {
Hover hover = new Hover(ImmutableList.of(Either.forLeft(rendered)), range);
return hover;
}
}
}
} catch (Exception e) {
logger.error("error computing hover", e);
}
return SimpleTextDocumentService.NO_HOVER;
}
use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.
the class CompilationUnitCacheTest method cu_cached.
@Test
public void cu_cached() throws Exception {
harness = BootJavaLanguageServerHarness.builder().mockDefaults().build();
harness.useProject(new IJavaProject() {
@Override
public IClasspath getClasspath() {
return new DelegatingCachedClasspath<>(() -> null, null);
}
});
harness.intialize(null);
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" + "\n" + "public class SomeClass {\n" + "\n" + "}\n");
CompilationUnit cu = getCompilationUnit(doc);
assertNotNull(cu);
CompilationUnit cuAnother = getCompilationUnit(doc);
assertTrue(cu == cuAnother);
}
use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.
the class CompilationUnitCacheTest method cu_not_generated_without_project.
@Test
public void cu_not_generated_without_project() throws Exception {
harness.intialize(null);
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" + "\n" + "public class SomeClass {\n" + "\n" + "}\n");
CompilationUnit cu = getCompilationUnit(doc);
assertNull(cu);
}
Aggregations