This is useful if a commenting plugin enables commenting a region that is not the full line. Currently, only Comment.nvim seems to support this.
For example, typing gciw in a TypeScript file here:
hello world!
^ cursor
Would result in this:
hello /* world */!
And not this:
// hello world!
The way we support it is to allow each commentstring configuration value to be a table with custom keys. Afterwards, the custom key can be passed to update_commentstring so that the commentstring returned matches the requested one if possible.
Here is how it can be configured with Comment.nvim:
require('Comment').setup {
pre_hook = function(ctx)
local U = require 'Comment.utils'
local type = ctx.ctype == U.ctype.line and '__default' or '__multiline'
return require('ts_context_commentstring.internal').calculate_commentstring {
key = type,
}
end,
}
This is useful if a commenting plugin enables commenting a region that is not the full line. Currently, only Comment.nvim seems to support this.
For example, typing
gciw
in a TypeScript file here:Would result in this:
And not this:
The way we support it is to allow each
commentstring
configuration value to be a table with custom keys. Afterwards, the custom key can be passed toupdate_commentstring
so that thecommentstring
returned matches the requested one if possible.Later, the
__multiline
comment is returned (if available) with:Here is how it can be configured with
Comment.nvim
:This feature was requested in https://github.com/numToStr/Comment.nvim/issues/10