| Crates.io | tree-sitter-d2 |
| lib.rs | tree-sitter-d2 |
| version | 0.7.1 |
| created_at | 2025-02-02 10:08:37.637513+00 |
| updated_at | 2025-05-19 20:16:49.686282+00 |
| description | d2 grammar for the tree-sitter parsing library |
| homepage | |
| repository | https://github.com/ravsii/tree-sitter-d2 |
| max_upload_size | |
| id | 1539433 |
| size | 389,926 |
Tree Sitter grammar for d2lang (github). It's not yet finished, but usable for every-day cases with support for latest features like globs, filters and variables.
The goal is to provide better experience for existing keywords, code blocks injections, folds, etc.
I've never done anything remotely close to parsing grammar, so there could be some bad patterns and simply bad code. Feel free to open issues.
via lazy.nvim
{
"ravsii/tree-sitter-d2",
dependencies = { "nvim-treesitter/nvim-treesitter" },
build = "make nvim-install",
branch = "v0.7.1",
},
[!TIP] We recommend using
branchset to the latest release tag instead ofmain, as we cannot guarantee that there won't be breaking changes, because that's fully on d2 team. But if there are, we simply follow the latest release.
Fortunately Helix has it's own guide on how to add new languages and grammars.
A quick example for installing d2 would be:
languages.toml[[language]]
name = "d2"
scope = "source.git"
file-types = ["d2"]
comment-token = "#"
roots = [""]
indent = { tab-width = 2, unit = " " }
[[grammar]]
source = { git = "https://github.com/ravsii/tree-sitter-d2", rev = "main" }
name = "d2"
hx --grammar fetch && hx --grammar build~/.config/helix/runtime/queries/d2~/.config/helix/runtime/queries/d2
├── highlights.scm
├── injections.scm
└── locals.scm
[!WARNING]
We found out that Helix is usingtree-sitter v0.22.xwhich makes it incompatible with this grammar, as it was built usingtree-sitter v0.25.x.If the highlighting doesn't work and
:log-openhas this error:Incompatible language version 15. Expected minimum 13, maximum 14then try using these options
[[grammar]] source = { git = "https://github.com/ravsii/tree-sitter-d2", rev = "main-helix" } name = "d2"For more info see: https://github.com/ravsii/tree-sitter-d2/issues/102
If you're using some other editor that's using tree-sitter, please open an issue. Would be great if you could also provide instructions for other how to install it.
Tokyo Night Storm theme with CaskaydiaCove font.
Props to Neovim's Tokyo Night theme for supporting pretty much every highlighting group.
https://github.com/user-attachments/assets/a9bd20d0-eb6c-43c2-8e58-7d211d350025
See CONTRIBUTION.md
This section is outdated and not maintained
Actually, there's another tree-sitter-d2 by pleshevskiy. My project's initial
goal was to fix issues his grammar had, but later I realized that his grammar
is not maintained and lacks many features d2 has added since then.
Here's a list of comparisons as of v0.2 version of this project, both using
Tokyonight Storm theme.
Please note that:

