get_available(tier)
Return a list of languages available for installation from the parser manifest.Parameters
Filter parsers by tier. Valid values:
1- stable parsers2- unstable parsers3- unmaintained parsers4- unsupported parsers
Returns
Array of language names available for installation, sorted alphabetically.
Usage
Implementation Notes
- Triggers the
User TSUpdateautocommand to allow dynamic parser registration - Reads from the parser manifest (
nvim-treesitter.parsersmodule) - Results are always sorted alphabetically
get_installed(type)
Return a list of languages installed via nvim-treesitter.This only searches nvim-treesitter’s configured installation directory. Parsers from other sources placed elsewhere on
runtimepath are not included.Parameters
Filter installed languages by type:
"parsers"- only show languages with installed parsers"queries"- only show languages with installed queries
Returns
Array of installed language names.
Usage
List All Parsers (Any Source)
To list all parsers installed from any source (not just nvim-treesitter):Implementation Details
The function:- Scans the
queries/directory for query folders (unlesstype = 'parsers') - Scans the
parser/directory for.sofiles (unlesstype = 'queries') - Returns unique language names found in either location
A language may have queries without a parser (queries only) or a parser without queries (parser only). Calling without the
type parameter returns both.indentexpr()
Used to enable treesitter-based indentation for a language. This function should be assigned to theindentexpr option.
Parameters
None. The function reads the line number fromvim.v.lnum (set by Neovim when evaluating indentexpr).
Returns
The calculated indentation level in columns for the current line.Special return values:
-1- use autoindent (fall back tocindentorsmartindent)0- no indentation- positive integer - specific column position for indentation
Usage
Enable treesitter indentation in your configuration:~/.config/nvim/after/ftplugin/rust.lua):
How It Works
- Gets the current buffer’s treesitter parser
- Parses the visible window range for performance
- Finds the language tree covering the current line
- Queries indent captures from the language’s
indents.scmquery file - Calculates indentation based on treesitter node hierarchy and indent directives
Indent Query Captures
The function recognizes these captures inindents.scm:
@indent.begin- increase indent for child nodes@indent.end- decrease indent@indent.align- align with specific delimiter@indent.dedent- dedent current line@indent.branch- conditional indent based on branch@indent.ignore- preserve existing indentation@indent.auto- use autoindent@indent.zero- force zero indentation
Performance Considerations
- Only parses the visible window range (lines between
w0andw$) - Uses memoization to cache indent query results per buffer and syntax tree
- Ignores comment parsers to avoid incorrect indentation in documentation
Limitations
- Requires a
indents.scmquery file for the language - Returns
-1(fallback to autoindent) if no parser or query is available - May not work correctly in injected language regions with complex nesting