Skip to content

Commit

Permalink
Fix .ty info box
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia committed Jun 30, 2022
1 parent 14c609e commit ca00556
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
25 changes: 24 additions & 1 deletion docs/playground/json_editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ body.wide .container {
{
let prop_result = result.children[name];
this.on_property(name, name_node, prop_node, prop_result, result, path);
this.visit(prop_node.lastChild, prop_result, json[name], path.concat([name]));
if ( name == "ty" && prop_result.const )
this.on_ty_value(prop_node.lastChild, prop_result, result)
else
this.visit(prop_node.lastChild, prop_result, json[name], path.concat([name]));
}
else
{
Expand Down Expand Up @@ -457,6 +460,19 @@ body.wide .container {
return false;
}

on_ty_value(node, prop_result, object_result)
{
this.add_lint_errors(node, prop_result);
let schema = this.schema;
let deco = CodeMirrorWrapper.Decoration.mark({
class: "info_box_trigger",
info_box: () => TreeResultVisitor.ty_info_box(
editor, schema, node, prop_result, object_result
),
});
this.decorations.push(deco.range(node.from, node.to));
}

lint_error(node, severity, message)
{
let error = {
Expand Down Expand Up @@ -573,6 +589,13 @@ body.wide .container {
TreeResultVisitor.show_info_box(pos, view, box, node);
}

static ty_info_box(view, schema, node, prop_result, object_result)
{
let box = new InfoBoxContents(null, schema);
box.ty_value(object_result, prop_result, view.state.sliceDoc(node.from, node.to));
TreeResultVisitor.show_info_box(node.from, view, box, node);
}

static enum_info_box(pos, view, schema, node, result)
{
let box = new InfoBoxContents(null, schema);
Expand Down
16 changes: 16 additions & 0 deletions docs/scripts/lottie_explain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,22 @@ class InfoBoxContents
this.add("", validation.const.description);
}


ty_value(object_validation, prop_validation, value_string)
{
this.result_title(prop_validation.key);

this.type_line(prop_validation, false);

this.add("br");
this.add("code", value_string);
this.add(null, " = ");
this.result_links_to_element(object_validation, this.add("span"));

this.add("br");
this.add("", object_validation.description);
}

property(validation, prop_validation)
{
this.result_title(validation);
Expand Down

0 comments on commit ca00556

Please sign in to comment.