Skip to content

Latest commit

 

History

History
75 lines (53 loc) · 3.55 KB

File metadata and controls

75 lines (53 loc) · 3.55 KB

Treesitter

Treesitter is used for e.g. syntax highlighting.

Builtin treesitter parsers

The editor is statically linked to some treesitter parsers.

The list of builtin parsers is currently:

  • C
  • Nim
  • JavaScript
  • JSON
  • Markdown

To change the list of builtin parsers compile the editor with e.g. -d:treesitterBuiltins=cpp,rust

If an external parser exists then the editor will not use the builtin one.

External parsers

Nev supports treesitter parser compiled to dynamic libraries (.dll/.so) or wasm modules. .dll/.so parsers are not supported in the musl version because it can't load dynamic libraries, but wasm parsers are still supported.

The parsers have to placed in {app_dir}/languages to be detected.

Installing external treesitter parsers

You can use the install-treesitter-parser-prebuilt-from-list or install-treesitter-parser-prebuilt command to install prebuilt treesitter parsers for some language in wasm format. The parsers are downloaded from Nimaoth/tree-sitter-wasm-binaries by default.

You can change the download url template using the setting editor.treesitter-wasm-download-url, the default is https://github.com/Nimaoth/tree-sitter-wasm-binaries/releases/download/v0.3/{language}.tar.gz ({language} gets replaced with the language name)

Alternatively you can also download and compile any treesitter parser from a github repository using the install-treesitter-parser command. If lang.xyz.text.treesitter.repository is set to a github repository name like alaviss/tree-sitter-nim then you can just pass the language name to install-treesitter-parser. Otherwise you can pass the repository name directly.

install-treesitter-parser will clone the repository in {app_dir}/languages/tree-sitter-xyz and then compile the parser to a wasm module. This requires git, emscripten and tree-sitter (the treesitter cli) to be installed and in the PATH.

To see which languages have the treesitter repository preconfigured look at the base settings

install-treesitter-parser-prebuilt-from-list # Opens a prompt with a list of languages, then installs
                                             # the chosen language by downloading a prebuilt wasm file

install-treesitter-parser-prebuilt "bash"    # Installs the treesitter parser for the given language
                                             # by downloading a prebuilt wasm file

install-treesitter-parser "nim"              # Uses repo configured in `lang.xyz.text.treesitter.repository`
install-treesitter-parser "maxxnino/tree-sitter-zig" # username/repo-name
install-treesitter-parser "tree-sitter/tree-sitter-typescript/typescript" # Parser is in subdirectory `typescript` in the repository

Configuration

There is not much to configure treesitter. By default the editor will look for the parser library in {app_dir}/languages/{language}.{dll|so|wasm}.

// ~/.nev/settings.json
{
    "lang.markdown.text.treesitter": {
        // username/repo-name/subdir
        // subdir is required if the `src` directory containing the parser is not in the root of the repository
        "repository": "tree-sitter-grammars/tree-sitter-markdown/tree-sitter-markdown",

        // If there are multiple parsers in the same repository then you need to specify where the queries
        // for this parser are. If there is only one parser then it will find the queries by looking for the
        // `highlights.scm` file.
        "queries": "tree-sitter-markdown/queries",
    }
}