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

How to press once shortcut key to automatically jump class or function?

Open
#490 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is there a way to automatically determine whether the current context is a function or a class, and then set the same shortcut key to jump?

There will be problems if set the same settings directly

      goto_previous_start = {
        ["[m"] = "@function.outer",
        ["[m"] = "@class.outer",
      },

When using the treesitter-context plugin, it can get the corresponding line number like this. I want to automatically jump to the corresponding place.

截屏2023-09-08 12 02 45

For example, in go, when I am in a function or structure, I can jump to the definition by pressing [m

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 Go example with the shown goto_previous_start mappings and inspect how the treesitter-context plugin identifies the current context and line. The feature is done when one shortcut can determine whether the current location is in a function or class/structure and jump to the corresponding definition without duplicate mappings.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.