tree-sitter-grammar-lsp

A simple LSP server to help writing Tree Sitter grammars

Stars
10

Tree Sitter Grammar.js LSP

Specialised LSP to edit one file and one file only - grammar.js used to specify Tree sitter grammars.

Made using Langoustine and Jsonrpclib.

Scala 3, Scala.js, ScalablyTyped, Cats-effect 3, FS2

Installation

  1. Grab a release from the https://github.com/keynmol/tree-sitter-grammar-lsp/releases/ tab

    Alternatively, you can build it locally by running sbt buildDev - the binaries for all platforms will be put in the /bin/ folder

  2. Configure your editor, here's the instructions for Neovim:

Ensure you have nvim-lspconfig installed, and then add this to your config:

 vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
    pattern = { "grammar.js", "*/corpus/*.txt" },
    callback = function() vim.cmd("setfiletype tree-sitter-grammar") end
  })

  vim.api.nvim_create_autocmd({ "BufReadPost" }, {
    pattern = { "grammar.js" },
    command = "set syntax=javascript"
  })

  local configs = require("lspconfig.configs")
  local util = require("lspconfig.util")
  configs.tree_sitter_grammar_lsp = {
    default_config = {
      cmd = { "tree-sitter-grammar-lsp-<your-os>" }, -- update to match your local installation location
      filetypes = { "tree-sitter-grammar" },
      root_dir = util.path.dirname
    }
  }

Then you're able to call setup just like any other server you may be using from nvim-lspconfig.

local configs = require("lspconfig")
configs.tree_sitter_grammar_lsp.setup({})

Contributing

My recommendation is to point your LSP config to a locally checked out copy of this repository, specifically at <root>/bin/tree-sitter-grammar-lsp-dev-<your-platform>.

To produce that binary, you can run sbt buildDev - which will produce non-optimised JS version, and should be quicker to build iteratively.

If you want to produce a binary with all the optimisations, run sbt buildRelease.

Happy hacking!