-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NAPI Serialization for Nodes #466
Comments
This might be a handy resource for the debugger visualisation: microsoft/vscode#26234 |
github-merge-queue bot
pushed a commit
that referenced
this issue
Apr 11, 2024
Closes #466 ## JSON serialization Adds the `toJSON` method to the RuleNode/TokenNode classes with the comment stating that it's unstable and for debugging purposes only. I explicitly didn't type it (it's a string) as I didn't want to publicly encode any assumptions about the shape of the data. We can discuss further what we want to explore as part of having pure data external interface (JSON) for Slang, whether that's exporting or importing JSON, but I'd consider this a separate issue as it requires more thought and design; the original issue, from what I understand, was primarily about improving the debugging/inspection experience. ## Debugger Adds hidden getter properties that is only eagerly evaluated by debugger; since it's a getter function, it shouldn't add overhead to the runtime but I have to admit, I didn't double-check that with numbers. It adds both `__children` and `__text`, allowing to quickly explore the tree structure recursively and also the enclosing text scope of the node: ### vscode-js-debug (built-in to VS Code) ![image](https://github.com/NomicFoundation/slang/assets/3093213/193702fa-02b6-4853-9dcd-8af58469cf23) ### Chrome DevTools for Node ![image](https://github.com/NomicFoundation/slang/assets/3093213/a7b81836-ad7e-495c-aded-ebcc48f3bb6b)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First reported by @antico5
On Rust, our types do have
[serde]
attributes for serialization. But on TS side, the types are properties that cannot beJSON.stringify()
ied or visualized easily. One workaround is to do:Which produces something like:
But that is not enough. To make it easier for developers to use this, we can do two things:
One: JSON serialization
[serde]
JSON serialization/deserialization through TypeScript APIs on each node. Example:node.toJSON() -> string
Node.fromJSON(string) -> Node
Two: Debugger Visualization
They also reported having to implement their own serialization just to visualize the tree. Example:
However, instead of leaving it up to users, we can also provide such API, especially that we already have an internal one for unit tests snapshots:
slang/crates/solidity/testing/snapshots/cst_output/MappingType/named_value/generated/0.8.18.yml
Lines 9 to 21 in 52b7ed2
We can probably expose this for both Rust and TypeScript, as a public API, with explicitly warning users that this is for dev-time visualization only, and its structure is subject to change at any time.
An additional benefit to this is that TypeScript will be able to generate the same visualization as Rust, unblocking #439
The text was updated successfully, but these errors were encountered: