JoosepAlviste / nvim-ts-context-commentstring

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
MIT License
1.13k stars 34 forks source link

Work-around to make this work with native comments in Neovim 0.10 #109

Closed folke closed 1 month ago

folke commented 3 months ago

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
mosheavni commented 3 months ago

it's weird because it's working without the plugin 2024-05-20_20-00-39 (1)

is it already integrated into core nvim?

folke commented 3 months ago

TSX files don't work properly with native comments

JoosepAlviste commented 3 months ago

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.

ArchWand commented 2 months ago

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).