Search in sources :

Example 21 with TextDocument

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);
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath) Test(org.junit.Test)

Example 22 with TextDocument

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());
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ProjectsHarness(org.springframework.ide.vscode.project.harness.ProjectsHarness) ProgressService(org.springframework.ide.vscode.commons.languageserver.ProgressService) File(java.io.File) Test(org.junit.Test)

Example 23 with TextDocument

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;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) Renderable(org.springframework.ide.vscode.commons.util.Renderable) Hover(org.eclipse.lsp4j.Hover) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService) Range(org.eclipse.lsp4j.Range) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Example 24 with TextDocument

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);
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath) Test(org.junit.Test)

Example 25 with TextDocument

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);
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) Test(org.junit.Test)

Aggregations

TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)43 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)12 URI (java.net.URI)11 File (java.io.File)10 Location (org.eclipse.lsp4j.Location)8 Test (org.junit.Test)8 Path (java.nio.file.Path)7 ArrayList (java.util.ArrayList)7 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)7 IClasspath (org.springframework.ide.vscode.commons.java.IClasspath)7 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 Range (org.eclipse.lsp4j.Range)6 Collection (java.util.Collection)5 Map (java.util.Map)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 Stream (java.util.stream.Stream)5 ASTParser (org.eclipse.jdt.core.dom.ASTParser)5 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)5