Adding Treesitter Extensions

Since everyone has different needs in their workflow, we have opted not to pre-configure any treesitter extensions. You can, however, quite easily add your own in only a couple lines of code.

Let's use the very popular treesitter playground extension as an example. All you have to to is declare the extension source from your configuration. Registration with treesitter will be handled automatically.

{ pkgs, ... }: {
  treesitter.extensions.treesitter-playground = {
    # you can optionally specify `module` to override the name of the table
    # entry which is passed to `telescope.opts`. By default, the name of
    # the attribute set is used (in this case `treesitter-playground`), but
    # since we specified the `module` parameter explicitly, `playground` will be used
    # instead.
    module = "playground"
    src = pkgs.fetchFromGitHub {
      owner = "nvim-treesitter";
      repo = "playground";
      rev = "2b81a018a49f8e476341dfcb228b7b808baba68b";
      hash = "sha256-2wSTVSkuEvTAq3tB5yLw13WWpp1lAycCL4U1BKMm8Kw=";
    };
    # these values are passed under `opts.playground` in `treesitter.setup()`
    opts.enable = true;
  };
}

Options

treesitter.enable

Whether to enable treesitter.

Type: boolean

Default: false

Example: true

Declared by:

treesitter.extensions

The set of treesitter extensions to make available.

Type: attribute set of (submodule)

Default: { }

Declared by:

treesitter.extensions.<name>.module

The name of the lua module to load for this extension. If not set, the attribute’s name is used.

Type: null or string

Default: null

Declared by:

treesitter.extensions.<name>.opts

Options to use for this extension. These are passed into treesitter’s extension opts during setup.

Type: attribute set

Default: { }

Declared by:

treesitter.extensions.<name>.src

Source to use for this plugin. This allows you to swap out the pinned version with a newer revision/fork or add patches by creating a wrapper derivation.

Type: package

Declared by:

treesitter.keys

A list of keybindings to set up for treesitter. follows standard lazy keymap spec.

Type: list of (attribute set)

Default: [ ]

Declared by:

treesitter.opts

Options to pass to treesitter.

Type: attribute set

Default: { }

Declared by:

treesitter.parsers

list of language parsers to install

Type: list of string

Default: [ ]

Example:

[ "c" "lua" ]

Declared by:

treesitter.src

Source to use for this plugin. This allows you to swap out the pinned version with a newer revision/fork or add patches by creating a wrapper derivation.

Type: package

Default: <derivation source>

Declared by: