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

Distinguish between methods and functions

Open
#139 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Tree-sitter Query
Stars
2.8k
Forks
271
Avg merge
8d 8h
Merged PRs (30d)
1

Description

Is your feature request related to a problem? Please describe.
I want a way to distinguish between methods and functions in JavaScript and other languages.

Describe the solution you'd like
I'd like:

			goto_next_start = {
				["]k"] = "@class.outer",
				["]m"] = "(method_definition) @function",
				["]f"] = "@function.outer",
				["]b"] = "@block.outer",
			}

to work (I realize I'm not specifying javascript for ]m but I was just testing it out before cleaning it up.

Describe alternatives you've considered
None

Additional context
I'd like to do something like this eventually:

			goto_next_start = {
				["]k"] = "@class.outer",
				["]m"] = {
                                   javascript: "(method_definition) @function",
                                   java = "(method_declaration) @function",
                                   "@function.outer"
                                }
				["]f"] = "@function.outer",
				["]b"] = "@block.outer",
			}

So that I can correctly move from method to method in the languages I most often work with and fall back to the more generic solution when an override isn't defined.

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 tracing how the goto_next_start configuration is read and how Tree-sitter captures such as @function and (method_definition) are handled. Confirm that language-specific method queries can override the generic function query for JavaScript and Java, while retaining the generic fallback.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, javascript, lua, neovim
Domain
tooling
Issue type
Feature
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.