npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tree-sitter-d2

v0.7.2

Published

Tree sitter grammar for d2lang

Readme

tree-sitter-d2

Build Test

Table of Contents

Description

Tree Sitter grammar for d2lang (github). It's not yet finished, but usable for everyday cases with support for latest features like globs, filters and variables.

The goal is to provide a better experience for existing keywords, code blocks injections, folds, etc.

  • Better parsing of modern structures - The latest supported version of d2 is v0.7.0.
  • Built with nvim-treesitter in mind - We respect and follow its highlight groups.
  • Keywords - All keywords from the documentation are treated as such. (Open an issue if any are missing.)
  • Tests - We aim to cover all edge cases and examples from the documentation, resulting in more robust parsing. Currently, we have more than 100 tests. (This will be reduced later when the grammar becomes stable.)

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.

Installation

Neovim

via lazy.nvim

{
  "ravsii/tree-sitter-d2",
  dependencies = { "nvim-treesitter/nvim-treesitter" },
  build = "make nvim-install",
},

And then :TSInstall d2. After reloading Neovim everything should be working.

Helix

Fortunately Helix has its own guide on how to add new languages and grammars.

A quick example for installing d2 would be:

  1. Add a new language to 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"
  1. hx --grammar fetch && hx --grammar build
  2. Add your queries to ~/.config/helix/runtime/queries/d2
~/.config/helix/runtime/queries/d2
├── highlights.scm
├── injections.scm
└── locals.scm

[!WARNING]
We found out that Helix is using tree-sitter v0.22.x which makes it incompatible with this grammar, as it was built using tree-sitter v0.25.x.

If the highlighting doesn't work AND :log-open has this error:

Incompatible language version 15. Expected minimum 13, maximum 14

then 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

Other editors

If you're using some other editor that uses tree-sitter, please open an issue. Would be great if you could also provide instructions for others how to install it.

Showcase

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

Contribution

See CONTRIBUTION.md

Comparison

[!NOTE] This section is left "as is" from the very early development. It's outdated and not maintained, but it should give you a good perspective on the differences between these two grammars.

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:

  • On the left is our project using Neovim, on the right is pleshevskiy's grammar using Helix (I was unable to install pleshevskiy's grammar in Neovim)
  • Some examples are my random homework, thus being in Russian, please don't try to make sense of them. Thanks! :D

Better consistency overall

cmp1 cmp2

Better handling of foreign languages

cmpru1 cmpru2