fix(comments): better way of using ts-context-commentstring with native comments

This commit is contained in:
Folke Lemaitre
2024-05-18 12:05:19 +02:00
parent 72abb893ac
commit 1d23c98da1

View File

@ -188,24 +188,18 @@ return {
opts = {
enable_autocmd = false,
},
},
{
import = "lazyvim.plugins.extras.coding.mini-comment",
enabled = function()
init = function()
if vim.fn.has("nvim-0.10") == 1 then
-- Majestically override the native `get_commentstring` function.
vim.schedule(function()
LazyVim.inject.set_upvalue(
LazyVim.inject.get_upvalue(require("vim._comment").textobject, "get_comment_parts"),
"get_commentstring",
function()
return require("ts_context_commentstring.internal").calculate_commentstring() or vim.bo.commentstring
end
)
end)
else
return true
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
end
end,
},
{
import = "lazyvim.plugins.extras.coding.mini-comment",
enabled = vim.fn.has("nvim-0.10") == 0,
},
}