Tree Stringification

I’m trying to stringify a Tree from my custom grammar in order to demonstrate it in a web view:

const tree = MyLanguage.parser.parse(e.state.doc.toString());

However, when stringifying it, I commonly get recursive errors. Is there a friendly way to stringify a Tree?

What do you mean by ‘stringify’? Lezer trees have a toString method, which might help. JSON.stringify probably won’t do anything useful on these.

Lezer trees have a toString method, which might help.

Thanks! I feel very silly for not using that in the first place.