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

bug: `@parameter.outer` will match comments and not the actual parameters.

Open
#768 0 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

function_call(
    b,  # aaa
    c,  # aaa
    d,  # bbb
)

In cases like this, it will never match the parameters and only match comments. Matching comments itself is not a big issue but not being able to match parameters is.

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~

  • ✅ OK tree-sitter found 0.25.3 (parser generator, only needed for :TSInstallFromGrammar)
  • ✅ OK node found v23.11.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 17.0.0 (clang-1700.0.13.3)
  • ✅ OK Neovim was compiled with tree-sitter runtime ABI version 15 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
machine = "arm64",
release = "24.5.0",
sysname = "Darwin",
version = "Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000"
} ~

Parser/Features H L F I J

  • bash ✓ ✓ ✓ . ✓
  • bibtex ✓ . ✓ ✓ ✓
  • c ✓ ✓ ✓ ✓ ✓
  • c_sharp ✓ ✓ ✓ . ✓
  • cmake ✓ . ✓ ✓ ✓
  • cpp ✓ ✓ ✓ ✓ ✓
  • css ✓ . ✓ ✓ ✓
  • csv ✓ . . . .
  • diff ✓ . ✓ . ✓
  • dockerfile ✓ . . . ✓
  • editorconfig ✓ . ✓ . ✓
  • fortran ✓ . ✓ ✓ ✓
  • git_config ✓ . ✓ . ✓
  • git_rebase ✓ . . . ✓
  • gitattributes ✓ ✓ . . ✓
  • gitcommit ✓ . . . ✓
  • gitignore ✓ . . . ✓
  • haskell ✓ ✓ ✓ . ✓
  • html ✓ ✓ ✓ ✓ ✓
  • ini ✓ . ✓ . ✓
  • java ✓ ✓ ✓ ✓ ✓
  • javascript ✓ ✓ ✓ ✓ ✓
  • json ✓ ✓ ✓ ✓ .
  • jsonc ✓ ✓ ✓ ✓ ✓
  • latex ✓ . ✓ . ✓
  • lua ✓ ✓ ✓ ✓ ✓
  • make ✓ . ✓ . ✓
  • markdown ✓ . ✓ ✓ ✓
  • markdown_inline ✓ . . . ✓
  • perl ✓ . ✓ . ✓
  • php ✓ ✓ ✓ ✓ ✓
  • po ✓ . ✓ . ✓
  • powershell ✓ ✓ ✓ ✓ ✓
  • prolog ✓ . ✓ ✓ ✓
  • pymanifest ✓ . . . ✓
  • python ✓ ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓
  • requirements ✓ . . . ✓
  • rst ✓ ✓ . . ✓
  • ruby ✓ ✓ ✓ ✓ ✓
  • rust ✓ ✓ ✓ ✓ ✓
  • sql ✓ . ✓ ✓ ✓
  • ssh_config ✓ ✓ ✓ ✓ ✓
  • tmux ✓ . . . ✓
  • toml ✓ ✓ ✓ ✓ ✓
  • tsv ✓ . . . .
  • tsx ✓ ✓ ✓ ✓ ✓
  • typescript ✓ ✓ ✓ ✓ ✓
  • vim ✓ ✓ ✓ . ✓
  • vimdoc ✓ . . . ✓
  • xml ✓ ✓ ✓ ✓ ✓
  • yaml ✓ ✓ ✓ ✓ ✓

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.11.1
Build type: Release
LuaJIT 2.1.1744318430
Run "nvim -V1 -v" for more info

Additional context

To remove matching the comments completely, you can maybe use #not-has-type? predicate but maybe it's not supported in master branch of nvim-treesitter. (Could be in Neovim core)

Solution 1

Usually, comma comes directly after the parameter. If we match comma after the parameter except for the last one, in most cases it will be able to match.

Solution in #766 may fix the issue.

Solution 2 (not recommended)

We can remove comments between a leading comma and the parameter.

((parameters
  "," @_start
  .
  (comment)*
  .
  (_) @parameter.inner
  )
  (#make-range! "parameter.outer" @_start @parameter.inner))

But this is dangerous because it may remove too much more than what user expects.

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

Reproduce the Python example and inspect the Tree-sitter query definitions responsible for @parameter.outer. Compare the proposed comma-based approach with solution #766, then verify that parameters are matched while inline comments are not included.

Written by the indexing model from the issue text.

Assessment

Tech stack
neovim
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.