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

Jumping to next sibling key in dictionary

Open
#183 5 comments 0 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.
Following examples are for python, but it applies to many languages.

Let's say I have large nested dictionary, e.g :

a = {
    "item 1": 1,
    "item 2": [
               "big",
               "hairy",
               "list",
               "I",
               "want",
               "to",
               "skim",
               "over"
    ],
    "item 3": 3,
}

and cursor is placed on item 1. require'nvim-treesitter.textobjects.move'.goto_next_start('@parameter.inner') will jump to item 2 key, which is fine, but on next invocation, it will descend into item 2 list. I would like to be able to jump exclusively to next sibling/key, without descending into key's value. I often find myself wanting to jump over keys in JSON file with large values that span over many screens.

Describe the solution you'd like
Something similar to @parameter.(inner|outer) that is jumps only to keys on the same level of nesting as one under cursor.

Describe alternatives you've considered
% partially works, but it fails with large files. It doesn't do exactly what want (it jumps to the end of the array, not to the next dictionary key), but it's close enough.

Additional context
Same problem exists with nested arrays

ar = [
    "level 1 item",
    [
        "l",
        "e",
        "v",
        "e",
        "l",
        "2",
        "i",
        "t",
        "e",
        "m",
        "s"
    ],
    "another level 1 item"
]

Proposed operator, starting from cursor at level 1 item, should jump to beginning of array, but not inside of it, next require'nvim-treesitter.textobjects.move'.goto_next_start call should jump straight to another level 1 item.

I have read query documentation from treesitter site, but I don't still don't know if it's possible to write or not…

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 at nvim-treesitter.textobjects.move and its goto_next_start('@parameter.inner') entry point, then review the Tree-sitter query documentation referenced in the issue. Done means navigation can move between sibling dictionary keys or array items at the current nesting level without descending into nested values, including the Python examples shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
neovim, python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.