Docs: format and fixes

Format the docs to be consisted and some typos.
This commit is contained in:
Santos Gallegos 2020-07-27 09:23:42 -05:00 committed by Thomas Vigouroux
parent 1301884e97
commit 6f9e5bf23f
3 changed files with 235 additions and 176 deletions

View file

@ -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! room, so we can help you with any question you might have!
As you know, `nvim-treesitter` is roughly splitted in two parts : 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. 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 ## Adding new modules
If you want to see a new functionality added to `nvim-treesitter` feel free to first open an issue 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: 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`. - Little modules (like `incremental selection`) that are built in `nvim-treesitter`, we call them
- Bigger modules (like `completion-treesitter`, or `nvim-tree-docs`), or modules that integrate `builtin modules`.
with other plugins, that we call `remote 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 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). 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. 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`: 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. For both of these types there is a *norm* you will have to follow so that features work fine.
Here are some global advices : 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 your language is listed [here](https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries),
- If not, you should consider installing the [tree-sitter cli](https://github.com/tree-sitter/tree-sitter/tree/master/cli), you can debug and experiment with your queries there.
you should then be able to open a local playground using `tree-sitter build-wasm && tree-sitter web-ui` within the - If not, you should consider installing the [tree-sitter cli](https://github.com/tree-sitter/tree-sitter/tree/master/cli),
parsers repo. you should then be able to open a local playground using `tree-sitter build-wasm && tree-sitter web-ui` within the
- An Example of somewhat complex highlight queries can be found in queries/ruby/highlights.scm (Maintained by @TravonteD) parsers repo.
- An Example of somewhat complex highlight queries can be found in queries/ruby/highlights.scm (Maintained by @TravonteD)
### Highlights ### 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 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. effect on highlighting. We will work on improving highlighting in the near future though.
#### Misc #### Misc
``` ```
@comment @comment
@error for error (ERROR` nodes. @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 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. are optional and will not have any effect for now.
``` ```
@embedded @embedded
@injection @injection
language language
content content
``` ```
#### Constants #### Constants
``` ```
@constant @constant
builtin builtin
@ -96,6 +103,7 @@ are optional and will not have any effect for now.
``` ```
#### Functions #### Functions
``` ```
@function @function
builtin builtin
@ -109,6 +117,7 @@ are optional and will not have any effect for now.
``` ```
#### Keywords #### Keywords
``` ```
@conditional @conditional
@repeat @repeat
@ -161,4 +170,3 @@ Mainly for markup languages.
@scope @scope
@reference @reference
``` ```

119
README.md
View file

@ -4,7 +4,9 @@ Traditionnal highlighting (left) vs Treesitter-based highlighting (right).
[![Gitter](https://badges.gitter.im/nvim-treesitter/community.svg)](https://gitter.im/nvim-treesitter/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Gitter](https://badges.gitter.im/nvim-treesitter/community.svg)](https://gitter.im/nvim-treesitter/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
![Linting and style checking](https://github.com/nvim-treesitter/nvim-treesitter/workflows/Linting%20and%20style%20checking/badge.svg?branch=master) ![Linting and style checking](https://github.com/nvim-treesitter/nvim-treesitter/workflows/Linting%20and%20style%20checking/badge.svg?branch=master)
![Check loading of syntax files](https://github.com/nvim-treesitter/nvim-treesitter/workflows/Check%20loading%20of%20syntax%20files/badge.svg) ![Check loading of syntax files](https://github.com/nvim-treesitter/nvim-treesitter/workflows/Check%20loading%20of%20syntax%20files/badge.svg)
# nvim-treesitter # nvim-treesitter
Treesitter configurations and abstraction layer for Neovim. Treesitter configurations and abstraction layer for Neovim.
**Warning: Treesitter and Treesitter highlighting are an experimental feature of nightly versions of 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 # Quickstart
## Requirements ## Requirements
- Neovim [nightly](https://github.com/neovim/neovim#install-from-source)
- `git` in your path. - Neovim [nightly](https://github.com/neovim/neovim#install-from-source)
- A C compiler in your path. - `git` in your path.
- A C compiler in your path.
## Installation ## Installation
@ -24,6 +27,7 @@ You can install `nvim-treesitter` with your favorite package manager, or using t
### Using a package manager ### Using a package manager
Simply add these lines to your `init.vim` : Simply add these lines to your `init.vim` :
```vim ```vim
Plug 'nvim-treesitter/nvim-treesitter' Plug 'nvim-treesitter/nvim-treesitter'
``` ```
@ -31,6 +35,7 @@ Plug 'nvim-treesitter/nvim-treesitter'
### Using neovim `pack` feature ### Using neovim `pack` feature
We highly recommend reading `:h packages` to learn more about this feature, but you can still follow these steps: We highly recommend reading `:h packages` to learn more about this feature, but you can still follow these steps:
```sh ```sh
$ mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start $ mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start
$ cd ~/.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. - `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: Let's say you need parsers for `lua`, `c`, and `python`, this is how you do with these commands:
```vim ```vim
:TSInstall c :TSInstall c
Downloading... Downloading...
@ -63,6 +69,7 @@ Treesitter parser for python has been installed
``` ```
Cool, lets see which parsers are installed: Cool, lets see which parsers are installed:
```vim ```vim
:TSInstallInfo :TSInstallInfo
csharp [✗] not installed csharp [✗] not installed
@ -91,27 +98,27 @@ And now you should be able to use every functionality `nvim-treesitter` provides
## Setup ## Setup
in your `init.vim`: In your `init.vim`:
```lua ```lua
lua <<EOF lua <<EOF
require'nvim-treesitter.configs'.setup { require'nvim-treesitter.configs'.setup {
highlight = { highlight = {
enable = true, -- false will disable the whole extension enable = true, -- false will disable the whole extension
disable = { 'c', 'rust' }, -- list of language that will be disabled disable = { 'c', 'rust' }, -- list of language that will be disabled
custom_captures = { -- mapping of user defined captures to highlight groups 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 -- ["foo.bar"] = "Identifier" -- highlight own capture @foo.bar with highlight group "Identifier", see :h nvim-treesitter-query-extensions
}, },
}, },
incremental_selection = { incremental_selection = {
enable = true, enable = true,
disable = { 'cpp', 'lua' }, disable = { 'cpp', 'lua' },
keymaps = { -- mappings for incremental selection (visual mappings) keymaps = { -- mappings for incremental selection (visual mappings)
init_selection = 'gnn', -- maps in normal mode to init the node/scope selection init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
node_incremental = "grn", -- increment to the upper named parent node_incremental = "grn", -- increment to the upper named parent
scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm) scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm)
node_decremental = "grm", -- decrement to the previous node node_decremental = "grm", -- decrement to the previous node
} }
}, },
refactor = { refactor = {
highlight_definitions = { highlight_definitions = {
@ -123,44 +130,44 @@ require'nvim-treesitter.configs'.setup {
smart_rename = { smart_rename = {
enable = true, enable = true,
keymaps = { keymaps = {
smart_rename = "grr" -- mapping to rename reference under cursor smart_rename = "grr" -- mapping to rename reference under cursor
} }
}, },
navigation = { navigation = {
enable = true, enable = true,
keymaps = { keymaps = {
goto_definition = "gnd", -- mapping to go to definition of symbol under cursor goto_definition = "gnd", -- mapping to go to definition of symbol under cursor
list_definitions = "gnD" -- mapping to list all definitions in current file list_definitions = "gnD" -- mapping to list all definitions in current file
} }
} }
}, },
textobjects = { -- syntax-aware textobjects textobjects = { -- syntax-aware textobjects
enable = true, enable = true,
disable = {}, disable = {},
keymaps = { keymaps = {
["iL"] = { -- you can define your own textobjects directly here ["iL"] = { -- you can define your own textobjects directly here
python = "(function_definition) @function", python = "(function_definition) @function",
cpp = "(function_definition) @function", cpp = "(function_definition) @function",
c = "(function_definition) @function", c = "(function_definition) @function",
java = "(method_declaration) @function" java = "(method_declaration) @function"
}, },
-- or you use the queries from supported languages with textobjects.scm -- or you use the queries from supported languages with textobjects.scm
["af"] = "@function.outer", ["af"] = "@function.outer",
["if"] = "@function.inner", ["if"] = "@function.inner",
["aC"] = "@class.outer", ["aC"] = "@class.outer",
["iC"] = "@class.inner", ["iC"] = "@class.inner",
["ac"] = "@conditional.outer", ["ac"] = "@conditional.outer",
["ic"] = "@conditional.inner", ["ic"] = "@conditional.inner",
["ae"] = "@block.outer", ["ae"] = "@block.outer",
["ie"] = "@block.inner", ["ie"] = "@block.inner",
["al"] = "@loop.outer", ["al"] = "@loop.outer",
["il"] = "@loop.inner", ["il"] = "@loop.inner",
["is"] = "@statement.inner", ["is"] = "@statement.inner",
["as"] = "@statement.outer", ["as"] = "@statement.outer",
["ad"] = "@comment.outer", ["ad"] = "@comment.outer",
["am"] = "@call.outer", ["am"] = "@call.outer",
["im"] = "@call.inner" ["im"] = "@call.inner"
} }
}, },
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
} }
@ -170,6 +177,7 @@ EOF
## Commands ## Commands
Each feature can be enabled or disabled by different means: Each feature can be enabled or disabled by different means:
```vim ```vim
:TSBufEnable {module} " enable module on current buffer :TSBufEnable {module} " enable module on current buffer
:TSBufDisable {module} " disable 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, 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: but also to add some functionalities to it:
Some of these features are : Some of these features are :
- [x] Incremental selection
- [x] Syntax based code folding (`set foldmethod=expr foldexpr=nvim_treesitter#foldexpr()`) - [x] Incremental selection
- [x] Consistent syntax highlighting (the api is not quite stable yet) - [x] Syntax based code folding (`set foldmethod=expr foldexpr=nvim_treesitter#foldexpr()`)
- [x] Statusline indicator (`require'nvim-treesitter'.statusline(size)`) - [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). 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! 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. - `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. - `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. - `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. - `detach`: A function that detaches from a buffer. This is required if `module_path` is not provided.
## Utils ## Utils
you can get some utility functions with you can get some utility functions with
```lua ```lua
local ts_utils = require 'nvim-treesitter.ts_utils' 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'`. You can also manually add query paths to the runtime path by adding this to your vim config `set rtp+='path/to/queries'`.
## Troubleshooting ## Troubleshooting
Before doing anything run `:checkhealth nvim_treesitter`. This will help you find where the bug might come from. 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`... ### Feature `X` does not work for language `Y`...
First, check the `## Y parser healthcheck` section of `:checkhealth` if you have any warning. 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 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. 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. \ 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: 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 ```vim
:write | edit | TSBufEnable highlight :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.

View file

@ -5,13 +5,13 @@ Minimum version of neovim: nightly
Authors: Yazdani Kiyan <yazdani.kiyan@protonmail.com>, Vigouroux Thomas <tomvig38@gmail.com> 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 nvim-treesitter wraps the neovim treesitter api to provide functionnalities such
as highlighting and incremental selection, and a command to easily install parsers. 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 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 lua <<EOF
require'nvim-treesitter.configs'.setup { require'nvim-treesitter.configs'.setup {
highlight = { highlight = {
enable = true, -- false will disable the whole extension enable = true, -- false will disable the whole extension
disable = { 'c', 'rust' }, -- list of language that will be disabled disable = { 'c', 'rust' }, -- list of language that will be disabled
custom_captures = { -- mapping of user defined captures to highlight groups 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 -- ["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
}, },
smart_rename = { incremental_selection = {
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
enable = true, enable = true,
disable = {}, disable = { 'cpp', 'lua' },
keymaps = { keymaps = { -- mappings for incremental selection (visual mappings)
["iL"] = { -- you can define your own textobjects directly here init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
python = "(function_definition) @function", node_incremental = "grn", -- increment to the upper named parent
cpp = "(function_definition) @function", scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm)
c = "(function_definition) @function", node_decremental = "grm", -- decrement to the previous node
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 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 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 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, 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. Install one or more treesitter parsers.
You can use |:TSInstall| `all` to install all parsers. You can use |:TSInstall| `all` to install all parsers.
|:TSInstallInfo| *:TSInstallInfo* *:TSInstallInfo*
:TSInstallInfo~
List informations about currently installed parsers List informations about currently installed parsers
|:TSBufEnable| {module} *:TSBufEnable* *:TSBufEnable*
:TSBufEnable {module}~
Enable {module} on the current buffer. Enable {module} on the current buffer.
A list of modules can be found at |:TSModuleInfo| A list of modules can be found at |:TSModuleInfo|
|:TSBufDisable| {module} *:TSBufDisable* *:TSBufDisable*
:TSBufDisable {module}~
Disable {module} on the current buffer Disable {module} on the current buffer
A list of modules can be found at |:TSModuleInfo| A list of modules can be found at |:TSModuleInfo|
|:TSBufEnableAll| {module} [{language}] *:TSBufEnableAll* *:TSBufEnableAll*
:TSBufEnableAll {module} [{language}]~
Enable {module} for the session Enable {module} for the session
if {language} is specified, enable module for the session only for this 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 modules can be found at |:TSModuleInfo|
A list of languages can be found at |:TSInstallInfo| A list of languages can be found at |:TSInstallInfo|
|:TSBufDisableAll| {module} [{language}] *:TSBufDisableAll* *:TSBufDisableAll*
:TSBufDisableAll {module} [{language}]~
Disable {module} for the session Disable {module} for the session
if {language} is specified, disable module for the session only for this 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 modules can be found at |:TSModuleInfo|
A list of languages can be found at |:TSInstallInfo| A list of languages can be found at |:TSInstallInfo|
|:TSModuleInfo| [{module}] *:TSModuleInfo* *:TSModuleInfo*
:TSModuleInfo [{module}]~
List modules state for the current session. 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: Nvim treesitter has some wrapper functions that you can retrieve with:
> >
local ts_utils = require 'nvim-treesitter.ts_utils' local ts_utils = require 'nvim-treesitter.ts_utils'
< <
Methods 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.
winnr will be 0 if nil Returns the node under the cursor.
returns the node under the cursor
get_node_text(node, bufnr) *ts_utils.get_node_text* *ts_utils.get_node_text*
return the text content of a node get_node_text(node, bufnr)~
is_parent(dest, source) *ts_utils.is_parent* Returns the text content of a `node`.
determines wether `dest` is a parent of `source`
return a boolean
get_named_children(node) *ts_utils.get_named_children* *ts_utils.is_parent*
return a table of named children of `node` is_parent(dest, source)~
get_next_node(node, allow_switch_parent, allow_next_parent) *ts_utils.get_next_node* Determines whether `dest` is a parent of `source`.
return the next node within the same parent. Returns a boolean.
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.
get_previous_node(node, allow_switch_parents, allow_prev_parent) *ts_utils.get_previous_node* *ts_utils.get_named_children*
return the previous node within the same parent. get_named_children(node)~
`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.
containing_scope(node) *ts_utils.containing_scope* Returns a table of named children of `node`.
return the smallest scope containing the node
parent_scope(node, cursor_pos) *ts_utils.parent_scope* *ts_utilsiget_next_node*
return the parent scope of the current scope that contains the node. get_next_node(node, allow_switch_parent, allow_next_parent)~
`cursor_pos` should be `{ row = number, col = number }`
nested_scope(node, cursor_pos) *ts_utils.nested_scope* Returns the next node within the same parent.
return the first scope within current scope that contains the node. If no node is found, returns `nil`.
`cursor_pos` should be `{ row = number, col = number }` 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* *ts_utils.get_previous_node*
return the neighbour scope of the current node get_previous_node(node, allow_switch_parents, allow_prev_parent)~
previous_scope(node) *ts_utils.previous_scope* Returns the previous node within the same parent.
return the previous neighbour scope of the current node `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()*
nvim_treesitter#statusline(size)~
Returns a string describing the current position in the syntax tree. This Returns a string describing the current position in the syntax tree. This
could be used as a statusline indicator. could be used as a statusline indicator.
Note: The `size` argument is optionnal. When specified, the string will not be Note: The `size` argument is optionnal. When specified, the string will not be
longer than `size`. longer than `size`.
|nvim_treesitter#foldexpr()|
*nvim_treesitter#foldexpr()* *nvim_treesitter#foldexpr()*
nvim_treesitter#foldexpr()~
Functions to be used to determine the fold level at a given line number. Functions to be used to determine the fold level at a given line number.
To use it: > To use it: >
@ -228,7 +264,7 @@ Note: This is highly experimental, and folding can break on some types of
HIGHLIGHTS *nvim-treesitter-highlights* HIGHLIGHTS *nvim-treesitter-highlights*
`TSError` `TSError`
*hl-TSError* *hl-TSError*
For syntax/parser errors. For syntax/parser errors.
You can deactivate highlighting of syntax errors by adding this to your You can deactivate highlighting of syntax errors by adding this to your
@ -389,4 +425,4 @@ Literal text.
*hl-TSURI* *hl-TSURI*
Any URI like a link or email. 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: