Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
afgomez opened this issue Aug 24, 2023 · 4 comments
Open

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

afgomez opened this issue Aug 24, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@afgomez
Copy link

afgomez commented Aug 24, 2023

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.
vaa.mov

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.

vaquote.mov

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
@afgomez afgomez added the bug Something isn't working label Aug 24, 2023
@kiyoon
Copy link
Collaborator

kiyoon commented Sep 8, 2023

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.

@afgomez
Copy link
Author

afgomez commented Aug 1, 2024

Sorry for the very late reply. I stopped using neovim, but I started again recently (🎉).

I've been doing some tests today with this. The incremental selection of nvim-treesitter has indeed the same problem. This was reported in nvim-treesitter/nvim-treesitter#3488, and it is still present.

There was an attempt to fix it in nvim-treesitter/nvim-treesitter#5724. However as per this comment, the module will be deprecated soon and the ts_utils.lua file removed.

I wonder what's the best solution here. This (nvim-treesitter-textobjects) plugin still has the same problem.

Since apparently there are intentions to remove ts_utils.lua from nvim-treesitter, should we move it to this plugin and fix the implementation here?

If so I can give it a shot

@kiyoon
Copy link
Collaborator

kiyoon commented Aug 2, 2024

the function is already in this plugin in the main branch. If you can make a fix for both master and main, I'm down to review it. I think just copying the implementation from what you've found will work.

@kiyoon
Copy link
Collaborator

kiyoon commented Aug 2, 2024

I mean just make a fix for the master branch, and make it so that it is easy to be rebased to main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants