Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Tree-sitter Lua parser integration for nvim-treesitter.

License

Notifications You must be signed in to change notification settings

MunifTanjim/nvim-treesitter-lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Tree-sitter Lua parser integration for nvim-treesitter.

Topics

Resources

License

Stars

Watchers

Forks