@comment.inner not working as expected
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>
This is a limitation with the parser, right now block and line comments are parsed as the same node, and there is no distinction exposed between // and comment content
@comment.inner is just not defined for C and it can be added for more languages.
Currently the implementation is simple without a comment parser. It selects comment.outer with an offset.