Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MunifTanjim/nvim-treesitter-lua
Tree-sitter Lua parser integration for nvim-treesitter.
https://github.com/MunifTanjim/nvim-treesitter-lua
lua neovim treesitter
Last synced: 3 months ago
JSON representation
Tree-sitter Lua parser integration for nvim-treesitter.
- Host: GitHub
- URL: https://github.com/MunifTanjim/nvim-treesitter-lua
- Owner: MunifTanjim
- License: mit
- Archived: true
- Created: 2021-08-02T18:38:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-19T15:16:44.000Z (almost 3 years ago)
- Last Synced: 2024-06-10T00:37:32.931Z (5 months ago)
- Topics: lua, neovim, treesitter
- Language: Scheme
- Homepage:
- Size: 13.7 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nvim-treesitter-lua
Lua parser: [`MunifTanjim/tree-sitter-lua`](https://github.com/MunifTanjim/tree-sitter-lua).
_**This repository is now archived. Everything is merged into [`nvim-treesitter/nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter).**_
Archived Documentation
Tree-sitter Lua parser integration for [`nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter).
## Installation
Install the plugins with your preferred plugin manager. For example, with
[`vim-plug`](https://github.com/junegunn/vim-plug):```vim
Plug 'MunifTanjim/nvim-treesitter-lua'
Plug 'nvim-treesitter/nvim-treesitter'
```And put this in your config file:
```lua
require("nvim-treesitter-lua").setup()
```After that you can install the parser using this command:
```vim
:TSInstall lua
```## Tree-sitter Queries
This Lua parser is different than the default one that comes with
[`nvim-treesitter`](https://github.com/nvim-treesitter/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](https://github.com/MunifTanjim/nvim-treesitter-lua/tree/main/queries/lua)
folder:- [`nvim-treesitter/nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter).
- [`nvim-treesitter/nvim-treesitter-textobjects`](https://github.com/nvim-treesitter/nvim-treesitter-textobjects).
- [`RRethy/nvim-treesitter-textsubjects`](https://github.com/RRethy/nvim-treesitter-textsubjects).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:**
```lua
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:**
```lua
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](./LICENSE) file for details.