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

Treatment of whitespace is inconsistent/inconvenient

Open
#69 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Consider a python snippet like the following with the cursor placed at the caret:

print( "a" , "b" , "c" )
            ^

If you try to select parameter.inner or parameter.outer, nothing will happen.

If the cursor is in a different location:

print( "a" , "b" , "c" )
                ^

Now parameter.outer will select something (the "b" parameter up to its comma, but not its leading space),
but parameter.inner still does nothing.

This is probably technically correct according to the way the syntax tree maps to tokens, but it's not very convenient for editing. You'll get similar behavior if you happen to be in whitespace for other text objects, e.g.:

def foo(bar):
    print(bar)
  ^

Here function.outer will select the entire function and body as expected, but function.inner selects nothing.

When the cursor is on whitespace, it should probably "snap" to the next non-whitespace token before looking for the surrounding text object.

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 Python examples with the cursor in whitespace and compare parameter.inner, parameter.outer, and function.inner behavior. Trace the text-object handling for whitespace cursor positions and verify that the completed behavior selects the surrounding object after snapping to the next non-whitespace token.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.