Skip to content

@parameter.inner/outer capture group is too broad? #701

Open
@rossvold

Description

Describe the bug
I expected @parameter.inner/outer to only select parameters, but it seems like it currently way too broad. This happens in rust, js, ts & go. Since this is the exact same behaviour this might be intended, if so why?

I couldn't really find any discussions on what should be counted as parameters and not so thought i would make an issue on it.

In my mind atleast, it would only make sense to only grab actual parameters, the way it's currently setup feels way to broad.

To Reproduce
Rust example:

fn main() {
    let y = plus_one(5);  // 5 is captured by @parameter
    println!("The value of y is: {y}"); // Captured by @parameter
}

fn plus_one(y: i32) -> i32 { // this is the only parameter in our code, & is captured by @parameter
    y + 1
}

Ts example:

// In this example every single line is captured by the @parameter capture group
function test(number: number) { // number is the only actual parameter here.
	console.log("print number", number)
	console.log("not a parameter")
}

test(1)

This also happens in ts & go.

Expected behavior
In my own config i ended up basically using something like this:
Image
Image

Output of :checkhealth nvim-treesitter

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

Installation ~
- OK `tree-sitter` found 0.24.3 (bdfe32402e85673bbc693216f0a6ef72c98bb665) (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v22.9.0 (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 20240910
- 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.11.1-arch1-1",
  sysname = "Linux",
  version = "#1 SMP PREEMPT_DYNAMIC Mon, 30 Sep 2024 23:49:50 +0000"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - css                 ✓ . ✓ ✓ ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - svelte              ✓ ✓ ✓ ✓ ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - vue                 ✓ . ✓ ✓ ✓

  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.2
Build type: RelWithDebInfo
LuaJIT 2.1.1727870382
Run "nvim -V1 -v" for more info

Additional context
Would a PR making @parameters.inner / outer more strict be welcome?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions