crystal-lang-tools/tree-sitter-crystal

tree sitter parser for crystal lang

57

stars

570

commits

C

primary language

Jan 28, 2026

updated

crystal-lang
hacktoberfest
tree-sitter

README

tree-sitter-crystal

Crystal grammar for tree-sitter.

This grammar is mostly complete, and can parse the majority of Crystal's own source code without errors.

Setup

Hopefully support for this parser will be upstreamed by editors soon. At the moment, it must be integrated manually.

Neovim

  1. Set up the nvim-treesitter plugin.
  1. Include this lua snippet in your neovim setup:

    vim.api.nvim_create_autocmd("User", {
      pattern = 'TSUpdate',
      callback = function()
        require('nvim-treesitter.parsers').crystal = {
          install_info = {
            url = 'https://github.com/crystal-lang-tools/tree-sitter-crystal',
            -- path = '<ts-crystal-install-path>', -- if you want to use a local version instead
            generate = false,
            generate_from_json = false,
            queries = 'queries/nvim'
          },
        }
      end,
    })
    
    vim.treesitter.language.register("crystal", { "cr" })
    
  2. Restart neovim and run :TSUpdate

To confirm the grammar is functioning, run :checkhealth nvim-treesitter and look for this line:

- crystal             ✓ . ✓ . ✓

For older nvim-treesitter versions (aka the master branch)

  1. Check out this repo locally. Its location will be referred to as <ts-crystal-install-path>.

  2. In a terminal, navigate to wherever nvim-treesitter is installed (this will depend on your plugin manager). Run:

    mkdir queries/crystal
    cd queries/crystal
    ln -s <ts-crystal-install-path>/queries/nvim/*.scm .
    
  3. Include this lua snippet in your neovim setup:

    local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
    parser_config.crystal = {
      install_info = {
        url = "<ts-crystal-install-path>",
        files = {"src/parser.c", "src/scanner.c"},
        branch = "main",
      },
      filetype = "cr",
    }
    
  4. Restart neovim and run :TSInstall crystal

Contributors

keidax

377 commits

nobodywasishere

163 commits

hugopl

23 commits

devnote-dev

2 commits

crystal-lang-tools/tree-sitter-crystal

tree sitter parser for crystal lang

57

stars

570

commits

C

primary language

Jan 28, 2026

updated

crystal-lang
hacktoberfest
tree-sitter

README

tree-sitter-crystal

Crystal grammar for tree-sitter.

This grammar is mostly complete, and can parse the majority of Crystal's own source code without errors.

Setup

Hopefully support for this parser will be upstreamed by editors soon. At the moment, it must be integrated manually.

Neovim

  1. Set up the nvim-treesitter plugin.
  1. Include this lua snippet in your neovim setup:

    vim.api.nvim_create_autocmd("User", {
      pattern = 'TSUpdate',
      callback = function()
        require('nvim-treesitter.parsers').crystal = {
          install_info = {
            url = 'https://github.com/crystal-lang-tools/tree-sitter-crystal',
            -- path = '<ts-crystal-install-path>', -- if you want to use a local version instead
            generate = false,
            generate_from_json = false,
            queries = 'queries/nvim'
          },
        }
      end,
    })
    
    vim.treesitter.language.register("crystal", { "cr" })
    
  2. Restart neovim and run :TSUpdate

To confirm the grammar is functioning, run :checkhealth nvim-treesitter and look for this line:

- crystal             ✓ . ✓ . ✓

For older nvim-treesitter versions (aka the master branch)

  1. Check out this repo locally. Its location will be referred to as <ts-crystal-install-path>.

  2. In a terminal, navigate to wherever nvim-treesitter is installed (this will depend on your plugin manager). Run:

    mkdir queries/crystal
    cd queries/crystal
    ln -s <ts-crystal-install-path>/queries/nvim/*.scm .
    
  3. Include this lua snippet in your neovim setup:

    local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
    parser_config.crystal = {
      install_info = {
        url = "<ts-crystal-install-path>",
        files = {"src/parser.c", "src/scanner.c"},
        branch = "main",
      },
      filetype = "cr",
    }
    
  4. Restart neovim and run :TSInstall crystal

Contributors

keidax

377 commits

nobodywasishere

163 commits

hugopl

23 commits

devnote-dev

2 commits

Languages

C

46.1%

JavaScript

29.6%

Crystal

21.7%

Tree-sitter Query

2.7%