nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects

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

Open
#488 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Tree-sitter Query
Stars
2.8k
Forks
271
Avg merge
8d 8h
Merged PRs (30d)
1

Description

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",
      },
   },
},
  • With set selection=inclusive, vaa selects the whole parameter
  • With set selection=exclusice, vaa selection is one character short.

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named in the report. First reproduce the textobject selection with set selection=exclusive and the aa/ia mappings, then trace the selection entry point and compare it with inclusive mode; done means the whole parameter is selected in both modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, vim
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.