Open ybc37 opened 1 month ago
Happening to me too 😿
I have recently browser through nvim-treesitter and noticed it injects comment
parser into multiple languages. This also breaks uncommenting (and might make for a simpler repro).
comment
injected.I did a bit of testing, and I am not even sure if this is ts-comments.nvim issue. I would say it's a matter of proper configuration and/or missing defaults.
This particular issue is caused by the commented line being treated as phpdoc
. Notice the tags on right-hand side of the tree changing. If we are in php
, then it works as expected. If we are in phpdoc
, then it "breaks".
https://github.com/user-attachments/assets/825f3162-910b-4ddb-adb1-f3a3a6688c8e
There is no default ts-comments.nvim config for php
. The README states:
ts-comments.nvim uses the default Neovim
commentstring
as a fallback, so there's no need to configure every language.
And the default commentstring
is /*%s*/
, so it works as intended.
Updating your reproduction script with:
{
"folke/ts-comments.nvim",
opts = {
lang = {
phpdoc = { "// %s" },
},
},
}
Changes the behavior to:
https://github.com/user-attachments/assets/91a58553-f0bc-4ec4-b638-bd60ae3c43a1
Aside: notice that the deafult commentstring
is always included. That's why both // %s
and /*%s*/
work for php
.
Did you check docs and existing issues?
Neovim version (nvim -v)
NVIM v0.10.1
Operating system/version
Linux 6.10.3-arch1-2
Describe the bug
First, I'm not actually sure where this bug belongs, because I don't quite understand every part of it.
I noticed, that uncommenting a line in PHP sometimes results in commenting the commented code with block style comments:
$foo = 1;
gcc
:// $foo = 1;
gcc
:/*// $foo = 1;*/
This happens when...
php
andphpdoc
are installed// ...
, it works as expected).I can imagine, it's expected behavior somehow, but practically it's unintuitive at best. I wonder if this is something
ts-comments.nvim
can fix/improve or if there's some other approach to change this behavior.Steps To Reproduce
Example PHP file (
repro.php
):nvim -u repro.lua repro.php
/priv<CR>gcc
-> line is commented; cursor is on the first slash of// private...
gcc
-> line is now wrapped with a blockwise commentu
ndo -> cursor is on the first slash, again0gcc
-> line is uncommentedExpected Behavior
The code is uncommented.
Repro