nvim-treesitter / nvim-treesitter-textobjects

Apache License 2.0
2.11k stars 190 forks source link

Captures dont work with +/* quantifiers. #102

Open AkashKarnatak opened 3 years ago

AkashKarnatak commented 3 years ago

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;
    }
  3. Install nvim-treesitter/playground
  4. 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.

stsewd commented 3 years ago

Hi, currently the quantifier operators (*, +) aren't supported.

theHamsta commented 2 years ago

This is a upstream problem https://github.com/neovim/neovim/pull/17099