nvim-treesitter / nvim-treesitter-textobjects

Apache License 2.0
2.03k stars 182 forks source link

Selections are one character short with `set selection=exclusive` #488

Open afgomez opened 10 months ago

afgomez commented 10 months ago

Describe the bug

The textobjects don't work properly with set selection=exclusive.

To Reproduce

I have setup the following keymaps:

textobjects = {
   select = {
      enable = true,
      lookahead = true,
      keymaps = {
         ["aa"] = "@parameter.outer",
         ["ia"] = "@parameter.inner",
      },
   },
},

https://github.com/nvim-treesitter/nvim-treesitter-textobjects/assets/57448/0b3bcd7a-a818-4a7f-8b6e-0787ff05a4c1

For comparison, this is what happens with va". The whole string is selected with both inclusive or exclusive. The difference is where the cursor is placed in the second case.

https://github.com/nvim-treesitter/nvim-treesitter-textobjects/assets/57448/1a9b3a83-bb0a-45ee-9f36-45bbbba0d36d

Expected behavior

A clear and concise description of what you expected to happen.

Output of :checkhealth nvim-treesitter

============================================================================== nvim-treesitter: require("nvim-treesitter.health").check() Installation ~ - OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar) - OK `node` found v20.5.0 (only needed for :TSInstallFromGrammar) - OK `git` executable found. - OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" } Version: Apple clang version 14.0.3 (clang-1403.0.22.14.1) - OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI. OS Info: { machine = "arm64", release = "22.5.0", sysname = "Darwin", version = "Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000" } ~ Parser/Features H L F I J - ada ✓ ✓ ✓ . . - agda ✓ . ✓ . . - arduino ✓ ✓ ✓ ✓ ✓ - astro ✓ ✓ ✓ ✓ ✓ - awk ✓ . . . ✓ - bash ✓ ✓ ✓ . ✓ - bass ✓ ✓ ✓ ✓ ✓ - beancount ✓ . ✓ . . - bibtex ✓ . ✓ ✓ . - bicep ✓ ✓ ✓ ✓ ✓ - blueprint ✓ . . . . - c ✓ ✓ ✓ ✓ ✓ - c_sharp ✓ ✓ ✓ . ✓ - cairo ✓ ✓ ✓ ✓ ✓ - capnp ✓ ✓ ✓ ✓ ✓ - chatito ✓ ✓ ✓ ✓ ✓ - clojure ✓ ✓ ✓ . ✓ - cmake ✓ . ✓ ✓ . - comment ✓ . . . . - commonlisp ✓ ✓ ✓ . . - cooklang ✓ . . . . - corn ✓ ✓ ✓ ✓ . - cpon ✓ ✓ ✓ ✓ ✓ - cpp ✓ ✓ ✓ ✓ ✓ - css ✓ . ✓ ✓ ✓ - cuda ✓ ✓ ✓ ✓ ✓ - cue ✓ ✓ ✓ ✓ ✓ - d ✓ . ✓ ✓ ✓ - dart ✓ ✓ ✓ ✓ ✓ - devicetree ✓ ✓ ✓ ✓ ✓ - dhall ✓ . ✓ . ✓ - diff ✓ . . . . - dockerfile ✓ . . . ✓ - dot ✓ . . . ✓ - ebnf ✓ . . . . - eex ✓ . . . ✓ - elixir ✓ ✓ ✓ ✓ ✓ - elm ✓ . . . ✓ - elsa ✓ ✓ ✓ ✓ ✓ - elvish ✓ . . . ✓ - embedded_template ✓ . . . ✓ - erlang ✓ . ✓ . . - fennel ✓ ✓ ✓ . ✓ - firrtl ✓ ✓ ✓ ✓ ✓ - fish ✓ ✓ ✓ ✓ ✓ - foam ✓ ✓ ✓ ✓ ✓ - fortran ✓ . ✓ ✓ . - fsh ✓ . . . . - func ✓ . . . . - fusion ✓ ✓ ✓ ✓ . - gdscript ✓ ✓ ✓ ✓ ✓ - git_config ✓ . . . . - git_rebase ✓ . . . ✓ - gitattributes ✓ . . . ✓ - gitcommit ✓ . . . ✓ - gitignore ✓ . . . . - gleam ✓ ✓ ✓ ✓ ✓ - glimmer ✓ ✓ ✓ ✓ . - glsl ✓ ✓ ✓ ✓ ✓ - go ✓ ✓ ✓ ✓ ✓ - godot_resource ✓ ✓ ✓ . . - gomod ✓ . . . ✓ - gosum ✓ . . . . - gowork ✓ . . . ✓ - graphql ✓ . . ✓ ✓ - groovy ✓ . . . ✓ - hack ✓ . . . . - hare ✓ ✓ ✓ ✓ ✓ - haskell ✓ . ✓ . ✓ - haskell_persistent ✓ . ✓ . . - hcl ✓ . ✓ ✓ ✓ - heex ✓ ✓ ✓ ✓ ✓ - hjson ✓ ✓ ✓ ✓ ✓ - hlsl ✓ ✓ ✓ ✓ ✓ - hocon ✓ . . . ✓ - hoon ✓ ✓ ✓ . . - html ✓ ✓ ✓ ✓ ✓ - htmldjango ✓ . ✓ ✓ ✓ - http ✓ . . . ✓ - hurl ✓ . ✓ ✓ ✓ - ini ✓ . ✓ . . - ispc ✓ ✓ ✓ ✓ ✓ - janet_simple ✓ ✓ ✓ . ✓ - java ✓ ✓ ✓ ✓ ✓ - javascript ✓ ✓ ✓ ✓ ✓ - jq ✓ . . . ✓ - jsdoc ✓ . . . . - json ✓ ✓ ✓ ✓ . - json5 ✓ . . . ✓ - jsonc ✓ ✓ ✓ ✓ ✓ - jsonnet ✓ . . . . - julia ✓ ✓ ✓ ✓ ✓ - kdl ✓ ✓ ✓ ✓ ✓ - kotlin ✓ ✓ ✓ . ✓ - lalrpop ✓ ✓ . . ✓ - latex ✓ . ✓ . ✓ - ledger ✓ . ✓ ✓ ✓ - llvm ✓ . . . . - lua ✓ ✓ ✓ ✓ ✓ - luadoc ✓ . . . . - luap ✓ . . . . - luau ✓ ✓ ✓ ✓ ✓ - m68k ✓ ✓ ✓ . ✓ - make ✓ . ✓ . ✓ - markdown ✓ . ✓ ✓ ✓ - markdown_inline ✓ . . . ✓ - matlab ✓ ✓ ✓ ✓ ✓ - menhir ✓ . . . ✓ - mermaid ✓ . . . . - meson ✓ . ✓ . ✓ - mlir ✓ ✓ . . . - nickel ✓ . . ✓ . - ninja ✓ . ✓ ✓ . - nix ✓ ✓ ✓ . ✓ - norg . . . . . - objc ✓ ✓ ✓ ✓ ✓ - ocaml ✓ ✓ ✓ ✓ ✓ - ocaml_interface ✓ ✓ ✓ ✓ ✓ - ocamllex ✓ . . . ✓ - odin ✓ ✓ ✓ ✓ ✓ - org . . . . . - pascal ✓ ✓ ✓ ✓ ✓ - passwd ✓ . . . . - pem ✓ . ✓ . ✓ - perl ✓ . ✓ . ✓ - php ✓ ✓ ✓ ✓ ✓ - phpdoc ✓ . . . . - pioasm ✓ . . . ✓ - po ✓ . ✓ . ✓ - poe_filter ✓ . ✓ ✓ ✓ - pony ✓ ✓ ✓ ✓ ✓ - prisma ✓ . . . . - promql ✓ . . . ✓ - proto ✓ . ✓ . . - prql ✓ . . . ✓ - pug ✓ . . . ✓ - puppet ✓ ✓ ✓ ✓ ✓ - python ✓ ✓ ✓ ✓ ✓ - ql ✓ ✓ ✓ ✓ ✓ - qmldir ✓ . . . ✓ - qmljs ✓ . ✓ . . - query ✓ ✓ ✓ ✓ ✓ - r ✓ ✓ . ✓ ✓ - racket ✓ . ✓ . ✓ - rasi ✓ ✓ ✓ ✓ . - regex ✓ . . . . - rego ✓ . . . ✓ - requirements ✓ . . . ✓ - rnoweb ✓ . ✓ . ✓ - robot ✓ . . . . - ron ✓ ✓ ✓ ✓ ✓ - rst ✓ ✓ . . ✓ - ruby ✓ ✓ ✓ ✓ ✓ - rust ✓ ✓ ✓ ✓ ✓ - scala ✓ ✓ ✓ . ✓ - scfg ✓ . . . ✓ - scheme ✓ . ✓ . ✓ - scss ✓ . ✓ ✓ . - slint ✓ . . ✓ . - smali ✓ ✓ ✓ ✓ ✓ - smithy ✓ . . . . - solidity ✓ . . . . - sparql ✓ ✓ ✓ ✓ ✓ - sql ✓ . . ✓ ✓ - squirrel ✓ ✓ ✓ ✓ ✓ - starlark ✓ ✓ ✓ ✓ ✓ - supercollider ✓ ✓ ✓ ✓ ✓ - surface ✓ . ✓ ✓ ✓ - svelte ✓ . ✓ ✓ ✓ - swift ✓ ✓ . ✓ . - sxhkdrc ✓ . ✓ . ✓ - systemtap ✓ ✓ ✓ . ✓ - t32 ✓ ✓ ✓ ✓ ✓ - tablegen ✓ ✓ ✓ ✓ ✓ - teal ✓ ✓ ✓ ✓ ✓ - terraform ✓ . ✓ ✓ ✓ - thrift ✓ ✓ ✓ ✓ ✓ - tiger ✓ ✓ ✓ ✓ ✓ - tlaplus ✓ ✓ ✓ . ✓ - todotxt ✓ . . . . - toml ✓ ✓ ✓ ✓ ✓ - tsx ✓ ✓ ✓ ✓ ✓ - turtle ✓ ✓ ✓ ✓ ✓ - twig ✓ . . . ✓ - typescript ✓ ✓ ✓ ✓ ✓ - ungrammar ✓ ✓ ✓ ✓ ✓ - usd ✓ ✓ ✓ ✓ . - uxntal ✓ ✓ ✓ ✓ ✓ - v ✓ ✓ ✓ ✓ ✓ - vala ✓ . ✓ . . - verilog ✓ ✓ ✓ . ✓ - vhs ✓ . . . . - vim ✓ ✓ ✓ . ✓ - vimdoc ✓ . . . ✓ - vue ✓ . ✓ ✓ ✓ - wgsl ✓ . ✓ ✓ . - wgsl_bevy ✓ . ✓ ✓ . - wing ✓ ✓ ✓ . . - yaml ✓ ✓ ✓ ✓ ✓ - yang ✓ . ✓ ✓ ✓ - yuck ✓ ✓ ✓ ✓ ✓ - zig ✓ . ✓ ✓ ✓ 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 --version
NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.1/share/nvim"

Run :checkhealth for more info
kiyoon commented 10 months ago

It may be a bug on nvim-treesitter's update_selection function.

https://github.com/nvim-treesitter/nvim-treesitter/blob/dfcfdb0e7bcb362c4de1ed7d0015c21957c91ba7/lua/nvim-treesitter/ts_utils.lua#L278

Check if incremental selection of nvim treesitter have the same problem. If so, then that function should be the problem.