Code Monkey home page Code Monkey logo

nvim-treesitter-textobjects's Introduction

nvim-treesitter

Matrix Chat Linting and Style Syntax files

Logo

Treesitter configurations and abstraction layer for Neovim.

Logo by @steelsojka

The goal of nvim-treesitter is both to provide a simple and easy way to use the interface for tree-sitter in Neovim and to provide some basic functionality such as highlighting based on it:

example-cpp

Traditional highlighting (left) vs Treesitter-based highlighting (right). More examples can be found in our gallery.

Warning: Treesitter and nvim-treesitter highlighting are an experimental feature of Neovim. Please consider the experience with this plug-in as experimental until Tree-Sitter support in Neovim is stable! We recommend using the nightly builds of Neovim if possible. You can find the current roadmap here. The roadmap and all features of this plugin are open to change, and any suggestion will be highly appreciated!

Nvim-treesitter is based on three interlocking features: language parsers, queries, and modules, where modules provide features – e.g., highlighting – based on queries for syntax objects extracted from a given buffer by language parsers. Users will generally only need to interact with parsers and modules as explained in the next section. For more detailed information on setting these up, see "Advanced setup".


Table of contents


Quickstart

Requirements

Installation

You can install nvim-treesitter with your favorite package manager (or using the native package feature of vim, see :h packages).

NOTE: This plugin is only guaranteed to work with specific versions of language parsers (as specified in the lockfile.json). When upgrading the plugin, you must make sure that all installed parsers are updated to the latest version via :TSUpdate. It is strongly recommended to automate this; e.g., if you are using vim-plug, put this in your init.vim file:

Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}

For other plugin managers such as packer.nvim, see this Installation page from the wiki (Note that this page is community maintained).

Language parsers

Treesitter uses a different parser for every language, which needs to be generated via tree-sitter-cli from a grammar.js file, then compiled to a .so library that needs to be placed in neovim's runtimepath (typically under parser/{language}.so). To simplify this, nvim-treesitter provides commands to automate this process. If the language is already supported by nvim-treesitter, you can install it with

:TSInstall <language_to_install>

This command supports tab expansion. You can also get a list of all available languages and their installation status with :TSInstallInfo. Parsers not on this list can be added manually by following the steps described under "Adding parsers" below.

To make sure a parser is at the latest compatible version (as specified in nvim-treesitter's lockfile.json), use :TSUpdate {language}. To update all parsers unconditionally, use :TSUpdate all or just :TSUpdate.

Modules

Each module provides a distinct tree-sitter-based feature such as highlighting, indentation, or folding; see :h nvim-treesitter-modules or "Available modules" below for a list of modules and their options.

Following examples assume that you are configuring neovim with lua. If you are using vimscript, see :h lua-heredoc. All modules are disabled by default and need to be activated explicitly in your init.lua, e.g., via

require'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all" (the listed parsers MUST always be installed)
  ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline" },

  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,

  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,

  -- List of parsers to ignore installing (or "all")
  ignore_install = { "javascript" },

  ---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
  -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!

  highlight = {
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = { "c", "rust" },
    -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
    disable = function(lang, buf)
        local max_filesize = 100 * 1024 -- 100 KB
        local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
        if ok and stats and stats.size > max_filesize then
            return true
        end
    end,

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

Each module can also be enabled or disabled interactively through the following commands:

:TSBufEnable {module} " enable module on current buffer
:TSBufDisable {module} " disable module on current buffer
:TSEnable {module} [{ft}] " enable module on every buffer. If filetype is specified, enable only for this filetype.
:TSDisable {module} [{ft}] " disable module on every buffer. If filetype is specified, disable only for this filetype.
:TSModuleInfo [{module}] " list information about modules state for each filetype

Check :h nvim-treesitter-commands for a list of all available commands. It may be necessary to reload the buffer (e.g., via :e) after enabling a module interactively.

Supported languages

For nvim-treesitter to support a specific feature for a specific language requires both a parser for that language and an appropriate language-specific query file for that feature.

The following is a list of languages for which a parser can be installed through :TSInstall; a checked box means that nvim-treesitter also contains queries at least for the highlight module.

Experimental parsers are parsers that have a maintainer but are not stable enough for daily use yet.

We are looking for maintainers to add more parsers and to write query files for their languages. Check our tracking issue for open language requests.

  • ada (maintained by @briot)
  • agda (maintained by @Decodetalkers)
  • angular (experimental, maintained by @dlvandenberg)
  • apex (maintained by @aheber, @xixiaofinland)
  • arduino (maintained by @ObserverOfTime)
  • asm (maintained by @RubixDev)
  • astro (maintained by @virchau13)
  • authzed (maintained by @mattpolzin)
  • awk
  • bash (maintained by @TravonteD)
  • bass (maintained by @amaanq)
  • beancount (maintained by @polarmutex)
  • bibtex (maintained by @theHamsta, @clason)
  • bicep (maintained by @amaanq)
  • bitbake (maintained by @amaanq)
  • blueprint (experimental, maintained by @gabmus)
  • bp (maintained by @ambroisie)
  • c (maintained by @amaanq)
  • c_sharp (maintained by @amaanq)
  • cairo (maintained by @amaanq)
  • capnp (maintained by @amaanq)
  • chatito (maintained by @ObserverOfTime)
  • clojure (maintained by @NoahTheDuke)
  • cmake (maintained by @uyha)
  • comment (maintained by @stsewd)
  • commonlisp (maintained by @theHamsta)
  • cooklang (maintained by @addcninblue)
  • corn (maintained by @jakestanger)
  • cpon (maintained by @amaanq)
  • cpp (maintained by @theHamsta)
  • css (maintained by @TravonteD)
  • csv (maintained by @amaanq)
  • cuda (maintained by @theHamsta)
  • cue (maintained by @amaanq)
  • d (maintained by @amaanq)
  • dart (maintained by @akinsho)
  • devicetree (maintained by @jedrzejboczar)
  • dhall (maintained by @amaanq)
  • diff (maintained by @gbprod)
  • disassembly (maintained by @ColinKennedy)
  • djot (maintained by @NoahTheDuke)
  • dockerfile (maintained by @camdencheek)
  • dot (maintained by @rydesun)
  • doxygen (maintained by @amaanq)
  • dtd (maintained by @ObserverOfTime)
  • earthfile (maintained by @glehmann)
  • ebnf (experimental, maintained by @RubixDev)
  • editorconfig (maintained by @ValdezFOmar)
  • eds (maintained by @uyha)
  • eex (maintained by @connorlay)
  • elixir (maintained by @connorlay)
  • elm (maintained by @zweimach)
  • elsa (maintained by @glapa-grossklag, @amaanq)
  • elvish (maintained by @elves)
  • embedded_template
  • erlang (maintained by @filmor)
  • facility (maintained by @bryankenote)
  • faust (maintained by @khiner)
  • fennel (maintained by @alexmozaidze)
  • fidl (maintained by @chaopeng)
  • firrtl (maintained by @amaanq)
  • fish (maintained by @ram02z)
  • foam (experimental, maintained by @FoamScience)
  • forth (maintained by @amaanq)
  • fortran (maintained by @amaanq)
  • fsh (maintained by @mgramigna)
  • func (maintained by @amaanq)
  • fusion (maintained by @jirgn)
  • GAP system (maintained by @reiniscirpons)
  • GAP system test files (maintained by @reiniscirpons)
  • Godot (gdscript) (maintained by @PrestonKnopp)
  • gdshader (maintained by @godofavacyn)
  • git_config (maintained by @amaanq)
  • git_rebase (maintained by @gbprod)
  • gitattributes (maintained by @ObserverOfTime)
  • gitcommit (maintained by @gbprod)
  • gitignore (maintained by @theHamsta)
  • gleam (maintained by @amaanq)
  • Glimmer and Ember (maintained by @NullVoxPopuli)
  • glimmer_javascript (maintained by @NullVoxPopuli)
  • glimmer_typescript (maintained by @NullVoxPopuli)
  • glsl (maintained by @theHamsta)
  • GN (Generate Ninja) (maintained by @amaanq)
  • gnuplot (maintained by @dpezto)
  • go (maintained by @theHamsta, @WinWisely268)
  • goctl (maintained by @chaozwn)
  • Godot Resources (gdresource) (maintained by @pierpo)
  • gomod (maintained by @camdencheek)
  • gosum (maintained by @amaanq)
  • gotmpl (maintained by @qvalentin)
  • gowork (maintained by @omertuc)
  • gpg (maintained by @ObserverOfTime)
  • graphql (maintained by @bkegley)
  • groovy (maintained by @murtaza64)
  • gstlaunch (maintained by @theHamsta)
  • hack
  • hare (maintained by @amaanq)
  • haskell (maintained by @mrcjkb)
  • haskell_persistent (maintained by @lykahb)
  • hcl (maintained by @MichaHoffmann)
  • heex (maintained by @connorlay)
  • helm (maintained by @qvalentin)
  • hjson (maintained by @winston0410)
  • hlsl (maintained by @theHamsta)
  • hlsplaylist (maintained by @Freed-Wu)
  • hocon (maintained by @antosha417)
  • hoon (experimental, maintained by @urbit-pilled)
  • html (maintained by @TravonteD)
  • htmldjango (experimental, maintained by @ObserverOfTime)
  • http (maintained by @amaanq, @NTBBloodbath)
  • hurl (maintained by @pfeiferj)
  • hyprlang (maintained by @luckasRanarison)
  • idl (maintained by @cathaysia)
  • ini (experimental, maintained by @theHamsta)
  • inko (maintained by @yorickpeterse)
  • ispc (maintained by @fab4100)
  • janet_simple (maintained by @sogaiu)
  • java (maintained by @p00f)
  • javascript (maintained by @steelsojka)
  • jq (maintained by @ObserverOfTime)
  • jsdoc (maintained by @steelsojka)
  • json (maintained by @steelsojka)
  • json5 (maintained by @Joakker)
  • JSON with comments (maintained by @WhyNotHugo)
  • jsonnet (maintained by @nawordar)
  • julia (maintained by @theHamsta)
  • just (maintained by @Hubro)
  • kconfig (maintained by @amaanq)
  • kdl (maintained by @amaanq)
  • kotlin (maintained by @SalBakraa)
  • koto (maintained by @irh)
  • kusto (maintained by @Willem-J-an)
  • lalrpop (maintained by @traxys)
  • latex (maintained by @theHamsta, @clason)
  • ledger (maintained by @cbarrete)
  • leo (maintained by @r001)
  • linkerscript (maintained by @amaanq)
  • liquid (maintained by @hankthetank27)
  • liquidsoap (maintained by @toots)
  • llvm (maintained by @benwilliamgraham)
  • lua (maintained by @muniftanjim)
  • luadoc (maintained by @amaanq)
  • lua patterns (maintained by @amaanq)
  • luau (maintained by @amaanq)
  • m68k (maintained by @grahambates)
  • make (maintained by @lewis6991)
  • markdown (basic highlighting) (experimental, maintained by @MDeiml)
  • markdown_inline (needed for full highlighting) (experimental, maintained by @MDeiml)
  • matlab (maintained by @acristoffers)
  • menhir (maintained by @Kerl13)
  • mermaid (experimental)
  • meson (maintained by @Decodetalkers)
  • mlir (experimental, maintained by @artagnon)
  • muttrc (maintained by @Freed-Wu)
  • nasm (maintained by @ObserverOfTime)
  • nginx (maintained by @opa-oz)
  • nickel
  • nim (maintained by @aMOPel)
  • nim_format_string (maintained by @aMOPel)
  • ninja (maintained by @alemuller)
  • nix (maintained by @leo60228)
  • norg (maintained by @JoeyGrajciar, @vhyrro)
  • nqc (maintained by @amaanq)
  • objc (maintained by @amaanq)
  • objdump (maintained by @ColinKennedy)
  • ocaml (maintained by @undu)
  • ocaml_interface (maintained by @undu)
  • ocamllex (maintained by @undu)
  • odin (maintained by @amaanq)
  • org
  • pascal (maintained by @Isopod)
  • passwd (maintained by @amaanq)
  • pem (maintained by @ObserverOfTime)
  • perl (maintained by @RabbiVeesh, @LeoNerd)
  • php (maintained by @tk-shirasaka, @calebdw)
  • php_only (maintained by @tk-shirasaka, @calebdw)
  • phpdoc (experimental, maintained by @mikehaertl)
  • pioasm (maintained by @leo60228)
  • po (maintained by @amaanq)
  • pod (maintained by @RabbiVeesh, @LeoNerd)
  • Path of Exile item filter (experimental, maintained by @ObserverOfTime)
  • pony (maintained by @amaanq, @mfelsche)
  • powershell (maintained by @L2jLiga)
  • printf (maintained by @ObserverOfTime)
  • prisma (maintained by @elianiva)
  • problog (maintained by @foxyseta)
  • prolog (maintained by @foxyseta)
  • promql (maintained by @MichaHoffmann)
  • properties (maintained by @ObserverOfTime)
  • proto (maintained by @treywood)
  • prql (maintained by @matthias-Q)
  • psv (maintained by @amaanq)
  • pug (experimental, maintained by @zealot128)
  • puppet (maintained by @amaanq)
  • purescript (maintained by @postsolar)
  • PyPA manifest (maintained by @ObserverOfTime)
  • python (maintained by @stsewd, @theHamsta)
  • ql (maintained by @pwntester)
  • qmldir (maintained by @amaanq)
  • qmljs (maintained by @Decodetalkers)
  • Tree-Sitter query language (maintained by @steelsojka)
  • r (maintained by @ribru17)
  • racket
  • ralph (maintained by @tdroxler)
  • rasi (maintained by @Fymyte)
  • rbs (maintained by @joker1007)
  • re2c (maintained by @amaanq)
  • readline (maintained by @ribru17)
  • regex (maintained by @theHamsta)
  • rego (maintained by @FallenAngel97)
  • pip requirements (maintained by @ObserverOfTime)
  • rescript (maintained by @ribru17)
  • rnoweb (maintained by @bamonroe)
  • robot (maintained by @Hubro)
  • robots (maintained by @opa-oz)
  • roc (maintained by @nat-418)
  • ron (maintained by @amaanq)
  • rst (maintained by @stsewd)
  • ruby (maintained by @TravonteD)
  • rust (maintained by @amaanq)
  • scala (maintained by @stevanmilic)
  • scfg (maintained by @WhyNotHugo)
  • scheme
  • scss (maintained by @elianiva)
  • sflog (maintained by @aheber, @xixiaofinland)
  • slang (experimental, maintained by @theHamsta)
  • slint (maintained by @hunger)
  • smali (maintained by @amaanq)
  • smithy (maintained by @amaanq, @keynmol)
  • snakemake (experimental)
  • solidity (maintained by @amaanq)
  • soql (maintained by @aheber, @xixiaofinland)
  • sosl (maintained by @aheber, @xixiaofinland)
  • sourcepawn (maintained by @Sarrus1)
  • sparql (maintained by @GordianDziwis)
  • sql (maintained by @derekstride)
  • squirrel (maintained by @amaanq)
  • ssh_config (maintained by @ObserverOfTime)
  • starlark (maintained by @amaanq)
  • strace (maintained by @amaanq)
  • styled (maintained by @mskelton)
  • supercollider (maintained by @madskjeldgaard)
  • surface (maintained by @connorlay)
  • svelte (maintained by @amaanq)
  • swift (maintained by @alex-pinkus)
  • sxhkdrc (maintained by @RaafatTurki)
  • systemtap (maintained by @ok-ryoko)
  • systemverilog (maintained by @zhangwwpeng)
  • t32 (maintained by @xasc)
  • tablegen (maintained by @amaanq)
  • tact (maintained by @novusnota)
  • tcl (maintained by @lewis6991)
  • teal (maintained by @euclidianAce)
  • templ (maintained by @vrischmann)
  • terraform (maintained by @MichaHoffmann)
  • textproto (maintained by @Porter)
  • thrift (maintained by @amaanq, @duskmoon314)
  • tiger (maintained by @ambroisie)
  • tlaplus (maintained by @ahelwer, @susliko)
  • tmux (maintained by @Freed-Wu)
  • todotxt (experimental, maintained by @arnarg)
  • toml (maintained by @tk-shirasaka)
  • tsv (maintained by @amaanq)
  • tsx (maintained by @steelsojka)
  • turtle (maintained by @GordianDziwis)
  • twig (maintained by @gbprod)
  • typescript (maintained by @steelsojka)
  • typespec (maintained by @happenslol)
  • typoscript (maintained by @Teddytrombone)
  • typst (maintained by @uben0, @RaafatTurki)
  • udev (maintained by @ObserverOfTime)
  • ungrammar (maintained by @Philipp-M, @amaanq)
  • unison (maintained by @tapegram)
  • usd (maintained by @ColinKennedy)
  • uxn tal (maintained by @amaanq)
  • v (maintained by @kkharji, @amaanq)
  • vala (maintained by @Prince781)
  • vento (maintained by @wrapperup, @oscarotero)
  • verilog (maintained by @zegervdv)
  • vhdl (maintained by @jpt13653903)
  • vhs (maintained by @caarlos0)
  • vim (maintained by @clason)
  • vimdoc (maintained by @clason)
  • vrl (maintained by @belltoy)
  • vue (maintained by @WhyNotHugo, @lucario387)
  • wgsl (maintained by @szebniok)
  • wgsl_bevy (maintained by @theHamsta)
  • wing (maintained by @gshpychka, @MarkMcCulloh)
  • wit (maintained by @liamwh)
  • xcompose (maintained by @ObserverOfTime)
  • xml (maintained by @ObserverOfTime)
  • yaml (maintained by @amaanq)
  • yang (maintained by @Hubro)
  • yuck (maintained by @Philipp-M, @amaanq)
  • zathurarc (maintained by @Freed-Wu)
  • zig (maintained by @amaanq)

For related information on the supported languages, including related plugins, see this wiki page.

Available modules

Modules provide the top-level features of nvim-treesitter. The following is a list of modules included in nvim-treesitter and their configuration via init.lua (where multiple modules can be combined in a single call to setup). Note that not all modules work for all languages (depending on the queries available for them). Additional modules can be provided as external plugins.

Highlight

Consistent syntax highlighting.

require'nvim-treesitter.configs'.setup {
  highlight = {
    enable = true,
    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

To customize the syntax highlighting of a capture, simply define or link a highlight group of the same name:

-- Highlight the @foo.bar capture group with the "Identifier" highlight group
vim.api.nvim_set_hl(0, "@foo.bar", { link = "Identifier" })

For a language-specific highlight, append the name of the language:

-- Highlight @foo.bar as "Identifier" only in Lua files
vim.api.nvim_set_hl(0, "@foo.bar.lua", { link = "Identifier" })

See :h treesitter-highlight-groups for details.

Incremental selection

Incremental selection based on the named nodes from the grammar.

require'nvim-treesitter.configs'.setup {
  incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = "gnn", -- set to `false` to disable one of the mappings
      node_incremental = "grn",
      scope_incremental = "grc",
      node_decremental = "grm",
    },
  },
}

Indentation

Indentation based on treesitter for the = operator. NOTE: This is an experimental feature.

require'nvim-treesitter.configs'.setup {
  indent = {
    enable = true
  }
}

Folding

Tree-sitter based folding (implemented in Neovim itself, see :h vim.treesitter.foldexpr()). To enable it for the current window, set

vim.wo.foldmethod = 'expr'
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'

This will respect your foldminlines and foldnestmax settings.

Advanced setup

Changing the parser install directory

If you want to install the parsers to a custom directory you can specify this directory with parser_install_dir option in that is passed to setup. nvim-treesitter will then install the parser files into this directory.

This directory must be writeable and must be explicitly prepended to the runtimepath. For example:

  -- It MUST be at the beginning of runtimepath. Otherwise the parsers from Neovim itself
  -- is loaded that may not be compatible with the queries from the 'nvim-treesitter' plugin.
  vim.opt.runtimepath:prepend("/some/path/to/store/parsers")

  require'nvim-treesitter.configs'.setup {
    parser_install_dir = "/some/path/to/store/parsers",

    ...

  }

If this option is not included in the setup options, or is explicitly set to nil then the default install directories will be used. If this value is set the default directories will be ignored.

Bear in mind that any parser installed into a parser folder on the runtime path will still be considered installed. (For example if "~/.local/share/nvim/site/parser/c.so" exists then the "c" parser will be considered installed, even though it is not in parser_install_dir)

The default paths are:

  1. first the package folder. Where nvim-treesitter is installed.
  2. second the site directory. This is the "site" subdirectory of stdpath("data").

Adding parsers

If you have a parser that is not on the list of supported languages (either as a repository on Github or in a local directory), you can add it manually for use by nvim-treesitter as follows:

  1. Clone the repository or create a new project in, say, ~/projects/tree-sitter-zimbu. Make sure that the tree-sitter-cli executable is installed and in your path; see https://tree-sitter.github.io/tree-sitter/creating-parsers#installation for installation instructions.
  2. Run tree-sitter generate in this directory (followed by tree-sitter test for good measure).
  3. Add the following snippet to your init.lua:
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.zimbu = {
  install_info = {
    url = "~/projects/tree-sitter-zimbu", -- local path or git repo
    files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
    -- optional entries:
    branch = "main", -- default branch in case of git repo if different from master
    generate_requires_npm = false, -- if stand-alone parser without npm dependencies
    requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
  },
  filetype = "zu", -- if filetype does not match the parser name
}

If you wish to set a specific parser for a filetype, you should use vim.treesitter.language.register():

vim.treesitter.language.register('python', 'someft')  -- the someft filetype will use the python parser and queries.

Note this requires Nvim v0.9.

  1. Start nvim and :TSInstall zimbu.

You can also skip step 2 and use :TSInstallFromGrammar zimbu to install directly from a grammar.js in the top-level directory specified by url. Once the parser is installed, you can update it (from the latest revision of the main branch if url is a Github repository) with :TSUpdate zimbu.

Note that neither :TSInstall nor :TSInstallFromGrammar copy query files from the grammar repository. If you want your installed grammar to be useful, you must manually add query files to your local nvim-treesitter installation. Note also that module functionality is only triggered if your language's filetype is correctly identified. If Neovim does not detect your language's filetype by default, you can use Neovim's vim.filetype.add() to add a custom detection rule.

If you use a git repository for your parser and want to use a specific version, you can set the revision key in the install_info table for you parser config.

Adding queries

Queries are what nvim-treesitter uses to extract information from the syntax tree; they are located in the queries/{language}/* runtime directories (see :h rtp), like the queries folder of this plugin, e.g. queries/{language}/{locals,highlights,textobjects}.scm. Other modules may require additional queries such as folding.scm. You can find a list of all supported capture names in CONTRIBUTING.md.

The first query file on runtimepath will be used (see :h treesitter-query). If you want to make a query on the user config extend other queries instead of replacing them, see :h treesitter-query-modeline-extends.

If you want to completely override a query, you can use :h vim.treesitter.query.set(). For example, to override the injections queries from c with your own:

vim.treesitter.query.set("c", "injections", "(comment) @comment")

Note: when using query.set(), all queries in the runtime directories will be ignored.

Adding modules

If you wish you write your own module, you need to support

  • tree-sitter language detection support;
  • attaching and detaching to buffers;
  • all nvim-treesitter commands.

At the top level, you can use the define_modules function to define one or more modules or module groups:

require'nvim-treesitter'.define_modules {
  my_cool_plugin = {
    attach = function(bufnr, lang)
      -- Do cool stuff here
    end,
    detach = function(bufnr)
      -- Undo cool stuff here
    end,
    is_supported = function(lang)
      -- Check if the language is supported
    end
  }
}

with the following properties:

  • module_path specifies a require path (string) that exports a module with an attach and detach function. This is not required if the functions are on this definition.
  • enable determines if the module is enabled by default. This is usually overridden by the user.
  • disable takes a list of languages that this module is disabled for. This is usually overridden by the user.
  • is_supported takes a function that takes a language and determines if this module supports that language.
  • attach takes a function that attaches to a buffer. This is required if module_path is not provided.
  • detach takes a function that detaches from a buffer. This is required if module_path is not provided.

Extra features

Statusline indicator

echo nvim_treesitter#statusline(90)  " 90 can be any length
module->expression_statement->call->identifier

Utilities

You can get some utility functions with

local ts_utils = require 'nvim-treesitter.ts_utils'

Check :h nvim-treesitter-utils for more information.

Troubleshooting

Before doing anything, make sure you have the latest version of this plugin and run :checkhealth nvim-treesitter. It can also help to update the parsers via :TSUpdate.

Feature X does not work for {language}...

First, check the health#nvim_treesitter#check and the health#treesitter#check sections of :checkhealth for any warning. If there is one, it's highly likely that this is the cause of the problem.

Next check the ## Parser/Features subsection of the health#nvim_treesitter#check section of :checkhealth to ensure the desired module is enabled for your language. If not, you might be missing query files; see Adding queries.

Finally, ensure Neovim is correctly identifying your language's filetype using the :echo &filetype command while one of your language's files is open in Neovim. If not, add a short Vimscript file to nvim-treesitter's ftdetect runtime directory following Neovim's documentation on filetype detection. You can also quickly & temporarily set the filetype for a single buffer with the :set filetype=langname command to test whether it fixes the problem.

If everything is okay, then it might be an actual error. In that case, feel free to open an issue here.

I get module 'vim.treesitter.query' not found

Make sure you have the latest version of Neovim.

I get Error detected while processing .../plugin/nvim-treesitter.vim every time I open Neovim

This is probably due to a change in a parser's grammar or its queries. Try updating the parser that you suspect has changed (:TSUpdate {language}) or all of them (:TSUpdate). If the error persists after updating all parsers, please open an issue.

I get query error: invalid node type at position

This could be due a query file outside this plugin using outdated nodes, or due to an outdated parser.

  • Make sure you have the parsers up to date with :TSUpdate
  • Make sure you don't have more than one parser runtime directory. You can execute this command :echo nvim_get_runtime_file('parser', v:true) to find all runtime directories. If you get more than one path, remove the ones that are outside this plugin (nvim-treesitter directory), so the correct version of the parser is used.

I experience weird highlighting issues similar to #78

This is a well known issue, which arises when the tree and the buffer have gotten out of sync. As this is an upstream issue, we don't have any definite fix. To get around this, you can force reparsing the buffer with

:write | edit | TSBufEnable highlight

This will save, restore and enable highlighting for the current buffer.

I experience bugs when using nvim-treesitter's foldexpr similar to #194

This might happen, and is known to happen, with vim-clap. To avoid these kind of errors, please use setlocal instead of set for the respective filetypes.

I run into errors like module 'nvim-treesitter.configs' not found at startup

This is because of rtp management in nvim, adding packadd nvim-treesitter should fix the issue.

I want to use Git instead of curl for downloading the parsers

In your Lua config:

require("nvim-treesitter.install").prefer_git = true

I want to use a HTTP proxy for downloading the parsers

You can either configure curl to use additional CLI arguments in your Lua config:

require("nvim-treesitter.install").command_extra_args = {
    curl = { "--proxy", "<proxy url>" },
}

or you can configure git via .gitconfig and use git instead of curl

require("nvim-treesitter.install").prefer_git = true

I want to use a mirror instead of "https://github.com/"

In your Lua config:

for _, config in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
  config.install_info.url = config.install_info.url:gsub("https://github.com/", "something else")
end

require'nvim-treesitter.configs'.setup {
    --
    --
}

Using an existing parser for another filetype

For example, to use the bash tree-sitter to highlight file with filetype=apkbuild, use:

vim.treesitter.language.register("bash", "apkbuild")

The bash tree-sitter must be installed following the usual procedure as described above.

nvim-treesitter-textobjects's People

Contributors

acksld avatar aspeddro avatar clason avatar echasnovski avatar fsouza avatar gbprod avatar genesistms avatar ghostbuster91 avatar indianboy42 avatar jacfger avatar kiyoon avatar laytan avatar luathn avatar mike325 avatar mrcjkb avatar npezza93 avatar observeroftime avatar przepompownia avatar pwntester avatar qsdrqs avatar ranjithshegde avatar ribru17 avatar rrethy avatar savq avatar sevanteri avatar simonmandlik avatar stsewd avatar swoogan avatar thehamsta avatar yochem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nvim-treesitter-textobjects's Issues

Pasting a copied parameter before/after the current parameter

I think it would be so useful to use something like this:

require'nvim-treesitter.configs'.setup {
  textobjects = {
    select = {
     enable = true,
      keymaps = {
        ["ap"] = "@parameter.outer", 
      }
    }    
  }
}

nmap <leader>P :TSPasteParameterBefore<CR>
nmap <leader>p :TSPasteParameterAfter<CR>

Then if I could take a function call like:

blah(arg1, arg2, arg3);

and hover arg2 and use dap to delete arg2.

Then hover arg1 and use a keybinding to paste the parameter I just copied before arg1 or use a different keybinding to paste the parameter after arg1 (in this case <leader>P for "before" and <leader>p for "after").

When I do dap it copies the preceding , (or sometimes the trailing ,). When pasting the code would first need to remove the preceding/trailing , and then enter a new , after the pasted parameter when pasting before the final parameter, or enter a preceding , when pasting into the final parameter position. If there are no parameters then no trailing/preceding , would be added (for languages that support trailing , after the last parameter, could leave it up to the user's code formatter to handle this but in cases where a trailing , already exists then pasting into the final parameter position should not enter the preceding ,). I'm aware there are languages that don't use , between parameters such as Haskell, for such languages it would be easier.

This might not be the direction you see nvim-treesitter-textobjects going, and if not, I'm happy to provide this support in a new plugin, but I'd be really grateful for any advice you could give me on how I might implement this.

Can't use select and yank textobjects

Describe the bug
I used python, but can't select or yank the function with keybinding such as v or y.
when put the cursor in a function, :lua print(vim.inspect(require'nvim-treesitter.query'.collect_group_results(0, 'textobject')))
return {}, but use command like :TSTextobjectSelect @function.outer visually select all function
To Reproduce
Steps to reproduce the behavior:

  1. Install plugin and python parser
  2. Put cursor in python 's function
  3. For example, press vif (which i binded if for "@function.inner") doesn't visually select inner function
    Expected behavior
    Press vif select inner function

Output of :checkhealth nvim_treesitter

Parser/Features H L F I

  • python ✓ ✓ ✓ ✓

Output of nvim --version

NVIM v0.5.0-dev+1186-g8665a96b9
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az67-513

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

Additional context
Add any other context about the problem here.

Cannot delete parameter in tsx files but works fine with ts files

Describe the bug
Does not work with tsx files, only ts

To Reproduce
Use the following configuration:

require'nvim-treesitter.configs'.setup {                                                                        
  ensure_installed = {"typescript", "tsx", "javascript"},                                            
  highlight = { enable = true },                                                                                
  textobjects = {
    select = {                                                                                                  
      enable = true,                                                                                            
      lookahead = true,
      keymaps = {
        ["af"] = "@function.outer", 
        ["if"] = "@function.inner",
        ["ac"] = "@class.outer",
        ["ic"] = "@class.inner",
        ["ap"] = "@parameter.outer",                                                                            
        ["ip"] = "@parameter.inner",                                                                            
      },                                                                                                        
    },                                                                                                          
  },                                                                                                            
}  

Open tsx file with a function definition like:

function blah(arg: string, arg2: string): string {
  return arg + arg2;
}

Put the cursor over the first a in arg: and then use dip to delete the parameter.

This will work fine in a ts file, but not at all in a tsx file.

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check
======================================================================== ## Installation

  • OK: tree-sitter found 0.20.0 (parser generator, only needed for :TSInstallFromGrammar)
  • OK: node found v14.15.4 (only needed for :TSInstallFromGrammar)
  • OK: git executable found. - OK: cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  • OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features H L F I J

  • tsx ✓ ✓ ✓ ✓ ✓
  • c_sharp ✓ ✓ ✓ . ✓
  • c ✓ ✓ ✓ ✓ ✓
  • javascript ✓ ✓ ✓ ✓ ✓
  • typescript ✓ ✓ ✓ ✓ ✓

Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.6.0-dev+43-g02bf251bb
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az87-55

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/share/nvim"

Run :checkhealth for more info

Feature request: extend swap functionality to also work on comma separated lists

nvim-treesitter-textobjects has the the ability to swap function arguments. I have previously been using vim-argumentative, which also does this (without the use of tree-sitter). However, vim-argumentative is also able to swap the positions of items in lists. For instance, with the cursor on item foo in the following example, pressing >, moves foo from the first index to the second one like so: [foo, bar, baz] --> [bar, foo, baz].

Would this be possible to impement using tree-sitter?

I personally use the following config for swap:

swap = {
  enable = true,
  swap_next = {
    ['>,'] = '@parameter.inner',
  },
  swap_previous = {
    ['<,'] = '@parameter.inner',
  }
}

What I would want is for >, to swap both parameters and list items like in my previous example.

Edit: I realized after posting that #86 is a very similar question.

Define @parameter.outer which would include punctuation

First of all, thanks for this plugin! I'm trying it out and the results are impressive!

One thing I'm missing from targets.vim is the "an argument" text object:

Select an argument in a list of arguments. Includes a separator if preset, but excludes surrounding braces. This leaves a proper argument list after deletion. Accepts a count.

      ...........
a , b ( cccccccc , d ) e
        └─── aa ──┘

As I understand the analogue could be @parameter.outer. Unfortunately I wasn't able to see how that could be defined with queries at the moment as the most grammars I've checked do not keep punctuation in the AST. Maybe some out of band solution might work where there's some post processing on the query result to find the matching comma...

Duplicate help tag

Describe the bug
Help tags are duplicated from nvim-treesitter:

Error generating helptags:
Vim(helptags):E154: Duplicate tag "nvim-treesitter-text-objects-move-submod" in file ...
$ rg nvim-treesitter-text-objects-move-submod

nvim-treesitter/nvim-treesitter/doc/nvim-treesitter.txt
356:                                    *nvim-treesitter-text-objects-move-submod*

nvim-treesitter/nvim-treesitter-textobjects/doc/nvim-treesitter-textobjects.txt
77:                                    *nvim-treesitter-text-objects-move-submod*

Allow linewise selection

Is your feature request related to a problem? Please describe.
When attempting to make linewise selection of a textobject (for example, with Vaf for function.outer) I expect it to become linewise selection. Instead it is forced to be a regular selection (like an outcome of vaf). This is a consequence of how nvim-treesitter.ts_utils.update_selection() operates: it selects exactly the textobject forcing regular visual selection.

Linewise selection is useful, for example, when you want to delete lines with indented function definition.

Describe the solution you'd like
Making explicit linewise visual selection possible.

Describe alternatives you've considered
Technically, adding extra V keystroke solves the issue: vafV forces linewise selection. However, it seems to present a little unnecessary cognitive load compared to regular vim experience.

Additional context
I will make a PR which utilizes the equivalence of expected Vaf and vafV.

Hotkey for custom query does not work

Describe the bug
Hotkey for query does not capture block.

I have this query set to fold docstrings for Python in my own little plugin so I can be certain the query captures correctly.
(function_definition body: (block (expression_statement (string) @docstring)))

I have also tested this with my plugin enabled/disabled.

I have tried this with capture groups @docstring, @comment, @comment.inner, @comment.outer

I have tried with multi line and single line string.

To Reproduce

# Python file with docstring to yank
def f():
   """ Some text
   
   With more to follow
   """
   return 3 + 3
# My configuration
require('nvim-treesitter.configs') .setup({
   ...,
   textobjects = {
     select = {
        keymaps = {
          ...,                    
          ["c"] = {
            python = "(function_definition body: (block (expression_statement (string) @comment.outer)))"
          }
        }
      }
    }
   ...,
})

Expected behavior
Using yid, the documentation block should be yanked

Output of :checkhealth nvim_treesitter

nvim_treesitter: health#nvim_treesitter#check

Installation

  • OK: tree-sitter found 0.20.0 (parser generator, only needed for :TSInstallFromGrammar)
  • WARNING: node executable not found (only needed for :TSInstallFromGrammar, not required for :TSInstall)
  • OK: git executable found.
  • OK: cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (GCC) 11.1.0
  • OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features H L F I J

  • python ✓ ✓ ✓ ✓ ✓
  • c ✓ ✓ ✓ ✓ ✓
  • lua ✓ ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓

Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.7.0-dev+734-g51306f98b
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by root@skantify

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

Additional context
Using nvim-treesitter-playground I can be certain this query highlights the documentation block.

Screenshot_2021-12-21_16-49-58

Treatment of whitespace is inconsistent/inconvenient

Consider a python snippet like the following with the cursor placed at the caret:

print( "a" , "b" , "c" )
            ^

If you try to select parameter.inner or parameter.outer, nothing will happen.

If the cursor is in a different location:

print( "a" , "b" , "c" )
                ^

Now parameter.outer will select something (the "b" parameter up to its comma, but not its leading space),
but parameter.inner still does nothing.

This is probably technically correct according to the way the syntax tree maps to tokens, but it's not very convenient for editing. You'll get similar behavior if you happen to be in whitespace for other text objects, e.g.:

def foo(bar):
    print(bar)
  ^

Here function.outer will select the entire function and body as expected, but function.inner selects nothing.

When the cursor is on whitespace, it should probably "snap" to the next non-whitespace token before looking for the surrounding text object.

different approach to defining keybindings?

Is your feature request related to a problem? Please describe.
A lot of the time when defining selections and movements, I run into conflicts with default vim bindings or other plugins. Debugging such situations is pretty tough, since the current way of configuring bindings (via the map) is opaque.

Describe the solution you'd like
Instead of creating bindings via the map, perhaps there's a way to expose the motions as commands, or some other format, where the user can assign them to bindings through a more standard mechanism, like nvim_set_keymap. For example, https://github.com/neovim/nvim-lspconfig defines a bunch of functions and asks users to create bindings via something like:

buf_set_keymap("n", "<leader>t", [[<Cmd>lua vim.lsp.buf.hover()<CR>]], opts)

I think this is pretty straightforward for things like "move" commands, but I'm not sure whether it will work for things like "select".

Defining my own textobjects as shown in docs isn't working

Describe the bug
I am unable to define custom textobjects for the select submodule.

To Reproduce
Config:

  require'nvim-treesitter.configs'.setup {
    textobjects = {
      select = {
        enable = true,
        keymaps = {
          -- Or you can define your own textobjects like this
          ["iF"] = {
            python = "(function_definition) @function",
            cpp = "(function_definition) @function",
            c = "(function_definition) @function",
            java = "(method_declaration) @function",
          },
        },
      },
    },
  }

C file:

int foo() {
}

Doing viF results in E5108: Error executing lua ...ckpack/opt/nvim-treesitter/lua/nvim-treesitter/query.lua:144: attempt to index local 'query' (a nil value).

Expected behavior

I expect the function to be selected.

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check

Installation

  • OK: tree-sitter found 0.19.4 (4e321f34a0688f2ad0ce6ec32d0700b039e8436c) (parser generator, only needed for :TSInstallFromGrammar)
  • OK: node found v12.16.3 (only needed for :TSInstallFromGrammar)
  • OK: git executable found.
  • OK: cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  • OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features H L F I

  • swift . . . .
  • fortran ✓ . ✓ .
  • c_sharp ✓ . . .
  • rust ✓ ✓ ✓ ✓
  • go ✓ ✓ ✓ ✓
  • ledger ✓ . ✓ ✓
  • ruby ✓ ✓ ✓ ✓
  • zig ✓ ✓ ✓ ✓
  • rst ✓ ✓ . .
  • bibtex ✓ . ✓ ✓
  • fennel ✓ ✓ . .
  • latex ✓ . ✓ .
  • teal ✓ ✓ ✓ ✓
  • gomod ✓ . . .
  • beancount ✓ . ✓ .
  • graphql ✓ . . ✓
  • r ✓ ✓ . .
  • glimmer ✓ . . .
  • verilog ✓ ✓ ✓ .
  • jsonc ✓ ✓ ✓ ✓
  • bash ✓ ✓ ✓ .
  • elm . . . .
  • c ✓ ✓ ✓ ✓
  • comment ✓ . . .
  • dart ✓ ✓ . ✓
  • fish ✓ ✓ ✓ ✓
  • sparql ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓
  • jsdoc ✓ . . .
  • php x x ✓ ✓
  • regex ✓ . . .
  • ql ✓ ✓ . ✓
  • gdscript x x . .
  • nix x x x .
  • typescript ✓ ✓ ✓ ✓
  • yaml x x ✓ ✓
  • turtle ✓ ✓ ✓ ✓
  • html ✓ ✓ ✓ ✓
  • devicetree x x x x
  • julia ✓ ✓ ✓ .
  • json ✓ ✓ ✓ ✓
  • javascript ✓ ✓ ✓ ✓
  • svelte x . ✓ ✓
  • css ✓ . ✓ ✓
  • supercollider x x x x
  • scss ✓ . . ✓
  • haskell . . . .
  • erlang . . . .
  • toml ✓ ✓ ✓ ✓
  • scala . . . .
  • elixir ✓ ✓ . ✓
  • tsx ✓ ✓ ✓ ✓
  • clojure ✓ ✓ ✓ .
  • kotlin ✓ . . .
  • ocaml x ✓ ✓ .
  • commonlisp ✓ ✓ ✓ .
  • vue ✓ . ✓ .
  • python ✓ ✓ ✓ ✓
  • lua ✓ ✓ ✓ ✓
  • ocaml_interfacex ✓ ✓ .
  • java x ✓ . ✓
  • cpp ✓ ✓ ✓ ✓
  • ocamllex x . . .
  • dockerfile ✓ . . .

Legend: H[ighlight], L[ocals], F[olds], I[ndents]
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}

The following errors have been detected:

  • ERROR: php(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 100
  • ERROR: php(locals): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 987
  • ERROR: gdscript(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/gdscript.so: supported between 13 and 13, found 12
  • ERROR: gdscript(locals): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/gdscript.so: supported between 13 and 13, found 12
  • ERROR: nix(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/nix.so: supported between 13 and 13, found 12
  • ERROR: nix(locals): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/nix.so: supported between 13 and 13, found 12
  • ERROR: nix(folds): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/nix.so: supported between 13 and 13, found 12
  • ERROR: yaml(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 291
  • ERROR: yaml(locals): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 20
  • ERROR: devicetree(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/devicetree.so: supported between 13 and 13, found 12
  • ERROR: devicetree(locals): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/devicetree.so: supported between 13 and 13, found 12
  • ERROR: devicetree(folds): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/devicetree.so: supported between 13 and 13, found 12
  • ERROR: devicetree(indents): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/devicetree.so: supported between 13 and 13, found 12
  • ERROR: svelte(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 17
  • ERROR: supercollider(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/supercollider.so: supported between 13 and 13, found 12
  • ERROR: supercollider(locals): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/supercollider.so: supported between 13 and 13, found 12
  • ERROR: supercollider(folds): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/supercollider.so: supported between 13 and 13, found 12
  • ERROR: supercollider(indents): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/supercollider.so: supported between 13 and 13, found 12
  • ERROR: ocaml(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 2729
  • ERROR: ocaml_interface(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 2729
  • ERROR: java(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 2209
  • ERROR: ocamllex(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/ocamllex.so: supported between 13 and 13, found 11

Output of nvim --version

NVIM v0.5.0-dev+1311-gf8173df4d
Build type: Debug
LuaJIT 2.1.0-beta3
Compilation: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=1 -I/Users/rethy/neovim/build/config -I/Users/rethy/neovim/src -I/Users/rethy/neovim/.deps/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/Library/Frameworks/Mono.framework/Headers -I/Users/rethy/neovim/build/src/nvim/auto -I/Users/rethy/neovim/build/include
Compiled by [email protected]

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

Additional context
I looked at the code and I don't think it should work unless I misunderstand the following snippet:

shared.lua

    local parser = parsers.get_parser(bufnr, lang)

    parser:for_each_tree(function(tree, lang_tree)
      local lang = lang_tree:lang()
      local start_row, _, end_row, _ = tree:root():range()
      local query = queries.get_query(lang, 'textobjects')
      for m in queries.iter_prepared_matches(query, tree:root(), bufnr, start_row, end_row) do
        for _, n in pairs(m) do
          if n.node then
            table.insert(matches, n)
          end
        end
      end
    end)

After selecting outer, allow an inner select to go back instead of jump ahead

In ruby you have blocks that can look like the following:

foo.each do |item|
  item
end

foo.each { |item| item }

@block.outer in the first case would cover do..end including the do and end and would cover the brackets and everything inside the brackets in the second. (Note in the second example the brackets dont have to be on the same line)

If you were to do a visual selection of the outer and then cancel, your cursor would be moved to the very end of the block(makes sense since this is how other text objects work like word). Your cursor would be on the d in end in the first example and } in the second.

If you then went to select @block.inner you jump to the next instance rather than doing the inner of the outer your cursor is on

If this isnt possible, feel free to close. Appreciate your work on this project!

Screen.Recording.2021-10-02.at.9.57.08.PM.mov

.

Question: is it expected that inner function objects include braces?

(Thanks for the plugin: it is a snap to set up and easy to work with so far.)

I was surprised to see that by default, an inner function object in, for example, Go and Javascript includes the braces. I'm guessing that this is expected behavior and probably a result of how treesitter itself works. But I wanted to confirm that before going further.

I ask because my most common use for inner function objects is that I want to change, delete, or yank all the code in the function body, but in those cases I don't normally want to include the braces. So, I'll need to consider whether it's possible to tweak treesitter's results.

Error in Rust textobjects

Describe the bug

Error detected while processing FileType Autocommands for "*":
E5108: Error executing lua /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:119: query: error at position 440

To Reproduce
Steps to reproduce the behavior:

  1. Open rust file

Expected behavior
no error

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check

Installation

  • OK: git executable found.
  • OK: cc executable found.

elm parser healthcheck

c parser healthcheck

teal parser healthcheck

java parser healthcheck

python parser healthcheck

dart parser healthcheck

lua parser healthcheck

  • OK: lua parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

ocaml parser healthcheck

go parser healthcheck

nix parser healthcheck

yaml parser healthcheck

json parser healthcheck

jsdoc parser healthcheck

php parser healthcheck

clojure parser healthcheck

html parser healthcheck

typescript parser healthcheck

fennel parser healthcheck

swift parser healthcheck

regex parser healthcheck

query parser healthcheck

verilog parser healthcheck

cpp parser healthcheck

ql parser healthcheck

rst parser healthcheck

ruby parser healthcheck

vue parser healthcheck

ocamllex parser healthcheck

scala parser healthcheck

toml parser healthcheck

rust parser healthcheck

bash parser healthcheck

ocaml_interface parser healthcheck

javascript parser healthcheck

css parser healthcheck

julia parser healthcheck

graphql parser healthcheck

haskell parser healthcheck

c_sharp parser healthcheck

tsx parser healthcheck

Output of nvim --version

NVIM v0.5.0-901-gf5e0f1796
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/sharks/source/neovim/build/config -I/home/sharks/source/neovim/src -I/home/sharks/source/neovim/.deps/usr/include -I/usr/include -I/home/sharks/source/neovim/build/src/nvim/auto -I/home/sharks/source/neovim/build/include

Additional context
Add any other context about the problem here.

Support textobjects defined by start and end node

#12

We could define texobjects like in #12 with by their start and end nodes. E.g.:

(
  (method_signature) @function.outer.start
  (function_body) @function.outer.end
) 

or in Lua

(local_function . (_) . (_) . (_) @function.inner.start  (_) @function.inner.end .)

Update README workflow should create a PR

Due to branch protection rules it can not directly push to master anymore.

Possible solutions:

  • create an automated PR in that workflow
  • create an exception somehow for Github bot in the branch protection rules

How to set the multiple target?

In scss syntax, the property's value could be multiple.
In treesitter, these values are same level.

For example below, the animation property has 5 value,
But in fact they all belong to one value.
Is there a way to select all the children below declaration, like plain_value, integer_value
but except property_name

截屏2021-05-10 下午11 33 15

Even after enabling the plugin can't select the function

Describe the bug
I used python, go etc, but can't select or yank the function

To Reproduce
Steps to reproduce the behavior:

  1. Install plugin
  2. intall respective language
  3. enable the plugin
  4. can't use key- mapping like no effect In pressing the key mappings

Expected behavior
select or yank the function

Output of :checkhealth nvim_treesitter

Installation

  • OK: git executable found.
  • OK: cc executable found.

javascript parser healthcheck

  • OK: javascript parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

json parser healthcheck

  • OK: json parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

clojure parser healthcheck

toml parser healthcheck

  • OK: toml parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

rust parser healthcheck

  • OK: rust parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

ql parser healthcheck

graphql parser healthcheck

python parser healthcheck

  • OK: python parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

teal parser healthcheck

  • OK: teal parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

go parser healthcheck

  • OK: go parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

kotlin parser healthcheck

c parser healthcheck

  • OK: c parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

turtle parser healthcheck

  • OK: turtle parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

gdscript parser healthcheck

sparql parser healthcheck

  • OK: sparql parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: folds.scm found.
  • OK: indents.scm found.

jsdoc parser healthcheck

regex parser healthcheck

fennel parser healthcheck

Paste the output here

Can't install the plugin

Describe the bug
I use Neovim nightly (0.6.0)
I can't install the plugin with packer.

To Reproduce
inside my startup function from packer I have:

local use = require('packer').use
require('packer').startup(function()
    -- Package manager
    use 'wbthomason/packer.nvim'

    -- Libs lua
    use({
        'nvim-lua/plenary.nvim',
        'nvim-lua/popup.nvim',
    })

    -- Treesitter
    use({
        'nvim-treesitter/nvim-treesitter',
        config = [[ require('modules.plugins.treesitter') ]],
        requires = {
            'nvim-treesitter/nvim-treesitter-textobjects'
        },
        run = ':TSUpdate',
    })

    -- Lsp
    use({
        'neovim/nvim-lspconfig',
        -- 'ray-x/lsp_signature.nvim',
        'jose-elias-alvarez/nvim-lsp-ts-utils',
        'jose-elias-alvarez/null-ls.nvim',
        requires = {
            'nvim-lua/plenary.nvim',
            'neovim/nvim-lspconfig',
        },
    })

    -- Completion
    use({
        'hrsh7th/nvim-cmp',
        'hrsh7th/cmp-nvim-lsp',
        'hrsh7th/cmp-buffer',
        'hrsh7th/cmp-path',
        'hrsh7th/cmp-nvim-lua',
        'lukas-reineke/cmp-rg',
    })

    -- File explorer
    use({
        'kyazdani42/nvim-tree.lua',
        requires = 'kyazdani42/nvim-web-devicons',
        config = [[ require('modules.plugins.nvimtree') ]],
    })

    -- Dev tools
    use({
        'editorconfig/editorconfig-vim',
    })

    use 'windwp/nvim-autopairs'

    use({
        'norcalli/nvim-colorizer.lua',
        config = [[require('modules.plugins.colorizer')]],
    })

    use 'tpope/vim-commentary' -- "gc" to comment visual regions/lines

    -- Telescope
    use { 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/plenary.nvim', 'nvim-lua/popup.nvim' } }
    use 'nvim-telescope/telescope-fzf-native.nvim'

    -- Theme
    use({
        'Mofiqul/dracula.nvim',
        'marko-cerovac/material.nvim',
        'kyazdani42/nvim-web-devicons',
    })

    -- Statusline
    use({
        'nvim-lualine/lualine.nvim',
        requires = {
            'nvim-web-devicons',
        },
    })

    use 'arkav/lualine-lsp-progress' -- Integration with progress notifications

    -- i3 support
    use({
        'mboughaba/i3config.vim',
        config = function() require('i3config').setup() end
    })
end)

I have the following error when I try to install it with packer:
nvim-treesitter/nvim-treesitter-textobjects: failed to install

Expected behavior
nvim-treesitter-textobjects should be installed.

Output of nvim --version

NVIM v0.6.0-dev+600-gf71be1f87
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compilé par runner@fv-az121-63

Features: +acl +iconv +tui
See ":help feature-compile"

         fichier vimrc système : "$VIM/sysinit.vim"
               $VIM par défaut : "/share/nvim"

Run :checkhealth for more info

"Move" commands not functioning properly for python methods within a class

Describe the bug
When trying to navigate a Python file using the goto_next_start action, @function.outer jumps to the next class definition rather than to the next method within a class

To Reproduce

  1. Config:
require'nvim-treesitter.configs'.setup {
  ensure_installed = "maintained",
  textobjects = {
    move = {
      enable = true,
      keymaps = {
        goto_next_start = {
          ["]]"] = "@function.outer"
        },
      },
    },
  },
}
  1. Example python module
# my_module.py
import os

class MyModuleClass:
    """My module"""
    def method_1(self):
        ...

    def method_2(self):
        ...

class MySecondModuleClass:
    ...
  1. With the cursor on the 'i' in import in normal mode, enter the keymap ]]
  2. Cursor lands on the 'c' in class MyModuleClass
  3. Enter keymap ]] again
  4. Cursor lands at the 'c' in class MySecondModuleClass
  5. Enter keymap ]] again
  6. Cursor lands at bottom of class MySecondModuleClass definition (...)

If the cursor is anywhere within MyModuleClass, entering ]] also moves the cursor to MySecondModuleClass

Expected behavior
Given 1-3 from above remain the same:
4. Cursor lands on the 'd' in def method_1(self)
5. Enter keymap ]] again
6. Cursor lands on the 'd' in def method_2(self)

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check

Installation

  • OK: tree-sitter found 0.20.0 (parser generator, only needed for :TSInstallFromGrammar)
  • OK: node found v12.22.3 (only needed for :TSInstallFromGrammar)
  • OK: git executable found.
  • OK: cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  • OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features H L F I J

  • javascript ✓ ✓ ✓ ✓ ✓
  • ocaml ✓ ✓ ✓ . ✓
  • ocaml_interface✓ ✓ ✓ . ✓
  • ocamllex ✓ . . . ✓
  • c_sharp ✓ . ✓ . ✓
  • vue ✓ . ✓ . ✓
  • yaml ✓ ✓ ✓ ✓ ✓
  • html ✓ ✓ ✓ ✓ ✓
  • lua ✓ ✓ ✓ ✓ ✓
  • tsx ✓ ✓ ✓ ✓ ✓
  • css ✓ . ✓ ✓ ✓
  • supercollider ✓ ✓ ✓ ✓ ✓
  • hcl ✓ . ✓ . ✓
  • c ✓ ✓ ✓ ✓ ✓
  • toml ✓ ✓ ✓ ✓ ✓
  • glimmer ✓ . . . .
  • jsonc ✓ ✓ ✓ ✓ ✓
  • yang ✓ . ✓ . .
  • nix ✓ ✓ ✓ . ✓
  • dart ✓ ✓ . ✓ ✓
  • rst ✓ ✓ . . ✓
  • fennel ✓ ✓ . . ✓
  • teal ✓ ✓ ✓ ✓ ✓
  • typescript ✓ ✓ ✓ ✓ ✓
  • clojure ✓ ✓ ✓ . ✓
  • regex ✓ . . . .
  • commonlisp ✓ ✓ ✓ . .
  • cpp ✓ ✓ ✓ ✓ ✓
  • comment ✓ . . . .
  • cuda ✓ ✓ ✓ ✓ ✓
  • dockerfile ✓ . . . ✓
  • sparql ✓ ✓ ✓ ✓ ✓
  • rust ✓ ✓ ✓ ✓ ✓
  • ledger ✓ . ✓ ✓ ✓
  • r ✓ ✓ . . .
  • python ✓ ✓ ✓ ✓ ✓
  • devicetree ✓ ✓ ✓ ✓ ✓
  • gomod ✓ . . . .
  • svelte ✓ . ✓ ✓ ✓
  • ruby ✓ ✓ ✓ ✓ ✓
  • beancount ✓ . ✓ . .
  • bash ✓ ✓ ✓ . ✓
  • latex ✓ . ✓ . ✓
  • fish ✓ ✓ ✓ ✓ ✓
  • php ✓ ✓ ✓ ✓ ✓
  • java ✓ ✓ . ✓ ✓
  • kotlin ✓ . . . ✓
  • cmake ✓ . ✓ . .
  • zig ✓ ✓ ✓ ✓ ✓
  • bibtex ✓ . ✓ ✓ .
  • julia ✓ ✓ ✓ ✓ ✓
  • json ✓ ✓ ✓ ✓ .
  • turtle ✓ ✓ ✓ ✓ ✓
  • go ✓ ✓ ✓ ✓ ✓
  • jsdoc ✓ . . . .
  • scss ✓ . . ✓ .
  • ql ✓ ✓ . ✓ ✓
  • verilog ✓ ✓ ✓ . ✓
  • erlang . . . . .
  • query ✓ ✓ ✓ ✓ ✓
  • gdscript ✓ ✓ . . ✓
  • elixir ✓ ✓ ✓ ✓ ✓
  • graphql ✓ . . ✓ ✓

Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.5.0
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210704-5099-1dv0lhc/neovim-0.5.0/build/config -I/tmp/neovim-20210704-5099-1dv0lhc/neovim-0.5.0/src -I/home/linuxbrew/.linuxbrew/include -I/usr/include -I/tmp/neovim-20210704-5099-1dv0lhc/neovim-0.5.0/build/src/nvim/auto -I/tmp/neovim-20210704-5099-1dv0lhc/neovim-0.5.0/build/include
Compiled by linuxbrew@e4b9819dd4f3

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "home/linuxbrew/.linuxbrew/Cellar/neovim/0.5.0/share/nvim"
Run :checkhealth for more info

Captures dont work with +/* quantifiers.

I want to create a custom textobject for c and cpp which will select all the statements inside function body excluding function parenthesis. I have added the below query search to textobjects.scm, but nvim-treesitter query seach does not work as expected. I am facing similar issue with nvim-treesitter/playground as well.

(function_definition
  body:  (compound_statement
              ("{" (_)* @function.inner . "}"))?) @function.outer

Steps to reproduce the behavior:

  1. Create a file foo.c
  2. Paste the following contents in foo.c
int foo(int x) {
  int a = 3;
  int b = 4;
  return x + 1;
}
  1. Install nvim-treesitter/playground
  2. In the query editor paste the following
(function_definition
  body:  (compound_statement
              ("{" (_)* @function.inner . "}"))?) @function.outer

@function.inner incorrectly highlights only the last statement inside function parenthesis.

ss

whereas @function.inner should highlight all the statements inside parenthesis.

image

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check

Installation

  • OK: tree-sitter found 0.20.0 (parser generator, only needed for :TSInstallFromGrammar)
  • OK: node found v16.6.1 (only needed for :TSInstallFromGrammar)
  • OK: git executable found.
  • OK: cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  • OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features H L F I J

  • ocaml_interface✓ ✓ ✓ . ✓
  • beancount ✓ . ✓ . .
  • python ✓ ✓ ✓ ✓ ✓
  • sparql ✓ ✓ ✓ ✓ ✓
  • comment ✓ . . . .
  • lua ✓ ✓ ✓ ✓ ✓
  • ocaml ✓ ✓ ✓ . ✓
  • go ✓ ✓ ✓ ✓ ✓
  • ql ✓ ✓ . ✓ ✓
  • json ✓ ✓ ✓ ✓ .
  • jsdoc ✓ . . . .
  • ledger ✓ . ✓ ✓ ✓
  • php ✓ ✓ ✓ ✓ ✓
  • clojure ✓ ✓ ✓ . ✓
  • supercollider ✓ ✓ ✓ ✓ ✓
  • heex ✓ . ✓ ✓ ✓
  • typescript ✓ ✓ ✓ ✓ ✓
  • fennel ✓ ✓ . . ✓
  • query ✓ ✓ ✓ ✓ ✓
  • cpp ✓ ✓ ✓ ✓ ✓
  • vue ✓ . ✓ . ✓
  • latex ✓ . ✓ . ✓
  • rst ✓ ✓ . . ✓
  • css ✓ . ✓ ✓ ✓
  • glimmer ✓ . . . .
  • erlang . . . . .
  • regex ✓ . . . .
  • svelte ✓ . ✓ ✓ ✓
  • c ✓ ✓ ✓ ✓ ✓
  • fortran ✓ . ✓ ✓ .
  • teal ✓ ✓ ✓ ✓ ✓
  • java ✓ ✓ . ✓ ✓
  • gomod ✓ . . . .
  • dart ✓ ✓ . ✓ ✓
  • verilog ✓ ✓ ✓ . ✓
  • bash ✓ ✓ ✓ . ✓
  • yaml ✓ ✓ ✓ ✓ ✓
  • julia ✓ ✓ ✓ ✓ ✓
  • vim ✓ . . . ✓
  • cmake ✓ . ✓ . .
  • turtle ✓ ✓ ✓ ✓ ✓
  • zig ✓ . ✓ ✓ ✓
  • html ✓ ✓ ✓ ✓ ✓
  • bibtex ✓ . ✓ ✓ .
  • r ✓ ✓ . . .
  • tsx ✓ ✓ ✓ ✓ ✓
  • yang ✓ . ✓ . .
  • javascript ✓ ✓ ✓ ✓ ✓
  • surface ✓ . ✓ ✓ ✓
  • godotResource ✓ ✓ ✓ . .
  • c_sharp ✓ ✓ ✓ . ✓
  • commonlisp ✓ ✓ ✓ . .
  • gdscript ✓ ✓ . . ✓
  • elixir ✓ ✓ ✓ ✓ ✓
  • cuda ✓ ✓ ✓ ✓ ✓
  • haskell ✓ . . . ✓
  • ocamllex ✓ . . . ✓
  • kotlin ✓ . . . ✓
  • ruby ✓ ✓ ✓ ✓ ✓
  • fish ✓ ✓ ✓ ✓ ✓
  • devicetree ✓ ✓ ✓ ✓ ✓
  • scala . . . . .
  • dockerfile ✓ . . . ✓
  • rust ✓ ✓ ✓ ✓ ✓
  • swift . . . . .
  • toml ✓ ✓ ✓ ✓ ✓
  • tlaplus ✓ . ✓ . ✓
  • elm . . . . .
  • jsonc ✓ ✓ ✓ ✓ ✓
  • graphql ✓ . . ✓ ✓
  • nix ✓ ✓ ✓ . ✓
  • scss ✓ . . ✓ .
  • hcl ✓ . ✓ ✓ ✓

Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.5.0
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1
-DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/build/neovim/src/neovim-0.5.0/build/config -I/build/neovim/src/neovim-0.5.0/src -I/usr/include -I/build/neovim/src/neovim-0.5.0/build/src/nvim/auto -I/build/neovim/src/neovim-0.5.0/build/include
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

I have also tested this on neovim nightly 0.6.0+dev+43+g02bf251bb-1. I am facing the same issue.

Swap doesn't repeat with . operator

If I have a piece of code f(a, b, c, d) and I put my cursor on a and perform swap_next for @parameter.inner, it does not compose with .; after the initial swap I have f(b, a, c, d) with the cursor still on a, and I would expect that . would once more do another swap (leaving f(b, c, a, d)). Instead . ignores the swap does whatever happened before that (eg an insertion).

Thanks for this plugin, by the way; enabling this kind of thing is to me one of the most exciting outcomes of treesitter.

How to target the object and include the before text?

For example, in jsx, the each attribute of element are split by <space>.
But Treesitter doesn't include the separator(space).

截屏2021-06-17 下午8 44 57

When I delete this textobj(test={true}), the `' before is still there.
This is correct, but it is inconvenient.

截屏2021-06-17 下午8 47 39

Then I need to delete that space manually.

图片

So, is there any to target the attribute, but also include the space(one or more) before?

and here's my config now.

; jsx attributes
(jsx_self_closing_element attribute: (_) @attribute.outer)
(jsx_element open_tag: (_ attribute: (_) @attribute.outer))

Refined incremental selection

Although the original incremental selection is good, it can be improved. It goes from the very bottom to the top, which can be tedious sometimes. Leveraging text objects, we can ensure that what we select are always that text object we specified earlier.

Refined incremental selection work this way:
User type some command that specify a text object and enter visual mode.
When user increase or decrease the node in the syntax tree, he can only reach a new text object (or syntax structure) that can match the query.

I have some time and I'm happy to contribute this feature. XD

Is it possible to make parameter.outer take the previous comma, if there is no comma afterwards

Is your feature request related to a problem? Please describe.
Given an argument list A, B, C, D the parameter.outer objects would be A,; B,; C, and D. This means that daa (delete around argument) would leave a trailing comma that has to be manually deleted

Describe the solution you'd like
It would be great if it could detect the last argument in the list specially and extend it backward to get the preceding comma

Text Objects are not being set at all

Describe the bug
The text objects I set are non-existent. When I try the bindings within the configuration (at the bottom), nothing happens. There's no error messages or anything like that. It is as if they weren't set. Thanks for any help

Expected behavior
I was expecting the text objects to be selected, cleared, etc when I acted upon them

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check ======================================================================== ## Installation - WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall) - OK: `node` found v16.4.1 (only needed for :TSInstallFromGrammar) - OK: `git` executable found. - OK: `gcc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" } - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features H L F I J

  • python ✓ ✓ ✓ ✓ ✓
  • haskell ✓ . . . ✓
  • yaml ✓ ✓ ✓ ✓ ✓
  • javascript ✓ ✓ ✓ ✓ ✓
  • commonlisp ✓ ✓ ✓ . .
  • json ✓ ✓ ✓ ✓ .
  • rust ✓ ✓ ✓ ✓ ✓
  • c ✓ ✓ ✓ ✓ ✓
  • html ✓ ✓ ✓ ✓ ✓
  • css ✓ . ✓ ✓ ✓
  • lua ✓ ✓ ✓ ✓ ✓

Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.6.0-dev+98-ga5c25e4f3
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe /DWIN32 /D_WINDOWS /W3 -DNVIM_TS_HAS_SET_MATCH_LIMIT /MD /Zi /O2 /Ob1 /DNDEBUG /W3 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DWIN32 -D_WIN32_WINNT=0x0600 -DINCLUDE_GENERATED_DECLARATIONS -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -ID:/a/neovim/neovim/build/config -ID:/a/neovim/neovim/src -ID:/a/neovim/neovim/nvim-deps/usr/include -ID:/a/neovim/neovim/build/src/nvim/auto -ID:/a/neovim/neovim/build/include
Compiled by runneradmin@fv-az152-272

Features: -acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM\sysinit.vim"
  fall-back for $VIM: "C:/Program Files/nvim/share/nvim"

Run :checkhealth for more info

Additional context
My Text Objects Configuration

-- ...
textobjects = {
    lsp_interop = { enable = true },
    select = {
        enable = true,
        keymaps = {
            ["al"] = "@loop.outer",
            ["il"] = "@loop.inner",
            ["ab"] = "@block.outer",
            ["ib"] = "@block.inner",
            ["ac"] = "@class.outer",
            ["ic"] = "@class.inner",
            ["af"] = "@function.outer",
            ["if"] = "@function.inner",
            ["ap"] = "@parameter.outer",
            ["ip"] = "@parameter.inner",
            ["ak"] = "@comment.outer"
        },
    },
    swap = {
        enable = true,
        swap_next = {
            ["<Leader>cs"] = "@parameter.inner",
        },
        swap_previous = {
            ["<Leader>cs"] = "@parameter.inner",
        },
    },
    move = {
        enable = true,
        set_jumps = true,
        goto_next_start = { ["]]"] = "@function.outer" },
        goto_next_end = { ["]}"] = "@function.outer" },
        goto_previous_start = { ["[["] = "@function.outer" },
        goto_previous_end = { ["[{"] = "@function.outer" },
    }
}
-- ...

Add string textobject

Is your feature request related to a problem? Please describe.
I would like to be able to have string textobjects so I can e.g. replace the content of a string with my clipboard

Describe the solution you'd like
@string.outer that includes the quotes and @string.inner that doesn't include the quotes

Describe alternatives you've considered
N/A

Additional context
N/A

Easier option to define mapping manually

Hey guys,

thank you very much for your great work on all the treesitter features! I highly appreciate it! 🙏

Is your feature request related to a problem? Please describe.

I must admit that I was never a friend of letting a plugin doing the key mappings for me. Also if it allows me to define a configuration option to define the key-combo to use. I feel like having less control, it becomes unstructured and ugly. At least that is my view. Unfortunately it seems to become a pattern for the more recent Lua'ish plugins to push for this kind of mappings.
So I denied to use the map definitions within the initialization step of this plugin. I'm adding them manually by myself where they belong to (from my perspective). Unfortunately this results in incredible long lines which look like this for example:

vnoremap <silent> af :<C-u>lua require'nvim-treesitter.textobjects.select'.select_textobject('@function.outer')<CR>

Talking about code quality this results into a fail that is hard to read, because 80% is equal boilerplate code. It is hard to see what is the actual relevant configuration here.

Describe the solution you'd like
I wanted to ask if you guys are willed to add a simple command for each of those exposed functions. Just something as simple as api.nvim_command('command! TSTextObjectSelect lua require..... This would make it slightly easier to add such mappings by hand, removing a lot of the boilerplate.


I'm also open to get suggestions how I could improve my mappings else.
Thank you very much in advanced!

Make @comment.outer span multiline comment

Is your feature request related to a problem? Please describe.
Code comments are usually hard-wrapped, so I use gw / gq to reflow long multiline comments when editing them. Unfortunately, when these are not separated by an empty line from preceding and following code, then the ip (inner paragraph) text object includes that as well, so gwip / gqip reflows even the code (which is unwanted and very probably wrong). So you have to resort to first visually selecting the comment and then gw / gq.

Describe the solution you'd like
I'd love to use treesitter + @comment.outer to invoke gw / gq over the appropriate range of text. However, @comment.outer currently doesn't span multiline comments, it only extends to the current line. Would it be realistic to redefine it, so that e.g. gwac (if ac is configured as the @comment.outer text object) reflows the entire multiline comment?

Describe alternatives you've considered
If redefining @comment.outer is doable but not desirable for backwards compatibility reasons, then maybe a new textobject could be provided, something like @multiline_comment.outer?

Additional context
I'm specifically interesting in Python, but once a solution exists for one language, it should be fairly easy to extend it to other ones with similar syntax?

textobjects declaration feature request

e.g.
@declaration.outer (the target is whole declaration)
截屏2021-04-08 下午10 38 35

@declaration.inner (the target is whole value)
截屏2021-04-08 下午10 38 50

and more like const, var, let, window.value = 123...

Lazy loading

Describe the bug
I am trying to set up lazy loading of treesitter with packer.nvim and there is a race condition with doing so.
As a result keymapping for textobjects are not loaded.

To Reproduce
A piece of packer config:

  use {
    "nvim-treesitter/nvim-treesitter",
    run = ":TSUpdate",
    requires = {
      {
        "nvim-treesitter/playground",
        after = "nvim-treesitter",
        cmd = { "TSPlaygroundToggle", "TSHighlightCapturesUnderCursor" },
      },
      {
        "nvim-treesitter/nvim-treesitter-textobjects",
        module = "nvim-treesitter-textobjects",
        after = "nvim-treesitter",
      },
    },
    event = "BufRead",
    config = function()
      require "config.treesitter"
    end,
  }

config.treesitter file:

local swap_next, swap_prev = (function()
  local swap_objects = {
    c = "@class.outer",
    f = "@function.outer",
    b = "@block.outer",
    s = "@statement.outer",
    p = "@parameter.inner",
    m = "@call.outer",
  }

  local n, p = {}, {}
  for key, obj in pairs(swap_objects) do
    n[string.format("<leader>s%s", key)] = obj
    p[string.format("<leader>S%s", key)] = obj
  end

  return n, p
end)()

require("nvim-treesitter.configs").setup {
  ensure_installed = "maintained",
  highlight = {
    enable = true,
  },
  indent = {
    enable = true,
    disable = { "yaml" },
  },
  incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = "<enter>",
      node_incremental = "<enter>",
      node_decremental = "<bs>",
    },
  },
  textobjects = {
    select = {
      enable = true,
      -- Automatically jump forward to textobj, similar to targets.vim
      lookahead = true,
      keymaps = {
        -- You can use the capture groups defined in textobjects.scm
        ["oc"] = "@class.outer",
        ["ic"] = "@class.inner",
        ["of"] = "@function.outer",
        ["if"] = "@function.inner",
        ["ob"] = "@block.outer",
        ["ib"] = "@block.inner",
        ["ol"] = "@loop.outer",
        ["il"] = "@loop.inner",
        ["os"] = "@statement.outer",
        ["is"] = "@statement.inner",
        ["oC"] = "@comment.outer",
        ["iC"] = "@comment.inner",
        ["om"] = "@call.outer",
        ["im"] = "@call.inner",
      },
    },
    swap = {
      enable = true,
      swap_next = swap_next,
      swap_previous = swap_prev,
    },
    move = {
      enable = true,
      set_jumps = true, -- whether to set jumps in the jumplist
      goto_next_start = {
        ["]m"] = "@function.outer",
        ["]]"] = "@class.outer",
      },
      goto_next_end = {
        ["]M"] = "@function.outer",
        ["]["] = "@class.outer",
      },
      goto_previous_start = {
        ["[m"] = "@function.outer",
        ["[["] = "@class.outer",
      },
      goto_previous_end = {
        ["[M"] = "@function.outer",
        ["[]"] = "@class.outer",
      },
    },
  },
  playground = {
    enable = true,
    disable = {},
    updatetime = 25,
    persist_queries = false,
  },
}

As far as I understand what is going on is:

  • treesitter is loaded (on BufRead) with the keymappings.
  • playground and textobjects are loaded AFTER keymappings were set up and as a result no keymapping are actually appied to the plugin.

Expected behavior
Keymapping from config.treesitter must be applied to the plugin.

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check

Installation

  • WARNING: tree-sitter executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  • OK: node found v14.17.1 (only needed for :TSInstallFromGrammar)
  • OK: git executable found.
  • OK: cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  • OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Output of nvim --version

NVIM v0.6.0-dev+116-g35041432b

Is there a way to lazy load the plugin with packer.nvim?

Accept counts

Would be nice if the move commands could accept counts. And also the select commands could accept counts to select an outer textobject in a nested structure.

Text objects don't work inside of injected languages

Describe the bug

Text objects don't work inside of injected languages.

Pressing daa here doesn't do anything.
image

Related to #27

To Reproduce
Steps to reproduce the behavior using the following textobjects config:

textobjects = {
  select = {
    enable = true,
    lookahead = true,
    keymaps = {
      ["aa"] = "@parameter.outer",
      ["ia"] = "@parameter.inner",
    },
  },
},
  1. Open a new buffer
  2. Type :set ft=vim
  3. Insert this code and move your cursor to the 2nd parameter:
lua <<EOF
test(1, 2)
EOF
  1. Press daa (nothing happens)

Output of :checkhealth nvim_treesitter

nvim_treesitter: health#nvim_treesitter#check
========================================================================
## Installation
  - WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - OK: `node` found v16.10.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (Debian 8.3.0-6) 8.3.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - dart           ✓ ✓ . ✓ ✓ 
  - ruby           ✓ ✓ ✓ ✓ ✓ 
  - ocaml_interface✓ ✓ ✓ . ✓ 
  - c_sharp        ✓ ✓ ✓ . ✓ 
  - dockerfile     ✓ . . . ✓ 
  - svelte         ✓ . ✓ ✓ ✓ 
  - typescript     ✓ ✓ ✓ ✓ ✓ 
  - regex          ✓ . . . . 
  - zig            ✓ . ✓ ✓ ✓ 
  - supercollider  ✓ ✓ ✓ ✓ ✓ 
  - r              ✓ ✓ . . . 
  - haskell        ✓ . . . ✓ 
  - hcl            ✓ . ✓ ✓ ✓ 
  - tlaplus        ✓ . ✓ . ✓ 
  - pioasm         ✓ . . . ✓ 
  - glimmer        ✓ . . . . 
  - json           ✓ ✓ ✓ ✓ . 
  - fish           ✓ ✓ ✓ ✓ ✓ 
  - llvm           ✓ . . . . 
  - jsonc          ✓ ✓ ✓ ✓ ✓ 
  - query          ✓ ✓ ✓ ✓ ✓ 
  - yang           ✓ . ✓ . . 
  - scala          ✓ . ✓ . ✓ 
  - scss           ✓ . . ✓ . 
  - rst            ✓ ✓ . . ✓ 
  - fennel         ✓ ✓ . . ✓ 
  - ql             ✓ ✓ . ✓ ✓ 
  - heex           ✓ . ✓ ✓ ✓ 
  - verilog        ✓ ✓ ✓ . ✓ 
  - c              ✓ ✓ ✓ ✓ ✓ 
  - jsdoc          ✓ . . . . 
  - sparql         ✓ ✓ ✓ ✓ ✓ 
  - html           ✓ ✓ ✓ ✓ ✓ 
  - toml           ✓ ✓ ✓ ✓ ✓ 
  - javascript     ✓ ✓ ✓ ✓ ✓ 
  - tsx            ✓ ✓ ✓ ✓ ✓ 
  - java           ✓ ✓ . ✓ ✓ 
  - turtle         ✓ ✓ ✓ ✓ ✓ 
  - vue            ✓ . ✓ . ✓ 
  - hjson          ✓ ✓ ✓ ✓ ✓ 
  - python         ✓ ✓ ✓ ✓ ✓ 
  - lua            ✓ ✓ ✓ ✓ ✓ 
  - clojure        ✓ ✓ ✓ . ✓ 
  - perl           ✓ . . . . 
  - vim            ✓ ✓ . . ✓ 
  - commonlisp     ✓ ✓ ✓ . . 
  - cmake          ✓ . ✓ . . 
  - latex          ✓ . ✓ . ✓ 
  - yaml           ✓ ✓ ✓ ✓ ✓ 
  - cuda           ✓ ✓ ✓ ✓ ✓ 
  - beancount      ✓ . ✓ . . 
  - bibtex         ✓ . ✓ ✓ . 
  - kotlin         ✓ . . . ✓ 
  - comment        ✓ . . . . 
  - glsl           ✓ ✓ ✓ ✓ ✓ 
  - fortran        ✓ . ✓ ✓ . 
  - julia          ✓ ✓ ✓ ✓ ✓ 
  - graphql        ✓ . . ✓ ✓ 
  - elm            . . . . . 
  - dot            ✓ . . . ✓ 
  - json5          ✓ . . . ✓ 
  - nix            ✓ ✓ ✓ . ✓ 
  - rust           ✓ ✓ ✓ ✓ ✓ 
  - erlang         . . . . . 
  - ledger         ✓ . ✓ ✓ ✓ 
  - css            ✓ . ✓ ✓ ✓ 
  - elixir         ✓ ✓ ✓ ✓ ✓ 
  - go             ✓ ✓ ✓ ✓ ✓ 
  - php            ✓ ✓ ✓ ✓ ✓ 
  - surface        ✓ . ✓ ✓ ✓ 
  - bash           ✓ ✓ ✓ . ✓ 
  - gomod          ✓ . . . . 
  - cpp            ✓ ✓ ✓ ✓ ✓ 
  - ocaml          ✓ ✓ ✓ . ✓ 

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.6.0-dev+479-g9086938f7
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az50-41

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

Performance

Describe the bug

Current search for textobjects is too slow and could be more flexible (counts, textobjects in same line).

Solution

Avoid iter_prepared_matches in find_best_match. Use find_best_matches to allow the use of v:count

How to make TSTextobjectSelect command work with <cmd> in visual mode?

Hey guys,
I prefer to use <cmd> for my mappings in general for all the documented benefits (always clean commands, no silent required, performance, clean command history, ...). Unfortunately this does not work for the TSTextobjectSelect command in visual mode.

This mapping does not work. The result is that the visual selections gets quit and and cursor jumps to the end of the textobject (here the function).

vnoremap af <cmd>TSTextobjectSelect @function.outer<CR>

But it works if I write the mapping like this:

vnoremap af :<C-u>TSTextobjectSelect @function.outer<CR>

Is it possible to patch the command to work with the <cmd> mapping syntax?

Per mapping/object options

Features like #150 and #125 would benefit from being per-mapping/objects instead of global options.

Our current settings look like this

      keymaps = {
        ["af"] = "@function.outer",
        ["if"] = "@function.inner",
        ["ac"] = "@class.outer",
        ["ic"] = "@class.inner",
      }

We could extend them to something like

-- Global options are defined here
-- lookahead = true,
keymaps = {
  ["af"] = {
    textobject = "@function.outer",
    -- If these options aren't given the global/default ones
    -- are used.
    lookahead = true,
    auto_expand = true,
  },
  -- This form is valid, and it uses the global options.
  ["if"] = "@function.inner"
}

vim-commentary can comment out functions and classes, but not uncomment them

I assume this is a bug in this extension rather than vim-commentary, but I don't know that. Please close if it is not.

Commenting in and out code is a PERFECT use of this extension, I hope it can be made to work.

Describe the bug
Using https://github.com/tpope/vim-commentary I can comment out a class or a function with gcac gcaf but when I repeat the command it does not uncomment it. This is the expected behaviour of vim-commentary.

To Reproduce
Try it with vim-commentary on any TypeScript file.

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check

Installation

  • WARNING: tree-sitter executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  • OK: node found v14.16.0 (only needed for :TSInstallFromGrammar)
  • OK: git executable found.
  • OK: cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  • OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features H L F I J

  • lua ✓ ✓ ✓ ✓ ✓
  • json ✓ ✓ ✓ ✓ .
  • bash ✓ ✓ ✓ . ✓
  • jsonc ✓ ✓ ✓ ✓ ✓
  • rust ✓ ✓ ✓ ✓ ✓
  • css ✓ . ✓ ✓ ✓
  • javascript ✓ ✓ ✓ ✓ ✓
  • html ✓ ✓ ✓ ✓ ✓
  • typescript ✓ ✓ ✓ ✓ ✓
  • c ✓ ✓ ✓ ✓ ✓

Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}

Paste the output here

Output of nvim --version

NVIM v0.5.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az242-526

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

Distinguish between methods and functions

Is your feature request related to a problem? Please describe.
I want a way to distinguish between methods and functions in JavaScript and other languages.

Describe the solution you'd like
I'd like:

			goto_next_start = {
				["]k"] = "@class.outer",
				["]m"] = "(method_definition) @function",
				["]f"] = "@function.outer",
				["]b"] = "@block.outer",
			}

to work (I realize I'm not specifying javascript for ]m but I was just testing it out before cleaning it up.

Describe alternatives you've considered
None

Additional context
I'd like to do something like this eventually:

			goto_next_start = {
				["]k"] = "@class.outer",
				["]m"] = {
                                   javascript: "(method_definition) @function",
                                   java = "(method_declaration) @function",
                                   "@function.outer"
                                }
				["]f"] = "@function.outer",
				["]b"] = "@block.outer",
			}

So that I can correctly move from method to method in the languages I most often work with and fall back to the more generic solution when an override isn't defined.

option to choose/disable textobjects-move module adding to jumplist

Is your feature request related to a problem? Please describe.
I'm always frustrated when [not a problem exactly, but when textobject/move adds to jumplist.]

Describe the solution you'd like
I would like to just move away to my hearts content around the code and not worry about populating the jumplist with [email protected], etc..

Additional context
Textobjects/move is a great feature. it makes navigating through code so much more intuitive, especially in large pages. But I would like to keep the jumplist separate so I can navigate back only to places where I have some edits instead of revisiting random "inspection" jumps from the past. It would make the move module even more necessary and good to use.

Goes without saying, thanks for this plugin, for me personally this and playground are the most important tree-sitter modules to be!

Heading or trailing comment in Python class/function not included in text object

Describe the bug

If the first or last element of a Python class or function is a comment, then targeting it as a text object (with @class.outer, @function.inner, etc.) won't include the comment.

This isn't a real problem for me, just a curious edge case I noticed. If fixing this over-complicates other parts of the code or parser, feel free to disregard this and close, but on the off-chance there is a simple fix I'm missing, I thought I would be reporting it.

To Reproduce

With

treesitter.setup {
  textobjects = {
    select = {
      enable = true,
      keymaps = {
        ["ac"] = "@class.outer",
      },
    },
  },
}

and the Python snippet

class A:
    x = 1
    y = 2  # some comment

with the cursor anywhere on or before the character 2, then typing vac will select everything except the comment. If the cursor is on the comment, then typing vac won't do anything.

Expected behavior

With the cursor anywhere in the class, typing vac selects the whole class.

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check

Installation

  • OK: git executable found.
  • OK: cc executable found.

elm parser healthcheck

c parser healthcheck

  • OK: c parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.
  • OK: folds.scm found.

java parser healthcheck

python parser healthcheck

  • OK: python parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.
  • OK: folds.scm found.

dart parser healthcheck

lua parser healthcheck

  • OK: lua parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.
  • OK: folds.scm found.

ocaml parser healthcheck

go parser healthcheck

nix parser healthcheck

yaml parser healthcheck

json parser healthcheck

jsdoc parser healthcheck

markdown parser healthcheck

julia parser healthcheck

html parser healthcheck

typescript parser healthcheck

  • OK: typescript parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.
  • OK: folds.scm found.

fennel parser healthcheck

swift parser healthcheck

query parser healthcheck

cpp parser healthcheck

  • OK: cpp parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.
  • OK: folds.scm found.

regex parser healthcheck

ruby parser healthcheck

vue parser healthcheck

ql parser healthcheck

scala parser healthcheck

toml parser healthcheck

rust parser healthcheck

bash parser healthcheck

ocaml_interface parser healthcheck

rst parser healthcheck

css parser healthcheck

c_sharp parser healthcheck

javascript parser healthcheck

  • OK: javascript parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.
  • OK: folds.scm found.

php parser healthcheck

haskell parser healthcheck

tsx parser healthcheck

  • OK: tsx parser found.
  • OK: highlights.scm found.
  • OK: locals.scm found.
  • OK: textobjects.scm found.
  • OK: folds.scm found.

Output of nvim --version

NVIM v0.5.0-721-g3c5141d2c
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/travis/build/neovim/bot-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by travis@travis-job-5482189d-7ef7-4d79-892c-6d7ec9adbd1f

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/travis/build/neovim/bot-ci/build/neovim/build/nvim.AppDir/usr/share/nvim
"

Run :checkhealth for more info

Autojump to @inner from @outer

In Vim, when you type a motion outside a textobj, it will auto jump forward then do the motion.
This is super usefull, mean you don't need to move the cursor to the textobj part.

ezgif-3-e88f11e678b7

In treesitter-textobjects, it only do the motion when cursor in right position.

For example below, the @inner is inside @outer.
When do the motion like ca, da, ya. It works good.
Cause cursor always in @outer

But the @inner part, have to move cursor it, then do the motion right.

截屏2021-06-29 上午1 28 10

And here's the config, but I think has nothing to do with the config.

; import
(import_statement
  (import_clause
    [(named_imports) (identifier)] @import.inner)) @import.outer

error navigating markdown

Describe the bug

Error when trying to navigate markdown file using text objects

To Reproduce

markdown file like this

# Heading

Text

configuration like this:

      ...
      goto_previous_end = {
        ['[]'] = '@class.outer',
      },

Hit [], error out:

E5108: Error executing lua ...r/start/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua:389: Column value outside range
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        ...r/start/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua:389: in function 'goto_node'
        ...ter-textobjects/lua/nvim-treesitter/textobjects/move.lua:47: in function 'move'
        ...ter-textobjects/lua/nvim-treesitter/textobjects/move.lua:60: in function 'goto_previous_end'
        [string ":lua"]:1: in main chunk

Expected behavior

Cursor is moved, no error.

Output of :checkhealth nvim_treesitter

nvim_treesitter: health#nvim_treesitter#check ======================================================================== ## Installation - OK: `tree-sitter` found 0.20.1 (062421dece3315bd6f228ad6d468cba083d0a2d5) (parser generator, only needed for :TSInstallFromGrammar) - OK: `node` found v15.14.0 (only needed for :TSInstallFromGrammar) - OK: `git` executable found. - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" } Version: cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features H L F I J

  • json ✓ ✓ ✓ ✓ .-
  • vim ✓ ✓ . . ✓-
  • haskell ✓ . . . ✓-
  • supercollider ✓ ✓ ✓ ✓ ✓-
  • scala ✓ . ✓ . ✓-
  • go ✓ ✓ ✓ ✓ ✓-
  • prisma ✓ . . . .-
  • tsx ✓ ✓ ✓ ✓ ✓-
  • typescript ✓ ✓ ✓ ✓ ✓-
  • r ✓ ✓ . . .-
  • c_sharp ✓ ✓ ✓ . ✓-
  • swift . . . . .-
  • cmake ✓ . ✓ . .-
  • ocamllex ✓ . . . ✓-
  • zig ✓ . ✓ ✓ ✓-
  • ocaml_interface✓ ✓ ✓ . ✓-
  • ocaml ✓ ✓ ✓ . ✓-
  • bibtex ✓ . ✓ ✓ .-
  • heex ✓ . ✓ ✓ ✓-
  • make ✓ . . . ✓-
  • surface ✓ . ✓ ✓ ✓-
  • elixir ✓ ✓ ✓ ✓ ✓-
  • erlang . . . . .-
  • svelte ✓ . ✓ ✓ ✓-
  • scss ✓ . . ✓ .-
  • dockerfile ✓ . . . ✓-
  • devicetree ✓ ✓ ✓ ✓ ✓-
  • glsl ✓ ✓ ✓ ✓ ✓-
  • julia ✓ ✓ ✓ ✓ ✓-
  • d ✓ . ✓ ✓ ✓-
  • cuda ✓ ✓ ✓ ✓ ✓-
  • kotlin ✓ . . . ✓-
  • cpp ✓ ✓ ✓ ✓ ✓-
  • commonlisp ✓ ✓ ✓ . .-
  • php ✓ ✓ ✓ ✓ ✓-
  • clojure ✓ ✓ ✓ . ✓-
  • sparql ✓ ✓ ✓ ✓ ✓-
  • fish ✓ ✓ ✓ ✓ ✓-
  • bash ✓ ✓ ✓ . ✓-
  • jsdoc ✓ . . . .-
  • javascript ✓ ✓ ✓ ✓ ✓-
  • perl ✓ . . . .-
  • comment ✓ . . . .-
  • ruby ✓ ✓ ✓ ✓ ✓-
  • graphql ✓ . . ✓ ✓-
  • verilog ✓ ✓ ✓ . ✓-
  • ql ✓ ✓ . ✓ ✓-
  • teal ✓ ✓ ✓ ✓ ✓-
  • python ✓ ✓ ✓ ✓ ✓-
  • fennel ✓ ✓ . . ✓-
  • rst ✓ ✓ . . ✓-
  • regex ✓ . . . .-
  • dart ✓ ✓ . ✓ ✓-
  • fusion ✓ ✓ . . .-
  • nix ✓ ✓ ✓ . ✓-
  • rust ✓ ✓ ✓ ✓ ✓-
  • yang ✓ . ✓ . .-
  • http ✓ . . . ✓-
  • llvm ✓ . . . .-
  • yaml ✓ ✓ ✓ ✓ ✓-
  • hjson ✓ ✓ ✓ ✓ ✓-
  • elm ✓ . . . ✓-
  • pioasm ✓ . . . ✓-
  • json5 ✓ . . . ✓-
  • fortran ✓ . ✓ ✓ .-
  • jsonc ✓ ✓ ✓ ✓ ✓-
  • latex ✓ . ✓ . ✓-
  • vue ✓ . ✓ ✓ ✓-
  • beancount ✓ . ✓ . .-
  • pug ✓ . . . ✓-
  • turtle ✓ ✓ ✓ ✓ ✓-
  • godot_resource ✓ ✓ ✓ . .-
  • gdscript ✓ ✓ . . ✓-
  • query ✓ ✓ ✓ ✓ ✓-
  • ledger ✓ . ✓ ✓ ✓-
  • java ✓ ✓ . ✓ ✓-
  • glimmer ✓ . . . .-
  • lua ✓ ✓ ✓ ✓ ✓-
  • c ✓ ✓ ✓ ✓ ✓-
  • toml ✓ ✓ ✓ ✓ ✓-
  • html ✓ ✓ ✓ ✓ ✓-
  • dot ✓ . . . ✓-
  • css ✓ . ✓ ✓ ✓-
  • tlaplus ✓ . ✓ . ✓-
  • hcl ✓ . ✓ ✓ ✓-
  • markdown ✓ . . . ✓-
  • gomod ✓ . . . ✓-
  • gowork ✓ . . . ✓-

Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.7.0-dev+751-g67bb01ae2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/dch/neovim/build/config -I/home/dch/neovim/src -I/home/dch/neovim/.deps/usr/include -I/usr/include -I/home/dch/neovim/build/src/nvim/auto -I/home/dch/neovim/build/include
Compiled by dch@DESKTOP-NA4O3IV

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/home/dch/.local/nvim/share/nvim"

Run :checkhealth for more info

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.