/nvim-treesitter-lua

Tree-sitter Lua parser integration for nvim-treesitter.

Primary LanguageSchemeMIT LicenseMIT

nvim-treesitter-lua

Lua parser: MunifTanjim/tree-sitter-lua.

This repository is now archived. Everything is merged into nvim-treesitter/nvim-treesitter.

Archived Documentation

Tree-sitter Lua parser integration for nvim-treesitter.

Installation

Install the plugins with your preferred plugin manager. For example, with vim-plug:

Plug 'MunifTanjim/nvim-treesitter-lua'
Plug 'nvim-treesitter/nvim-treesitter'

And put this in your config file:

require("nvim-treesitter-lua").setup()

After that you can install the parser using this command:

:TSInstall lua

Tree-sitter Queries

This Lua parser is different than the default one that comes with nvim-treesitter. So all the plugin that comes with tree-sitter queries for that default parser won't work with this one.

So, nvim-treesitter-lua includes queries for a few plugins in the ./queries/lua folder:

If you want to contribute queries for other plugins, please open a Pull Request.

It also returns some functions you can use to add/remove queries.

treesitter_lua.get_query

Returns the query content for name.

Signature: get_query(name: string) -> string

Name Type Description
name string Query name

Examples:

local treesitter_lua = require("nvim-treesitter-lua")

treesitter_lua.get_query('injections')

treesitter_lua.set_query

Sets (append/prepend/replace) the query content for name and returns it.

Signature:

  • set_query(filepath: string, mode?: string) -> string
  • set_query(name: string, content: string, mode?: string) -> string
Name Type Description
filepath string Absolute path to query file
name string Query name
content string Query content
mode "append" (default) / "prepend" / "replace" Mode for set_query

Examples:

local treesitter_lua = require("nvim-treesitter-lua")

-- using filepath
treesitter_lua.set_query("/absolute/path/to/queries/lua/indent.scm", "replace")

-- using name and content
treesitter_lua.set_query("injections", [[
((function_call
  name: (_) @_nvim_exec
  arguments: (arguments (string content: _ @vim)))
  (#match? @_nvim_exec "(^|\.)nvim_exec$"))
]], "append")

License

Licensed under the MIT License. Check the LICENSE file for details.