tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter
MIT License
338 stars 96 forks source link

feature: frontmatter #224

Open jwnrt opened 3 months ago

jwnrt commented 3 months ago

Did you check the tree-sitter docs?

Is your feature request related to a problem? Please describe.

Rust now supports frontmatter blocks in nightly. See RFC 3503.

These blocks are similar to markdown's fenced code blocks but using dashes instead of backticks.

They're opened with a line of 3+ dashes and an optional infostring, i.e. matching /^-{3,}\s*([^\s,]+)?\s*$/ (for example ---, -----, or --- cargo).

The blocks may contain any characters including dashes.

They are closed by a line matching /^-{n}\s*$/ where n is the number of opening dashes. That will need to be done in scanner.c.

Describe the solution you'd like

Something to match these frontmatter blocks and highlight them as a comment would be nice.

In the future the contents will probably want to be parsed with a language injection depending on the value of the infostring (e.g. TOML for cargo) but I don't think all of that is worked out on the Rust side yet.

Describe alternatives you've considered

An alternative is to just not implement this. It's still unstable.

Additional context

https://rust-lang.github.io/rfcs/3503-frontmatter.html#reference-level-explanation