Work-around to make this work with native comments in Neovim 0.10
folke opened this issue ยท 4 comments
This is not really a bug report, but maybe something to add to the wiki?
This is a work-around I use in LazyVim to use nvim-ts-context-commentstring together with native comments:
local get_option = vim.filetype.get_option
vim.filetype.get_option = function(filetype, option)
return option == "commentstring"
and require("ts_context_commentstring.internal").calculate_commentstring()
or get_option(filetype, option)
end
TSX files don't work properly with native comments
Thanks! I was wondering how best to support native commenting and this seems like a nice solution. Wrote it down in the Wiki page ๐
I'm now wondering if we could use this same approach by default, out of the box, instead of using the CursorHold
autocommand. It seems like it would work more reliably and we'd be able to get rid of some unnecessary (and error prone) logic and configuration. I don't see any disadvantages over the autocommand approach ๐ค
Will give it a think for a little bit. I'll keep the issue open until then.
The only thing preventing me from using nvim-ts-context-commentstring with native comments is that it appears to clobber cursorwant. Wrapping it in a commenting plugin delays the clobber until the comment keybind is used; is there a way to force this behavior naturally (i.e. only recalculate on the comment keybind).