Search in sources :

Example 1 with Renderable

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

the class PropertiesHoverCalculator method getPropertyHover.

private Tuple2<Renderable, IRegion> getPropertyHover(Key property) {
    PropertyInfo best = findBestHoverMatch(property.decode());
    if (best == null) {
        return null;
    } else {
        Renderable renderable = InformationTemplates.createHover(best);
        DocumentRegion region = createRegion(doc, property);
        return Tuples.of(renderable, region.asRegion());
    }
}
Also used : Renderable(org.springframework.ide.vscode.commons.util.Renderable) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo)

Example 2 with Renderable

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

the class InformationTemplates method createHover.

public static Renderable createHover(PropertyInfo info) {
    Deprecation deprecation = createDeprecation(info);
    Renderable description = info.getDescription() == null ? null : text(info.getDescription());
    return InformationTemplates.createHover(info.getId(), info.getType(), info.getDefaultValue(), description, deprecation);
}
Also used : Renderable(org.springframework.ide.vscode.commons.util.Renderable) Deprecation(org.springframework.ide.vscode.boot.configurationmetadata.Deprecation)

Example 3 with Renderable

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

the class InformationTemplates method createCompletionDocumentation.

public static Renderable createCompletionDocumentation(PropertyInfo info) {
    Deprecation deprecation = createDeprecation(info);
    Renderable description = info.getDescription() == null ? null : text(info.getDescription());
    return InformationTemplates.createCompletionDocumentation(description, info.getDefaultValue(), deprecation);
}
Also used : Renderable(org.springframework.ide.vscode.commons.util.Renderable) Deprecation(org.springframework.ide.vscode.boot.configurationmetadata.Deprecation)

Example 4 with Renderable

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

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

the class PropertiesHoverCalculator method getValueHover.

private Tuple2<Renderable, IRegion> getValueHover(Value value) {
    DocumentRegion valueRegion = createRegion(doc, value).trimStart(SPACES).trimEnd(SPACES);
    if (valueRegion.getStart() <= offset && offset < valueRegion.getEnd()) {
        String valueString = valueRegion.toString();
        String propertyName = value.getParent().getKey().decode();
        Type type = getValueType(index, typeUtil, propertyName);
        if (TypeUtil.isSequencable(type)) {
            // It is useful to provide content assist for the values in the list when entering a list
            type = TypeUtil.getDomainType(type);
        }
        if (TypeUtil.isClass(type)) {
            // Special case. We want to provide hoverinfos more liberally than what's suggested for completions (i.e. even class names
            // that are not suggested by the hints because they do not meet subtyping constraints should be hoverable and linkable!
            StsValueHint hint = StsValueHint.className(valueString, typeUtil);
            if (hint != null) {
                return Tuples.of(createRenderable(hint), valueRegion.asRegion());
            }
        }
        // Hack: pretend to invoke content-assist at the end of the value text. This should provide hints applicable to that value
        // then show hoverinfo based on that. That way we can avoid duplication a lot of similar logic to compute hoverinfos and hyperlinks.
        Collection<StsValueHint> hints = getValueHints(index, typeUtil, valueString, propertyName, EnumCaseMode.ALIASED);
        if (hints != null) {
            Optional<StsValueHint> hint = hints.stream().filter(h -> valueString.equals(h.getValue())).findFirst();
            if (hint.isPresent()) {
                return Tuples.of(createRenderable(hint.get()), valueRegion.asRegion());
            }
        }
    }
    return null;
}
Also used : CommonLanguageTools.getValueType(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType) IDocument(org.springframework.ide.vscode.commons.util.text.IDocument) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) SpringPropertyIndex(org.springframework.ide.vscode.boot.metadata.SpringPropertyIndex) Tuples(reactor.util.function.Tuples) Type(org.springframework.ide.vscode.boot.metadata.types.Type) Tuple2(reactor.util.function.Tuple2) AntlrParser(org.springframework.ide.vscode.java.properties.antlr.parser.AntlrParser) ImmutableList(com.google.common.collect.ImmutableList) FuzzyMap(org.springframework.ide.vscode.commons.util.FuzzyMap) Renderables.paragraph(org.springframework.ide.vscode.commons.util.Renderables.paragraph) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) EnumCaseMode(org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode) Collection(java.util.Collection) SPACES(org.springframework.ide.vscode.boot.common.CommonLanguageTools.SPACES) Renderables.concat(org.springframework.ide.vscode.commons.util.Renderables.concat) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Renderables.bold(org.springframework.ide.vscode.commons.util.Renderables.bold) Renderables.text(org.springframework.ide.vscode.commons.util.Renderables.text) Key(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Key) InformationTemplates(org.springframework.ide.vscode.boot.common.InformationTemplates) Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) CommonLanguageTools.getValueHints(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueHints) Value(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value) Optional(java.util.Optional) Renderable(org.springframework.ide.vscode.commons.util.Renderable) TypeUtil(org.springframework.ide.vscode.boot.metadata.types.TypeUtil) Builder(com.google.common.collect.ImmutableList.Builder) CommonLanguageTools.getValueType(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType) Type(org.springframework.ide.vscode.boot.metadata.types.Type) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion)

Aggregations

Renderable (org.springframework.ide.vscode.commons.util.Renderable)9 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)3 IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)3 ImmutableList (com.google.common.collect.ImmutableList)2 Collection (java.util.Collection)2 Hover (org.eclipse.lsp4j.Hover)2 Range (org.eclipse.lsp4j.Range)2 Deprecation (org.springframework.ide.vscode.boot.configurationmetadata.Deprecation)2 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)2 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)2 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)2 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)2 Tuple2 (reactor.util.function.Tuple2)2 Tuples (reactor.util.function.Tuples)2 Builder (com.google.common.collect.ImmutableList.Builder)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1