How to create AST from Jsonnet files in Javascript

135 views
Skip to first unread message

Emre Kabakci

unread,
Mar 4, 2020, 12:04:46 PM3/4/20
to Jsonnet
We're working on a web editor that allows people to write Jsonnet and compile them in the browser. The Monaco Editor (also used by VSCode) makes use of Web workers so even though the compiler is slow, it's not a big deal for us.

1. In case the compilation fails, we parse the result and highlight the errors in the editor.

2. We use JSON Schema in order to validate the output JSON and we're planning to provide better IDE support such as hover and autocomplete actions in the future.

We got 1 working in our POC and make the JSON Schema work with the output of the Jsonnet files but we need to find a way to parse the Jsonnet files in JS work with the AST for the following features:

1. In case JSON Schema fails to validate the file, we have the JSONPath for the errors and we want to highlight the errors in the source Jsonnet file. If we can create the AST from the Jsonnet file, we can try to find the location for the JSONPath using our best effort. It may not work if the file is created dynamically but it should work if the fields are hardcoded. In our case, it covers most of the cases. If it can't we can just walk the AST and stop when we can't identify the children nodes.

2. We also need to find a way to generate JSONPath from the cursor location of the source Jsonnet file for hover and autocomplete support. Again, it may not be possible in all the cases but hardcoded keys would be enough for our case.

We're currently working on this implementation: https://github.com/heptio/vscode-jsonnet/tree/master/compiler. However; the codebase is old and it does not support all the syntax so we have a hard time making the JSONPaths work. Any ideas?

Paul Rudin

unread,
Mar 5, 2020, 2:02:18 AM3/5/20
to Emre Kabakci, Jsonnet
I noticed that someone was asking for this on Upwork.

--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/b08c2148-0129-4f11-be55-52897cc5b20b%40googlegroups.com.

Emre Kabakci

unread,
Mar 5, 2020, 2:03:34 AM3/5/20
to pa...@rudin.co.uk, Jsonnet
Hey Paul, it’s us. :)
Reply all
Reply to author
Forward
0 new messages