You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Solved] Blockwise comments broken with context-commentstring #10
The problem might be context-commenstring returning a linewise commentstring while running gbc and as you already know pre_hook overrides the commentstring.
And to be honest, IDK how to resolve this situation but I am planning to update the pre_hook method to give you the comment type ie. line/block, and mode ie. toggle/comment/uncomment as the arguments. I still don't know after this whether anyone we'll be able to fully resolve this or not.
@sQVe I was wondering, Would something like this work?
{
pre_hook=function(ctype)
localU=require('Comment.utils')
ifctype==U.ctype.linethen-- This will only run if you do linewise commentreturnrequire('ts_context_commentstring.internal').calculate_commentstring()
endend,
}
It's challenging to make both plugins sing together 😆 . As you can tell, this is more like an issue with context-commenstring itself, you can ask its maintainer for this use case.
I just tested this some more and it's working quite nicely but it does have some quirks. It seems like the commentstring is evaluated on the line where the cursor is.
If I select everything from <button to }} I would assume that it would set the commentstring to {/* and not //. Only when I select down to > it uses the correct {/*.
Please take a look at the branch and let me know if it works for your use-case!
PS: I'm also planning to add a way to customize the location where the treesitter tree traversal is started (currently only on the first non-blank char on the cursor's line). This would make it possible to comment something like this in JSX when running gciW:
changed the title [-]Blockwise comments broken with context-commentstring[/-][+][Solved] Blockwise comments broken with context-commentstring[/+]on Nov 3, 2021
Activity
numToStr commentedon Oct 8, 2021
The problem might be context-commenstring returning a linewise commentstring while running
gbcand as you already knowpre_hookoverrides the commentstring.Someone was also facing this dilemma https://www.reddit.com/r/neovim/comments/q35328/comment/hfstsld/?utm_source=share&utm_medium=web2x&context=3
sQVe commentedon Oct 8, 2021
That seems like the same issue, yeah.
This issue makes this look sort of broken though. Especially since it also just comments the first line if I have many selected.
sQVe commentedon Oct 8, 2021
This is an example:
simplescreenrecorder-2021-10-08_12.21.29.mp4
numToStr commentedon Oct 8, 2021
Yeah, I figured that much. As we know block comments should have both LHS and RHS part in the comments. But line comments only have RHS.
And to be honest, IDK how to resolve this situation but I am planning to update the
pre_hookmethod to give you the comment type ie. line/block, and mode ie. toggle/comment/uncomment as the arguments. I still don't know after this whether anyone we'll be able to fully resolve this or not.numToStr commentedon Oct 9, 2021
@sQVe I was wondering, Would something like this work?
{ pre_hook = function(ctype) local U = require('Comment.utils') if ctype == U.ctype.line then -- This will only run if you do linewise comment return require('ts_context_commentstring.internal').calculate_commentstring() end end, }[-]Blockwise commenting broken with commentstring[/-][+]Blockwise comments broken with context-commentstring[/+]sQVe commentedon Oct 9, 2021
That would be an improvement but would obviously disable the proper comment string when doing block commenting.
gbwould still not work for JSX.numToStr commentedon Oct 9, 2021
It's challenging to make both plugins sing together 😆 . As you can tell, this is more like an issue with
context-commenstringitself, you can ask its maintainer for this use case.JoosepAlviste commentedon Oct 14, 2021
Hey!
Would it solve the problem if
nvim-ts-context-commentstringcould be configured with multi-line and single-line comments explicitly?Something like:
Then, we could accept a preferred commenting style in
calculate_commentstring(default tosingle, for example):numToStr commentedon Oct 14, 2021
@JoosepAlviste Surely, that should fix this. As the
pre_hookis now aware of the type of the comment so anyone can do this.{ pre_hook = function(ctx) local U = require('Comment.utils') local ty = ctx.ctype == U.ctype.line and 'single' or 'multi' return require('ts_context_commentstring.internal').calculate_commentstring(ty) end, }sQVe commentedon Oct 18, 2021
I just tested this some more and it's working quite nicely but it does have some quirks. It seems like the
commentstringis evaluated on the line where the cursor is.Given this code:
If I select everything from
<buttonto}}I would assume that it would set thecommentstringto{/*and not//. Only when I select down to>it uses the correct{/*.xeluxee commentedon Oct 29, 2021
@sQVe @numToStr I think I've found a solution to this problem using internal
ts-context-commentstringfunctions:The above code is partially copied by
calculate_commentstringfunction fromts-context-commentstringAdd support for requesting multi-line comments
JoosepAlviste commentedon Nov 2, 2021
Hey! I added a configuration option to
nvim-ts-context-commentstringthat would allow to do this: JoosepAlviste/nvim-ts-context-commentstring#26The way to use it with
Comment.nvimwould be like so:Please take a look at the branch and let me know if it works for your use-case!
PS: I'm also planning to add a way to customize the location where the treesitter tree traversal is started (currently only on the first non-blank char on the cursor's line). This would make it possible to comment something like this in JSX when running
gciW:CC @sQVe @numToStr
sQVe commentedon Nov 2, 2021
@JoosepAlviste That works perfectly for my use-case in
jsx! 🎉chore: calculate commentstring for block comments
numToStr commentedon Nov 3, 2021
@JoosepAlviste That's wonderful, thanks. I personally don't use
nvim-ts-context-commentstringbut it seems to fix the issue as @sQVe said.@sQVe Feel free to close the issue.
[-]Blockwise comments broken with context-commentstring[/-][+][Solved] Blockwise comments broken with context-commentstring[/+]