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_change.
@Test
public void cu_cache_invalidated_by_doc_change() 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.changeDocument(doc.getUri(), 0, 0, " ");
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 SpringIndexerHarness method getSymbolsInFile.
public List<TestSymbolInfo> getSymbolsInFile(String docURI) throws Exception {
List<? extends SymbolInformation> symbols = indexer.getSymbols(docURI);
if (symbols != null) {
symbols = new ArrayList<>(symbols);
Collections.sort(symbols, SYMBOL_COMPARATOR);
TextDocument doc = new TextDocument(docURI, LanguageId.JAVA, 1, IOUtils.toString(new URI(docURI)));
ImmutableList.Builder<TestSymbolInfo> symbolInfos = ImmutableList.builder();
for (SymbolInformation s : symbols) {
int start = doc.toOffset(s.getLocation().getRange().getStart());
int end = doc.toOffset(s.getLocation().getRange().getEnd());
symbolInfos.add(new TestSymbolInfo(doc.textBetween(start, end), s.getName()));
}
return symbolInfos.build();
}
return ImmutableList.of();
}
use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.
the class SpringPropertiesIndexTest method testPropertiesIndexRefreshOnProjectChange.
@Test
public void testPropertiesIndexRefreshOnProjectChange() throws Exception {
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/boot-1.2.0-properties-live-metadta/").toURI()));
propertyIndexProvider = (DefaultSpringPropertyIndexProvider) harness.getServerWrapper().getComponents().get(BootPropertiesLanguageServerComponents.class).getPropertiesIndexProvider();
File directory = new File(ProjectsHarness.class.getResource("/test-projects/boot-1.2.0-properties-live-metadta/").toURI());
File javaFile = new File(directory, "/src/main/java/demo/Application.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 RequestMappingSymbolProvider method getSymbols.
@Override
public Collection<EnhancedSymbolInformation> getSymbols(Annotation node, ITypeBinding annotationType, Collection<ITypeBinding> metaAnnotations, TextDocument doc) {
if (node.getParent() instanceof MethodDeclaration) {
try {
Location location = new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength()));
String[] path = getPath(node);
String[] parentPath = getParentPath(node);
String[] methods = getMethod(node);
String[] contentTypes = getContentTypes(node);
String[] acceptTypes = getAcceptTypes(node);
return (parentPath == null ? Stream.of("") : Arrays.stream(parentPath)).filter(Objects::nonNull).flatMap(parent -> (path == null ? Stream.<String>empty() : Arrays.stream(path)).filter(Objects::nonNull).map(p -> {
String separator = !parent.endsWith("/") && !p.startsWith("/") ? "/" : "";
String resultPath = parent + separator + p;
if (resultPath.endsWith("/")) {
resultPath = resultPath.substring(0, resultPath.length() - 1);
}
return resultPath.startsWith("/") ? resultPath : "/" + resultPath;
})).map(p -> RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes, null)).collect(Collectors.toList());
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.
the class BootJavaDocumentHighlightEngine method handle.
@Override
public List<DocumentHighlight> handle(TextDocumentPositionParams params) {
SimpleTextDocumentService documents = server.getTextDocumentService();
String docURI = params.getTextDocument().getUri();
if (documents.get(docURI) != null) {
TextDocument doc = documents.get(docURI).copy();
try {
return provideDocumentHighlights(doc, params.getPosition());
} catch (Exception e) {
log.error("", e);
}
}
return SimpleTextDocumentService.NO_HIGHLIGHTS;
}
Aggregations