mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
Docs: format and fixes
Format the docs to be consisted and some typos.
This commit is contained in:
parent
1301884e97
commit
6f9e5bf23f
3 changed files with 235 additions and 176 deletions
|
|
@ -6,8 +6,9 @@ If you haven't already, you should really come and reach out to us on our [gitte
|
|||
room, so we can help you with any question you might have!
|
||||
|
||||
As you know, `nvim-treesitter` is roughly splitted in two parts :
|
||||
- Parser configurations : for various things like `locals`, `highlights`
|
||||
- What we like to call *modules* : tiny lua modules that provide a given feature, based on parser configurations
|
||||
|
||||
- Parser configurations : for various things like `locals`, `highlights`
|
||||
- What we like to call *modules* : tiny lua modules that provide a given feature, based on parser configurations
|
||||
|
||||
Depending on which part of the plugin you want to contribute to, please read the appropriate section.
|
||||
|
||||
|
|
@ -26,12 +27,13 @@ ln -s ../../scripts/pre-push .git/hooks/pre-push
|
|||
## Adding new modules
|
||||
|
||||
If you want to see a new functionality added to `nvim-treesitter` feel free to first open an issue
|
||||
to that we can track our solution !
|
||||
to that we can track our solution!
|
||||
Thus far, there is basically two types of modules:
|
||||
- Little modules (like `incremental selection`) that are built in `nvim-treesitter`, we call them
|
||||
`builtin modules`.
|
||||
- Bigger modules (like `completion-treesitter`, or `nvim-tree-docs`), or modules that integrate
|
||||
with other plugins, that we call `remote modules`.
|
||||
|
||||
- Little modules (like `incremental selection`) that are built in `nvim-treesitter`, we call them
|
||||
`builtin modules`.
|
||||
- Bigger modules (like `completion-treesitter`, or `nvim-tree-docs`), or modules that integrate
|
||||
with other plugins, that we call `remote modules`.
|
||||
|
||||
In any case, you can build your own module ! To help you started in the process, we have a template
|
||||
repository designed to build new modules [here](https://github.com/nvim-treesitter/module-template).
|
||||
|
|
@ -46,17 +48,19 @@ Before going any further, we highly suggest that you [read more about tree-sitte
|
|||
|
||||
Each query has an appropriate name, which is then used by modules to extract data from the syntax tree.
|
||||
For now two types of queries are used by `nvim-treesitter`:
|
||||
- `highlights.scm` : used for syntax highlighting, using the `highlight` module.
|
||||
- `locals.scm` : used to extract keyword definitions, scopes, references,... using the `locals` module.
|
||||
|
||||
- `highlights.scm` : used for syntax highlighting, using the `highlight` module.
|
||||
- `locals.scm` : used to extract keyword definitions, scopes, references, etc, using the `locals` module.
|
||||
|
||||
For both of these types there is a *norm* you will have to follow so that features work fine.
|
||||
Here are some global advices :
|
||||
- If your language is listed [here](https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries),
|
||||
you can debug and experiment with your queries there.
|
||||
- If not, you should consider installing the [tree-sitter cli](https://github.com/tree-sitter/tree-sitter/tree/master/cli),
|
||||
you should then be able to open a local playground using `tree-sitter build-wasm && tree-sitter web-ui` within the
|
||||
parsers repo.
|
||||
- An Example of somewhat complex highlight queries can be found in queries/ruby/highlights.scm (Maintained by @TravonteD)
|
||||
|
||||
- If your language is listed [here](https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries),
|
||||
you can debug and experiment with your queries there.
|
||||
- If not, you should consider installing the [tree-sitter cli](https://github.com/tree-sitter/tree-sitter/tree/master/cli),
|
||||
you should then be able to open a local playground using `tree-sitter build-wasm && tree-sitter web-ui` within the
|
||||
parsers repo.
|
||||
- An Example of somewhat complex highlight queries can be found in queries/ruby/highlights.scm (Maintained by @TravonteD)
|
||||
|
||||
### Highlights
|
||||
|
||||
|
|
@ -64,8 +68,8 @@ As languages differ quite a lot, here is a set of captures available to you when
|
|||
One important thing to note is that many of these capture groups are not supported by `neovim` for now, and will not have any
|
||||
effect on highlighting. We will work on improving highlighting in the near future though.
|
||||
|
||||
|
||||
#### Misc
|
||||
|
||||
```
|
||||
@comment
|
||||
@error for error (ERROR` nodes.
|
||||
|
|
@ -75,13 +79,16 @@ effect on highlighting. We will work on improving highlighting in the near futur
|
|||
|
||||
Some captures are related to language injection (like markdown code blocks). As this is not supported by neovim yet, these
|
||||
are optional and will not have any effect for now.
|
||||
|
||||
```
|
||||
@embedded
|
||||
@injection
|
||||
language
|
||||
content
|
||||
```
|
||||
|
||||
#### Constants
|
||||
|
||||
```
|
||||
@constant
|
||||
builtin
|
||||
|
|
@ -96,6 +103,7 @@ are optional and will not have any effect for now.
|
|||
```
|
||||
|
||||
#### Functions
|
||||
|
||||
```
|
||||
@function
|
||||
builtin
|
||||
|
|
@ -109,6 +117,7 @@ are optional and will not have any effect for now.
|
|||
```
|
||||
|
||||
#### Keywords
|
||||
|
||||
```
|
||||
@conditional
|
||||
@repeat
|
||||
|
|
@ -161,4 +170,3 @@ Mainly for markup languages.
|
|||
@scope
|
||||
@reference
|
||||
```
|
||||
|
||||
|
|
|
|||
119
README.md
119
README.md
|
|
@ -4,7 +4,9 @@ Traditionnal highlighting (left) vs Treesitter-based highlighting (right).
|
|||
[](https://gitter.im/nvim-treesitter/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||

|
||||

|
||||
|
||||
# nvim-treesitter
|
||||
|
||||
Treesitter configurations and abstraction layer for Neovim.
|
||||
|
||||
**Warning: Treesitter and Treesitter highlighting are an experimental feature of nightly versions of Neovim.
|
||||
|
|
@ -13,9 +15,10 @@ Please consider the experience with this plug-in as experimental until Neovim 0.
|
|||
# Quickstart
|
||||
|
||||
## Requirements
|
||||
- Neovim [nightly](https://github.com/neovim/neovim#install-from-source)
|
||||
- `git` in your path.
|
||||
- A C compiler in your path.
|
||||
|
||||
- Neovim [nightly](https://github.com/neovim/neovim#install-from-source)
|
||||
- `git` in your path.
|
||||
- A C compiler in your path.
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
@ -24,6 +27,7 @@ You can install `nvim-treesitter` with your favorite package manager, or using t
|
|||
### Using a package manager
|
||||
|
||||
Simply add these lines to your `init.vim` :
|
||||
|
||||
```vim
|
||||
Plug 'nvim-treesitter/nvim-treesitter'
|
||||
```
|
||||
|
|
@ -31,6 +35,7 @@ Plug 'nvim-treesitter/nvim-treesitter'
|
|||
### Using neovim `pack` feature
|
||||
|
||||
We highly recommend reading `:h packages` to learn more about this feature, but you can still follow these steps:
|
||||
|
||||
```sh
|
||||
$ mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start
|
||||
$ cd ~/.local/share/nvim/site/pack/nvim-treesitter/start
|
||||
|
|
@ -45,6 +50,7 @@ provides two command to tackle this issue:
|
|||
- `TSInstallInfo` to know which parser is installed.
|
||||
|
||||
Let's say you need parsers for `lua`, `c`, and `python`, this is how you do with these commands:
|
||||
|
||||
```vim
|
||||
:TSInstall c
|
||||
Downloading...
|
||||
|
|
@ -63,6 +69,7 @@ Treesitter parser for python has been installed
|
|||
```
|
||||
|
||||
Cool, lets see which parsers are installed:
|
||||
|
||||
```vim
|
||||
:TSInstallInfo
|
||||
csharp [✗] not installed
|
||||
|
|
@ -91,27 +98,27 @@ And now you should be able to use every functionality `nvim-treesitter` provides
|
|||
|
||||
## Setup
|
||||
|
||||
in your `init.vim`:
|
||||
In your `init.vim`:
|
||||
|
||||
```lua
|
||||
lua <<EOF
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
highlight = {
|
||||
enable = true, -- false will disable the whole extension
|
||||
disable = { 'c', 'rust' }, -- list of language that will be disabled
|
||||
custom_captures = { -- mapping of user defined captures to highlight groups
|
||||
-- ["foo.bar"] = "Identifier" -- highlight own capture @foo.bar with highlight group "Identifier", see :h nvim-treesitter-query-extensions
|
||||
},
|
||||
enable = true, -- false will disable the whole extension
|
||||
disable = { 'c', 'rust' }, -- list of language that will be disabled
|
||||
custom_captures = { -- mapping of user defined captures to highlight groups
|
||||
-- ["foo.bar"] = "Identifier" -- highlight own capture @foo.bar with highlight group "Identifier", see :h nvim-treesitter-query-extensions
|
||||
},
|
||||
},
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
disable = { 'cpp', 'lua' },
|
||||
keymaps = { -- mappings for incremental selection (visual mappings)
|
||||
init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
|
||||
node_incremental = "grn", -- increment to the upper named parent
|
||||
scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm)
|
||||
node_decremental = "grm", -- decrement to the previous node
|
||||
}
|
||||
enable = true,
|
||||
disable = { 'cpp', 'lua' },
|
||||
keymaps = { -- mappings for incremental selection (visual mappings)
|
||||
init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
|
||||
node_incremental = "grn", -- increment to the upper named parent
|
||||
scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm)
|
||||
node_decremental = "grm", -- decrement to the previous node
|
||||
}
|
||||
},
|
||||
refactor = {
|
||||
highlight_definitions = {
|
||||
|
|
@ -123,44 +130,44 @@ require'nvim-treesitter.configs'.setup {
|
|||
smart_rename = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
smart_rename = "grr" -- mapping to rename reference under cursor
|
||||
smart_rename = "grr" -- mapping to rename reference under cursor
|
||||
}
|
||||
},
|
||||
navigation = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
goto_definition = "gnd", -- mapping to go to definition of symbol under cursor
|
||||
list_definitions = "gnD" -- mapping to list all definitions in current file
|
||||
goto_definition = "gnd", -- mapping to go to definition of symbol under cursor
|
||||
list_definitions = "gnD" -- mapping to list all definitions in current file
|
||||
}
|
||||
}
|
||||
},
|
||||
textobjects = { -- syntax-aware textobjects
|
||||
enable = true,
|
||||
disable = {},
|
||||
keymaps = {
|
||||
["iL"] = { -- you can define your own textobjects directly here
|
||||
python = "(function_definition) @function",
|
||||
cpp = "(function_definition) @function",
|
||||
c = "(function_definition) @function",
|
||||
java = "(method_declaration) @function"
|
||||
},
|
||||
-- or you use the queries from supported languages with textobjects.scm
|
||||
["af"] = "@function.outer",
|
||||
["if"] = "@function.inner",
|
||||
["aC"] = "@class.outer",
|
||||
["iC"] = "@class.inner",
|
||||
["ac"] = "@conditional.outer",
|
||||
["ic"] = "@conditional.inner",
|
||||
["ae"] = "@block.outer",
|
||||
["ie"] = "@block.inner",
|
||||
["al"] = "@loop.outer",
|
||||
["il"] = "@loop.inner",
|
||||
["is"] = "@statement.inner",
|
||||
["as"] = "@statement.outer",
|
||||
["ad"] = "@comment.outer",
|
||||
["am"] = "@call.outer",
|
||||
["im"] = "@call.inner"
|
||||
}
|
||||
enable = true,
|
||||
disable = {},
|
||||
keymaps = {
|
||||
["iL"] = { -- you can define your own textobjects directly here
|
||||
python = "(function_definition) @function",
|
||||
cpp = "(function_definition) @function",
|
||||
c = "(function_definition) @function",
|
||||
java = "(method_declaration) @function"
|
||||
},
|
||||
-- or you use the queries from supported languages with textobjects.scm
|
||||
["af"] = "@function.outer",
|
||||
["if"] = "@function.inner",
|
||||
["aC"] = "@class.outer",
|
||||
["iC"] = "@class.inner",
|
||||
["ac"] = "@conditional.outer",
|
||||
["ic"] = "@conditional.inner",
|
||||
["ae"] = "@block.outer",
|
||||
["ie"] = "@block.inner",
|
||||
["al"] = "@loop.outer",
|
||||
["il"] = "@loop.inner",
|
||||
["is"] = "@statement.inner",
|
||||
["as"] = "@statement.outer",
|
||||
["ad"] = "@comment.outer",
|
||||
["am"] = "@call.outer",
|
||||
["im"] = "@call.inner"
|
||||
}
|
||||
},
|
||||
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
|
||||
}
|
||||
|
|
@ -170,6 +177,7 @@ EOF
|
|||
## Commands
|
||||
|
||||
Each feature can be enabled or disabled by different means:
|
||||
|
||||
```vim
|
||||
:TSBufEnable {module} " enable module on current buffer
|
||||
:TSBufDisable {module} " disable module on current buffer
|
||||
|
|
@ -182,11 +190,13 @@ Each feature can be enabled or disabled by different means:
|
|||
|
||||
The goal of `nvim-treesitter` is both to provide a simple and easy way to use the interface for Treesitter in Neovim,
|
||||
but also to add some functionalities to it:
|
||||
|
||||
Some of these features are :
|
||||
- [x] Incremental selection
|
||||
- [x] Syntax based code folding (`set foldmethod=expr foldexpr=nvim_treesitter#foldexpr()`)
|
||||
- [x] Consistent syntax highlighting (the api is not quite stable yet)
|
||||
- [x] Statusline indicator (`require'nvim-treesitter'.statusline(size)`)
|
||||
|
||||
- [x] Incremental selection
|
||||
- [x] Syntax based code folding (`set foldmethod=expr foldexpr=nvim_treesitter#foldexpr()`)
|
||||
- [x] Consistent syntax highlighting (the api is not quite stable yet)
|
||||
- [x] Statusline indicator (`require'nvim-treesitter'.statusline(size)`)
|
||||
|
||||
You can find the roadmap [here](https://github.com/nvim-treesitter/nvim-treesitter/projects/1).
|
||||
The roadmap and all features of this plugin are open to change, and any suggestion will be highly appreciated!
|
||||
|
|
@ -234,12 +244,13 @@ Modules can consist of the following properties:
|
|||
- `enable`: Determines if the module is enabled by default. This is usually overridden by the user.
|
||||
- `disable`: A list of languages that this module is disabled for. This is usually overridden by the user.
|
||||
- `is_supported`: A function that takes a language and determines if this module supports that language.
|
||||
- `attach`: A function that attachs to a buffer. This is required if `module_path` is not provided.
|
||||
- `attach`: A function that attaches to a buffer. This is required if `module_path` is not provided.
|
||||
- `detach`: A function that detaches from a buffer. This is required if `module_path` is not provided.
|
||||
|
||||
## Utils
|
||||
|
||||
you can get some utility functions with
|
||||
|
||||
```lua
|
||||
local ts_utils = require 'nvim-treesitter.ts_utils'
|
||||
```
|
||||
|
|
@ -294,9 +305,11 @@ For example, you can add files to `<vim-config-dir>/after/queries/lua/highlights
|
|||
You can also manually add query paths to the runtime path by adding this to your vim config `set rtp+='path/to/queries'`.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Before doing anything run `:checkhealth nvim_treesitter`. This will help you find where the bug might come from.
|
||||
|
||||
### Feature `X` does not work for language `Y`...
|
||||
|
||||
First, check the `## Y parser healthcheck` section of `:checkhealth` if you have any warning.
|
||||
If you do, it's highly possible that this is the cause of the problem.
|
||||
If everything is okay, then it might be an actual error.
|
||||
|
|
@ -307,7 +320,9 @@ In both cases, feel free to open an issue here.
|
|||
|
||||
This is a well known issue, which arise when the tree and the buffer are getting out of sync. \
|
||||
As this issue comes from upstream, we don't have any finite fix. To get around this, you can force reparsing the buffer with this command:
|
||||
|
||||
```vim
|
||||
:write | edit | TSBufEnable highlight
|
||||
```
|
||||
This will save, restore and enable highlighting for the current buffer, fixing the issue.
|
||||
|
||||
This will save, restore and enable highlighting for the current buffer, fixing the issue.
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ Minimum version of neovim: nightly
|
|||
Authors: Yazdani Kiyan <yazdani.kiyan@protonmail.com>, Vigouroux Thomas <tomvig38@gmail.com>
|
||||
|
||||
==============================================================================
|
||||
INTRODUCTION *nvim-treesitter-intro*
|
||||
INTRODUCTION *nvim-treesitter-intro*
|
||||
|
||||
nvim-treesitter wraps the neovim treesitter api to provide functionnalities such
|
||||
as highlighting and incremental selection, and a command to easily install parsers.
|
||||
|
||||
==============================================================================
|
||||
QUICK START *nvim-treesitter-quickstart*
|
||||
QUICK START *nvim-treesitter-quickstart*
|
||||
|
||||
Install the parser for your language
|
||||
|
||||
|
|
@ -30,71 +30,79 @@ By default, everything is disabled. To enable support for features, in your `ini
|
|||
>
|
||||
lua <<EOF
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
highlight = {
|
||||
enable = true, -- false will disable the whole extension
|
||||
disable = { 'c', 'rust' }, -- list of language that will be disabled
|
||||
custom_captures = { -- mapping of user defined captures to highlight groups
|
||||
-- ["foo.bar"] = "Identifier" -- highlight own capture @foo.bar with highlight group "Identifier", see :h nvim-treesitter-query-extensions
|
||||
},
|
||||
},
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
disable = { 'cpp', 'lua' },
|
||||
keymaps = { -- mappings for incremental selection (visual mappings)
|
||||
init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
|
||||
node_incremental = "grn", -- increment to the upper named parent
|
||||
scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm)
|
||||
node_decremental = "grm", -- decrement to the previous node
|
||||
}
|
||||
},
|
||||
refactor = {
|
||||
highlight_defintions = {
|
||||
enable = true
|
||||
highlight = {
|
||||
enable = true, -- false will disable the whole extension
|
||||
disable = { 'c', 'rust' }, -- list of language that will be disabled
|
||||
custom_captures = { -- mapping of user defined captures to highlight groups
|
||||
-- ["foo.bar"] = "Identifier" -- highlight own capture @foo.bar with highlight group "Identifier", see :h nvim-treesitter-query-extensions
|
||||
},
|
||||
},
|
||||
smart_rename = {
|
||||
enable = true,
|
||||
smart_rename = "grr" -- mapping to rename reference under cursor
|
||||
},
|
||||
navigation = {
|
||||
enable = true,
|
||||
goto_definition = "gnd", -- mapping to go to definition of symbol under cursor
|
||||
list_definitions = "gnD" -- mapping to list all definitions in current file
|
||||
}
|
||||
},
|
||||
textobjects = { -- syntax-aware textobjects
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
disable = {},
|
||||
keymaps = {
|
||||
["iL"] = { -- you can define your own textobjects directly here
|
||||
python = "(function_definition) @function",
|
||||
cpp = "(function_definition) @function",
|
||||
c = "(function_definition) @function",
|
||||
java = "(method_declaration) @function"
|
||||
},
|
||||
-- or you use the queries from supported languages with textobjects.scm
|
||||
["af"] = "@function.outer",
|
||||
["if"] = "@function.inner",
|
||||
["aC"] = "@class.outer",
|
||||
["iC"] = "@class.inner",
|
||||
["ac"] = "@conditional.outer",
|
||||
["ic"] = "@conditional.inner",
|
||||
["ae"] = "@block.outer",
|
||||
["ie"] = "@block.inner",
|
||||
["al"] = "@loop.outer",
|
||||
["il"] = "@loop.inner",
|
||||
["is"] = "@statement.inner",
|
||||
["as"] = "@statement.outer",
|
||||
["ad"] = "@comment.outer",
|
||||
["am"] = "@call.outer",
|
||||
["im"] = "@call.inner"
|
||||
disable = { 'cpp', 'lua' },
|
||||
keymaps = { -- mappings for incremental selection (visual mappings)
|
||||
init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
|
||||
node_incremental = "grn", -- increment to the upper named parent
|
||||
scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm)
|
||||
node_decremental = "grm", -- decrement to the previous node
|
||||
}
|
||||
},
|
||||
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
|
||||
},
|
||||
refactor = {
|
||||
highlight_definitions = {
|
||||
enable = true
|
||||
},
|
||||
highlight_current_scope = {
|
||||
enable = true
|
||||
},
|
||||
smart_rename = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
smart_rename = "grr" -- mapping to rename reference under cursor
|
||||
}
|
||||
},
|
||||
navigation = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
goto_definition = "gnd", -- mapping to go to definition of symbol under cursor
|
||||
list_definitions = "gnD" -- mapping to list all definitions in current file
|
||||
}
|
||||
}
|
||||
},
|
||||
textobjects = { -- syntax-aware textobjects
|
||||
enable = true,
|
||||
disable = {},
|
||||
keymaps = {
|
||||
["iL"] = { -- you can define your own textobjects directly here
|
||||
python = "(function_definition) @function",
|
||||
cpp = "(function_definition) @function",
|
||||
c = "(function_definition) @function",
|
||||
java = "(method_declaration) @function"
|
||||
},
|
||||
-- or you use the queries from supported languages with textobjects.scm
|
||||
["af"] = "@function.outer",
|
||||
["if"] = "@function.inner",
|
||||
["aC"] = "@class.outer",
|
||||
["iC"] = "@class.inner",
|
||||
["ac"] = "@conditional.outer",
|
||||
["ic"] = "@conditional.inner",
|
||||
["ae"] = "@block.outer",
|
||||
["ie"] = "@block.inner",
|
||||
["al"] = "@loop.outer",
|
||||
["il"] = "@loop.inner",
|
||||
["is"] = "@statement.inner",
|
||||
["as"] = "@statement.outer",
|
||||
["ad"] = "@comment.outer",
|
||||
["am"] = "@call.outer",
|
||||
["im"] = "@call.inner"
|
||||
}
|
||||
},
|
||||
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
|
||||
}
|
||||
EOF
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
USER QUERY EXTENSIONS *nvim-treesitter-query-extensions*
|
||||
USER QUERY EXTENSIONS *nvim-treesitter-query-extensions*
|
||||
|
||||
You can add your own query files by placing a query file in vim's runtime path
|
||||
after `nvim-treesitter` is sourced. If the language has a built in query file,
|
||||
|
|
@ -107,28 +115,33 @@ to the runtime path by adding this to your vim config `set rtp+='path/to/queries
|
|||
|
||||
|
||||
==============================================================================
|
||||
COMMANDS *nvim-treesitter-commands*
|
||||
COMMANDS *nvim-treesitter-commands*
|
||||
|
||||
|:TSInstall| {language} ... *:TSInstall*
|
||||
*:TSInstall*
|
||||
:TSInstall| {language} ...~
|
||||
|
||||
Install one or more treesitter parsers.
|
||||
You can use |:TSInstall| `all` to install all parsers.
|
||||
|
||||
|:TSInstallInfo| *:TSInstallInfo*
|
||||
*:TSInstallInfo*
|
||||
:TSInstallInfo~
|
||||
|
||||
List informations about currently installed parsers
|
||||
|
||||
|:TSBufEnable| {module} *:TSBufEnable*
|
||||
*:TSBufEnable*
|
||||
:TSBufEnable {module}~
|
||||
|
||||
Enable {module} on the current buffer.
|
||||
A list of modules can be found at |:TSModuleInfo|
|
||||
|
||||
|:TSBufDisable| {module} *:TSBufDisable*
|
||||
*:TSBufDisable*
|
||||
:TSBufDisable {module}~
|
||||
|
||||
Disable {module} on the current buffer
|
||||
A list of modules can be found at |:TSModuleInfo|
|
||||
|
||||
|:TSBufEnableAll| {module} [{language}] *:TSBufEnableAll*
|
||||
*:TSBufEnableAll*
|
||||
:TSBufEnableAll {module} [{language}]~
|
||||
|
||||
Enable {module} for the session
|
||||
if {language} is specified, enable module for the session only for this
|
||||
|
|
@ -136,7 +149,8 @@ particular language.
|
|||
A list of modules can be found at |:TSModuleInfo|
|
||||
A list of languages can be found at |:TSInstallInfo|
|
||||
|
||||
|:TSBufDisableAll| {module} [{language}] *:TSBufDisableAll*
|
||||
*:TSBufDisableAll*
|
||||
:TSBufDisableAll {module} [{language}]~
|
||||
|
||||
Disable {module} for the session
|
||||
if {language} is specified, disable module for the session only for this
|
||||
|
|
@ -144,76 +158,98 @@ particular language.
|
|||
A list of modules can be found at |:TSModuleInfo|
|
||||
A list of languages can be found at |:TSInstallInfo|
|
||||
|
||||
|:TSModuleInfo| [{module}] *:TSModuleInfo*
|
||||
*:TSModuleInfo*
|
||||
:TSModuleInfo [{module}]~
|
||||
|
||||
List modules state for the current session.
|
||||
|
||||
==============================================================================
|
||||
UTILS *nvim-treesitter-utils*
|
||||
UTILS *nvim-treesitter-utils*
|
||||
|
||||
Nvim treesitter has some wrapper functions that you can retrieve with:
|
||||
>
|
||||
local ts_utils = require 'nvim-treesitter.ts_utils'
|
||||
<
|
||||
Methods
|
||||
*ts_utils.get_node_at_cursor*
|
||||
get_node_at_cursor(winnr)~
|
||||
|
||||
get_node_at_cursor(winnr) *ts_utils.get_node_at_cursor*
|
||||
winnr will be 0 if nil
|
||||
returns the node under the cursor
|
||||
`winnr` will be 0 if nil.
|
||||
Returns the node under the cursor.
|
||||
|
||||
get_node_text(node, bufnr) *ts_utils.get_node_text*
|
||||
return the text content of a node
|
||||
*ts_utils.get_node_text*
|
||||
get_node_text(node, bufnr)~
|
||||
|
||||
is_parent(dest, source) *ts_utils.is_parent*
|
||||
determines wether `dest` is a parent of `source`
|
||||
return a boolean
|
||||
Returns the text content of a `node`.
|
||||
|
||||
get_named_children(node) *ts_utils.get_named_children*
|
||||
return a table of named children of `node`
|
||||
*ts_utils.is_parent*
|
||||
is_parent(dest, source)~
|
||||
|
||||
get_next_node(node, allow_switch_parent, allow_next_parent) *ts_utils.get_next_node*
|
||||
return the next node within the same parent.
|
||||
if no node is found, returns `nil`.
|
||||
if `allow_switch_parent` is true, it will allow switching parent
|
||||
when the node is the last node
|
||||
if `allow_next_parent` is true, it will allow next parent if
|
||||
the node is the last node and the next parent doesn't have children.
|
||||
Determines whether `dest` is a parent of `source`.
|
||||
Returns a boolean.
|
||||
|
||||
get_previous_node(node, allow_switch_parents, allow_prev_parent) *ts_utils.get_previous_node*
|
||||
return the previous node within the same parent.
|
||||
`allow_switch_parent` and `allow_prev_parent` follow the same rule
|
||||
as |ts_utils.get_next_node| but if the node is the first node.
|
||||
*ts_utils.get_named_children*
|
||||
get_named_children(node)~
|
||||
|
||||
containing_scope(node) *ts_utils.containing_scope*
|
||||
return the smallest scope containing the node
|
||||
Returns a table of named children of `node`.
|
||||
|
||||
parent_scope(node, cursor_pos) *ts_utils.parent_scope*
|
||||
return the parent scope of the current scope that contains the node.
|
||||
`cursor_pos` should be `{ row = number, col = number }`
|
||||
*ts_utilsiget_next_node*
|
||||
get_next_node(node, allow_switch_parent, allow_next_parent)~
|
||||
|
||||
nested_scope(node, cursor_pos) *ts_utils.nested_scope*
|
||||
return the first scope within current scope that contains the node.
|
||||
`cursor_pos` should be `{ row = number, col = number }`
|
||||
Returns the next node within the same parent.
|
||||
If no node is found, returns `nil`.
|
||||
If `allow_switch_parent` is true, it will allow switching parent
|
||||
when the node is the last node.
|
||||
If `allow_next_parent` is true, it will allow next parent if
|
||||
the node is the last node and the next parent doesn't have children.
|
||||
|
||||
next_scope(node) *ts_utils.next_scope*
|
||||
return the neighbour scope of the current node
|
||||
*ts_utils.get_previous_node*
|
||||
get_previous_node(node, allow_switch_parents, allow_prev_parent)~
|
||||
|
||||
previous_scope(node) *ts_utils.previous_scope*
|
||||
return the previous neighbour scope of the current node
|
||||
Returns the previous node within the same parent.
|
||||
`allow_switch_parent` and `allow_prev_parent` follow the same rule
|
||||
as |ts_utils.get_next_node| but if the node is the first node.
|
||||
|
||||
*ts_utils.containing_scope*
|
||||
containing_scope(node)~
|
||||
|
||||
Returns the smallest scope containing the node.
|
||||
|
||||
*ts_utils.parent_scope*
|
||||
parent_scope(node, cursor_pos)~
|
||||
|
||||
Returns the parent scope of the current scope that contains the node.
|
||||
`cursor_pos` should be `{ row = number, col = number }`
|
||||
|
||||
*ts_utils.nested_scope*
|
||||
nested_scope(node, cursor_pos)~
|
||||
|
||||
Returns the first scope within current scope that contains the node.
|
||||
`cursor_pos` should be `{ row = number, col = number }`
|
||||
|
||||
*ts_utils.next_scope*
|
||||
next_scope(node)~
|
||||
|
||||
Returns the neighbour scope of the current node.
|
||||
|
||||
*ts_utils.previous_scope*
|
||||
previous_scope(node)~
|
||||
|
||||
Returns the previous neighbour scope of the current node.
|
||||
|
||||
==============================================================================
|
||||
FUNCTIONS *nvim-treesitter-functions*
|
||||
FUNCTIONS *nvim-treesitter-functions*
|
||||
|
||||
|nvim_treesitter#statusline(size)|
|
||||
*nvim_treesitter#statusline()*
|
||||
nvim_treesitter#statusline(size)~
|
||||
|
||||
Returns a string describing the current position in the syntax tree. This
|
||||
could be used as a statusline indicator.
|
||||
Note: The `size` argument is optionnal. When specified, the string will not be
|
||||
longer than `size`.
|
||||
|
||||
|nvim_treesitter#foldexpr()|
|
||||
*nvim_treesitter#foldexpr()*
|
||||
nvim_treesitter#foldexpr()~
|
||||
|
||||
Functions to be used to determine the fold level at a given line number.
|
||||
To use it: >
|
||||
|
|
@ -228,7 +264,7 @@ Note: This is highly experimental, and folding can break on some types of
|
|||
HIGHLIGHTS *nvim-treesitter-highlights*
|
||||
|
||||
`TSError`
|
||||
*hl-TSError*
|
||||
*hl-TSError*
|
||||
For syntax/parser errors.
|
||||
|
||||
You can deactivate highlighting of syntax errors by adding this to your
|
||||
|
|
@ -389,4 +425,4 @@ Literal text.
|
|||
*hl-TSURI*
|
||||
Any URI like a link or email.
|
||||
|
||||
vim:tw=78:ts=8:noet:ft=help:norl:
|
||||
vim:tw=78:ts=8:noet:ft=help:norl:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue