[STAL-1960] Add bridge for (TsSymbol <> Name) mappings #387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem are you trying to solve?
One of the fundamental design constraints for ddsa was to represent everything that needed to be passed between Rust and JavaScript with a v8 "smi" (a
uint31
on 64 bit platforms). At the same time, we want ergonomic APIs that aren't constrained by performance optimizations like this.Each tree-sitter CST node (that we care about) has a string name (that it internally calls a
TSSymbol
) to represent its type:The node type names for the nodes in this expression are:
We want users to be able to author JavaScript rules that can filter nodes by a string name, like
"identifier"
. We also want to be able to let JavaScript rules request nodes of a given type as well.In pseudo-code:
What is your solution?
In the above example (
const nodes = ddsa.getChildren(node, "variable_declarator");
), this is a function that will make a call to Rust to request additional tree-sitter nodes. Under the hood, we want to be able to translate this to something like:To achieve this, we create and pre-calculate a v8 map with data for each tree-sitter Language. For example, in JavaScript pseudo-code, this would be like:
With this map, we can always internally represent the type as a numeric id, but use string names in the user-facing JavaScript API.
This map will be exposed on the JavaScript
globalThis
on a per-language basis so thatddsa
will have access to this map.Alternatives considered
What the reviewer should know