Hi, I am trying to get the path for an iteration of a syntaxTree in CodeMirror v6. I have this code:
syntaxTree(view.state)
.cursor()
.iterate((node) => {
console.log(view.state.doc.sliceString(node.from, node.to));
});
which loops through a syntax tree and outputs the JSON attributes. However, this doesn’t give the path to the node. Outputting node.name
gives values like JsonText
, PropertyName
, Object
, Property
, and not a JSON path.
I am trying to output the path of the current node
. So if I had JSON like {"names": ["example"]}
on an iteration that outputs "example"
I would get names[0]
. Is there a way to do this?