nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
Captures dont work with +/* quantifiers.
Nobody has claimed this yet.
- Dominant language
- Tree-sitter Query
- Stars
- 2.8k
- Forks
- 271
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 1
Description
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:
- Create a file
foo.c - Paste the following contents in
foo.c
int foo(int x) {
int a = 3;
int b = 4;
return x + 1;
}
- Install
nvim-treesitter/playground - 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.

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

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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the query in the nvim-treesitter/playground using the provided foo.c example and capture pattern. Compare the actual @function.inner highlight with the expected selection of all statements inside the function body, then verify the behavior across the stated Neovim and parser versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100