Skip to content

Commit

Permalink
feat(mini.comment): added ts-context-commentstring back and made it w…
Browse files Browse the repository at this point in the history
…ork with mini.comment
  • Loading branch information
folke committed May 23, 2023
1 parent 7443eff commit 89db015
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lua/lazyvim/plugins/coding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,18 @@ return {
},

-- comments
{ "JoosepAlviste/nvim-ts-context-commentstring", lazy = true },
{
"echasnovski/mini.comment",
event = "VeryLazy",
config = function(_, opts)
local c = require("mini.comment")
c.setup(opts)
local H = require("lazyvim.util").get_upvalue(c.setup, "H")
H.get_commentstring = function()
return require("ts_context_commentstring.internal").calculate_commentstring() or vim.bo.commentstring
end
end,
opts = {},
},

Expand Down
14 changes: 14 additions & 0 deletions lua/lazyvim/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ function M.fg(name)
return fg and { fg = string.format("#%06x", fg) }
end

function M.get_upvalue(func, name)
local i = 1
while true do
local n, v = debug.getupvalue(func, i)
if not n then
break
end
if n == name then
return v
end
i = i + 1
end
end

---@param fn fun()
function M.on_very_lazy(fn)
vim.api.nvim_create_autocmd("User", {
Expand Down

0 comments on commit 89db015

Please sign in to comment.