folding / delims question

So… I made a grammar and syntax highlighting is working. Thanks a ton.

The lang is just a bunch of statements like this:

action-a
  foo
  bar
  ;

action-2
  baz
  qux;

It’d be cool to have code-folding on semicolons and just show action-x; when folded.

I’m not sure what I should use for foldNodeProp on the lezer side, or how to set up the delimiter.

There aren’t really any delimiters in the lang (other than semicolon? and the action keyword?)

If your tree has something like a Statement node, something like this (in parser.configure({props: [...]}) might work…

  foldNodeProp.add({
    Statement(tree) { return {from: tree.firstChild!.to, to: tree.to} }
  })

That creates a fold range from after the first token in the statement to the end of the statement.

2 Likes

That works perfectly.