nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
@comment.inner not working as expected
Nobody has claimed this yet.
- Dominant language
- Tree-sitter Query
- Stars
- 2.8k
- Forks
- 271
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 1
Description
Describe the bug
When using the @comment.inner text object, nothing gets selected.
@comment.outer works fine.
To Reproduce
- Add this to your treesitter config.
textobjects = {
select = {
enable = true,
lookahead = true,
include_surrounding_whitespace = true,
keymaps = {
["ac"] = "@comment.outer",
["ic"] = "@comment.inner",
},
},
},
- open cpp file
- go to line with comment "// ..."
- use command "cic"
- nothing happens
Expected behavior
Line in beginning:
// Change<cursor> this comment
Line after cic:
// <cursor>
Output of :checkhealth nvim-treesitter
nvim-treesitter: require("nvim-treesitter.health").check()
Installation ~
- OK `tree-sitter` found 0.22.5 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.12.2 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: cc (GCC) 14.1.1 20240522 (Red Hat 14.1.1-4)
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
OS Info:
{
machine = "x86_64",
release = "6.8.9-300.fc40.x86_64",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Thu May 2 18:59:06 UTC 2024"
} ~
Parser/Features H L F I J
- bash ✓ ✓ ✓ . ✓
- c ✓ ✓ ✓ ✓ ✓
- cmake ✓ . ✓ ✓ .
- cpp ✓ ✓ ✓ ✓ ✓
- csv ✓ . . . .
- gitignore ✓ . . . .
- glsl ✓ ✓ ✓ ✓ ✓
- html ✓ ✓ ✓ ✓ ✓
- lua ✓ ✓ ✓ ✓ ✓
- markdown ✓ . ✓ ✓ ✓
- python ✓ ✓ ✓ ✓ ✓
- rust ✓ ✓ ✓ ✓ ✓
- vim ✓ ✓ ✓ . ✓
- vimdoc ✓ . . . ✓
- yaml ✓ ✓ ✓ ✓ ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang} ~
Output of nvim --version
NVIM v0.10.0
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634
Run "nvim -V1 -v" for more info
Additional context
@comment.outer works fine and like expected:
Line in beginning:
// Change<cursor> this comment
Line after cac:
<cursor>
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 reproducing the @comment.inner selection in a C++ comment using the textobjects.select configuration shown in the issue, then compare it with @comment.outer. Done means cic selects the comment text as described while cac continues to select the whole comment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100