Syntax highlighting

Language support such as tokenizing and highlighting is provided by Tree Sitter. Each language requires a Tree Sitter grammar to have tokenization and queries to provide additional features such as syntax highlighting.


To learn more about queries, see Creating Parsers.

Lapce has select few (Rust, JSON, TOML) grammars built-in for convenience. All other languages need to provide an externally loadable grammar in a form of shared library. Lapce will update all supported grammars by default on start-up.

Grammars are stored in $LOCAL_DATA_DIR/grammars directory. Each grammar should be named ${DLL_PREFIX}tree-sitter-${NAME}.${DLL_SUFFIX} where ${NAME} refers to language name and ${DLL_PREFIX}/${DLL_SUFFIX} refer to OS defined constants for shared libraries (see DLL_PREFIX and DLL_EXTENSION).

Grammars are loaded in order:

  1. User provided grammar

  2. System provider grammar

  3. Built-in grammar


To learn more about queries, see Syntax Highlighting#Queries.

Queries are stored in $SETTINGS_DIR/queries/$LANGUAGE. Currently only highlights.scm are supported.


For Lapce to know how to deal with files, it's required to include a language definition which contains which filenames or extensions to match to language, what indent or comment type it uses and additional configuration (that depends on tree-sitter) such as code lens (unrelated to LSP code lens) or sticky headers tokens.

Languages are defined in lapce-core/src/

Language Server Protocol

LSPs should define DocumentSelector via the extension API and/or through volt.toml extension manifest. It can be otherwise defined through language_id_from_path in lapce-proxy/src/

Last updated