Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
theIbraDev opened this issue Oct 13, 2024 · 2 comments
Open

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

theIbraDev opened this issue Oct 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@theIbraDev
Copy link

theIbraDev commented Oct 13, 2024

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?

@theIbraDev theIbraDev added the bug Something isn't working label Oct 13, 2024
@Juhan280
Copy link
Contributor

Juhan280 commented Oct 14, 2024

arguments and parameters are both captured as @parameter. There is no separate builtin capture group for argument.

@theIbraDev
Copy link
Author

arguments and parameters are both captured as @parameter. There is no separate builtin capture group for argument.

Parameters and arguments are somewhat related, but it would in my mind be more sensible to add a new capture group called arguments and separate those two. I have done this in my personal setup and it makes editing and jumping to those objects much faster and intuitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants