Search in sources :

Example 31 with TextDocument

use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.

the class BootJavaHoverProvider method handle.

@Override
public Hover handle(TextDocumentPositionParams params) {
    SimpleTextDocumentService documents = server.getTextDocumentService();
    if (documents.get(params) != null) {
        TextDocument doc = documents.get(params).copy();
        try {
            int offset = doc.toOffset(params.getPosition());
            Hover hoverResult = provideHover(doc, offset);
            if (hoverResult != null) {
                return hoverResult;
            }
        } catch (Exception e) {
        }
    }
    return SimpleTextDocumentService.NO_HOVER;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) Hover(org.eclipse.lsp4j.Hover) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService)

Example 32 with TextDocument

use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.

the class BootJavaReferencesHandler method handle.

@Override
public List<? extends Location> handle(ReferenceParams params) {
    SimpleTextDocumentService documents = server.getTextDocumentService();
    TextDocument doc = documents.get(params).copy();
    if (doc != null) {
        try {
            int offset = doc.toOffset(params.getPosition());
            List<? extends Location> referencesResult = provideReferences(doc, offset);
            if (referencesResult != null) {
                return referencesResult;
            }
        } catch (Exception e) {
        }
    }
    return SimpleTextDocumentService.NO_REFERENCES;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService)

Example 33 with TextDocument

use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.

the class SpringIndexer method getTempTextDocument.

private TextDocument getTempTextDocument(String docURI, AtomicReference<TextDocument> docRef, String content) throws Exception {
    TextDocument doc = docRef.get();
    if (doc == null) {
        doc = createTempTextDocument(docURI, content);
        docRef.set(doc);
    }
    return doc;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument)

Example 34 with TextDocument

use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.

the class SpringIndexer method scanFiles.

private void scanFiles(ASTParser parser, String[] javaFiles, String[] classpathEntries) throws Exception {
    Map<String, String> options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_10, options);
    parser.setCompilerOptions(options);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setStatementsRecovery(true);
    parser.setBindingsRecovery(true);
    parser.setResolveBindings(true);
    parser.setIgnoreMethodBodies(false);
    String[] sourceEntries = new String[] {};
    parser.setEnvironment(classpathEntries, sourceEntries, null, true);
    FileASTRequestor requestor = new FileASTRequestor() {

        @Override
        public void acceptAST(String sourceFilePath, CompilationUnit cu) {
            String docURI = UriUtil.toUri(new File(sourceFilePath)).toString();
            AtomicReference<TextDocument> docRef = new AtomicReference<>();
            scanAST(cu, docURI, docRef, null);
        }
    };
    parser.createASTs(javaFiles, null, new String[0], requestor, null);
}
Also used : FileASTRequestor(org.eclipse.jdt.core.dom.FileASTRequestor) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) AtomicReference(java.util.concurrent.atomic.AtomicReference) File(java.io.File)

Example 35 with TextDocument

use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.

the class SpringIndexer method createTempTextDocument.

private TextDocument createTempTextDocument(String docURI, String content) throws Exception {
    if (content == null) {
        Path path = Paths.get(new URI(docURI));
        content = new String(Files.readAllBytes(path));
    }
    TextDocument doc = new TextDocument(docURI, LanguageId.PLAINTEXT, 0, content);
    return doc;
}
Also used : Path(java.nio.file.Path) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) URI(java.net.URI)

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