Home Explore Blog CI



neovim

9th chunk of `runtime/doc/treesitter.txt`
3aa56898f9692adc2bf54989d22f3d710cd2b37be422775a0000000100000fc4
 tags
    • PHP files, which can contain HTML between the `<php` tags
    • JavaScript files, which contain regular expression syntax within regex
      literals
    • Ruby, which can contain snippets of code inside of heredoc literals,
      where the heredoc delimiter often indicates the language
    • Lua, which can contain snippets of Vimscript inside |vim.cmd()| calls.
    • Vimscript, which can contain snippets of Lua inside |:lua-heredoc|
      blocks.

All of these examples can be modeled in terms of a parent syntax tree and one
or more injected syntax trees, which reside inside of certain nodes in the
parent tree. The language injection query allows you to specify these
“injections” using the following captures:

    • `@injection.content` - indicates that the captured node should have its
      contents re-parsed using another language. If there are multiple
      `@injection.content` captures in one pattern, all ranges will be
      collected and parsed as one tree. This allows query authors to create
      "scoped" injections with injection query quantifiers.
    • `@injection.language` - indicates that the captured node’s text may
      contain the name of a language that should be used to re-parse the
      `@injection.content`.
    • `@injection.filename` - indicates that the captured node’s text may
      contain a filename; the corresponding filetype is then looked-up up via
      |vim.filetype.match()| and treated as the name of a language that should
      be used to re-parse the `@injection.content`.

The language injection behavior can also be configured by some properties
associated with patterns:

    • `injection.language` - can be used to hard-code the name of a specific
    language.
    • `injection.combined` - indicates that all of the matching nodes in the
    tree should have their content parsed as one nested document.
    • `injection.include-children` - indicates that the `@injection.content`
    node's entire text should be re-parsed, including the text of its child
    nodes. By default, child nodes' text will be excluded from the injected
    document.
    • `injection.self` - indicates that the node's text should be parsed with
      the same language as the node's LanguageTree.
    • `injection.parent` - indicates that the captured node’s text should
      be parsed with the same language as the node's parent LanguageTree.

Injection queries are currently run over the entire buffer, which can be slow
for large buffers. To disable injections for, e.g.,  `c`, just place an
empty `queries/c/injections.scm` file in your 'runtimepath'.

==============================================================================
VIM.TREESITTER                                                *lua-treesitter*

The remainder of this document is a reference manual for the `vim.treesitter`
Lua module, which is the main interface for Nvim's treesitter integration.
Most of the following content is automatically generated from the function
documentation.


                                             *vim.treesitter.language_version*
The latest parser ABI version that is supported by the bundled treesitter
library.

                                     *vim.treesitter.minimum_language_version*
The earliest parser ABI version that is supported by the bundled treesitter
library.

==============================================================================
TREESITTER TREES                                    *treesitter-tree* *TSTree*

A "treesitter tree" represents the parsed contents of a buffer, which can be
used to perform further analysis. It is a |userdata| reference to an object
held by the treesitter library.

An instance `TSTree` of a treesitter tree supports the following methods.


TSTree:copy()                                                  *TSTree:copy()*
    Returns a copy of the `TSTree`.

    Return: ~
        (`TSTree`)

TSTree:root()                                                  *TSTree:root()*
  

Title: Nvim Treesitter Language Injections (Continued) and Lua API
Summary
This section continues the explanation of Treesitter language injections, detailing the captures `@injection.language` and `@injection.filename`, and pattern properties such as `injection.language`, `injection.combined`, `injection.include-children`, `injection.self`, and `injection.parent` for configuring injection behavior. It also mentions how to disable injections for specific languages. The section then introduces the `vim.treesitter` Lua module, providing an interface for Nvim's Treesitter integration and defining `vim.treesitter.language_version` and `vim.treesitter.minimum_language_version`. Finally, it introduces Treesitter trees (`TSTree`) and their methods for copying (`TSTree:copy()`) and accessing the root node (`TSTree:root()`).