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());
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations