nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
Make @comment.outer span multiline comment
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 your feature request related to a problem? Please describe.
Code comments are usually hard-wrapped, so I use gw / gq to reflow long multiline comments when editing them. Unfortunately, when these are not separated by an empty line from preceding and following code, then the ip (inner paragraph) text object includes that as well, so gwip / gqip reflows even the code (which is unwanted and very probably wrong). So you have to resort to first visually selecting the comment and then gw / gq.
Describe the solution you'd like
I'd love to use treesitter + @comment.outer to invoke gw / gq over the appropriate range of text. However, @comment.outer currently doesn't span multiline comments, it only extends to the current line. Would it be realistic to redefine it, so that e.g. gwac (if ac is configured as the @comment.outer text object) reflows the entire multiline comment?
Describe alternatives you've considered
If redefining @comment.outer is doable but not desirable for backwards compatibility reasons, then maybe a new textobject could be provided, something like @multiline_comment.outer?
Additional context
I'm specifically interesting in Python, but once a solution exists for one language, it should be fairly easy to extend it to other ones with similar syntax?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the Python @comment.outer text object is defined and how it supplies ranges for gw/gq; the issue identifies multiline comments and the ip text object as the relevant behavior. Decide whether the existing object or a new multiline-comment object should span the full comment, then verify that surrounding code is excluded and that the requested gwac-style workflow works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100