Search in sources :

Example 1 with SimpleTextDocumentService

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

the class BootJavaCodeLensEngine method handle.

@Override
public List<? extends CodeLens> handle(CodeLensParams params) {
    SimpleTextDocumentService documents = server.getTextDocumentService();
    String docURI = params.getTextDocument().getUri();
    if (documents.get(docURI) != null) {
        TextDocument doc = documents.get(docURI).copy();
        try {
            List<? extends CodeLens> codeLensesResult = provideCodeLenses(doc);
            if (codeLensesResult != null) {
                return codeLensesResult;
            }
        } catch (Exception e) {
        }
    }
    return SimpleTextDocumentService.NO_CODELENS;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService)

Example 2 with SimpleTextDocumentService

use of org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService 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 3 with SimpleTextDocumentService

use of org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService 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;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService)

Example 4 with SimpleTextDocumentService

use of org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService 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 5 with SimpleTextDocumentService

use of org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService 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)

Aggregations

SimpleTextDocumentService (org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService)5 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)5 Hover (org.eclipse.lsp4j.Hover)2 Range (org.eclipse.lsp4j.Range)1 Renderable (org.springframework.ide.vscode.commons.util.Renderable)1 IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)1