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

Rust: `@parameter` doesn't work correctly in macros

Open
#698 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
The @parameter.inner and @parameter.outer selectors does not work correctly inside function which are inside a macro.

To Reproduce

assert!(fu^nc("arg"), &r^ef, So^me(4));

Now run dia (Delete @parameter.inner) with cursour in every ^ separately.
The results are:

assert!(("arg"), &ref, Some(4));
assert!(func("arg"), &, Some(4));
assert!(func("arg"), &ref,(4));

Expected behavior

assert!(, &ref, Some(4));
assert!(func("arg"), , Some(4));
assert!(func("arg"), &ref,);

If we remove the shabang (!) and treat it as a function assert, then every keybinding works as expected.

Output of :checkhealth nvim-treesitter

Paste the output here

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

Installation ~

  • WARNING tree-sitter executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  • OK node found v20.11.1 (only needed for :TSInstallFromGrammar)
  • OK git executable found.
  • OK cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (GCC) 14.2.1 20240805
  • OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
machine = "x86_64",
release = "6.10.6-arch1-1.1-g14",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Thu, 29 Aug 2024 07:08:56 +0000"
} ~

Parser/Features H L F I J

  • bash ✓ ✓ ✓ . ✓
  • c ✓ ✓ ✓ ✓ ✓
  • cpp ✓ ✓ ✓ ✓ ✓
  • css ✓ . ✓ ✓ ✓
  • fish ✓ ✓ ✓ ✓ ✓
  • html ✓ ✓ ✓ ✓ ✓
  • hyprlang ✓ . ✓ ✓ ✓
  • javascript ✓ ✓ ✓ ✓ ✓
  • json ✓ ✓ ✓ ✓ .
  • lua ✓ ✓ ✓ ✓ ✓
  • luadoc ✓ . . . .
  • markdown ✓ . ✓ ✓ ✓
  • markdown_inline ✓ . . . ✓
  • nix ✓ ✓ ✓ ✓ ✓
  • norg . . . . .
  • printf ✓ . . . .
  • python ✓ ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓
  • rasi ✓ ✓ ✓ ✓ ✓
  • rust ✓ ✓ ✓ ✓ ✓
  • toml ✓ ✓ ✓ ✓ ✓
  • tsx ✓ ✓ ✓ ✓ ✓
  • typescript ✓ ✓ ✓ ✓ ✓
  • typst ✓ . ✓ ✓ ✓
  • vim ✓ ✓ ✓ . ✓
  • vimdoc ✓ . . . ✓
  • 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.10.1
Build type: Release
LuaJIT 2.1.1723675123
Run "nvim -V1 -v" for more info

Additional context
Add any other context about the problem here.

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

Start by reproducing the reported @parameter.inner and @parameter.outer behavior in the Rust macro example, comparing it with the same expression without the assert! macro. Trace the dia entry point and selector handling, then verify that each parameter is removed as shown in the expected results.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
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.