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