Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lua/Comment/ft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ local L = setmetatable({
python = { M.hash }, -- Python doesn't have block comments
php = { M.cxx_l, M.cxx_b },
prisma = { M.cxx_l },
quarto = { M.html, M.html },
r = { M.hash }, -- R doesn't have block comments
readline = { M.hash },
rego = { M.hash },
Expand Down Expand Up @@ -145,6 +146,13 @@ local L = setmetatable({
end,
})

---Maps a filteype to a parsername for filetypes
---that don't have their own parser (yet).
---From: <https://github.com/nvim-treesitter/nvim-treesitter/blob/cda8b291ef6fc4e04036e2ea6cf0de8aa84c2656/lua/nvim-treesitter/parsers.lua#L4-L23>.
local filetype_to_parsername = {
quarto = "markdown",
}

local ft = {}

---Sets a commentstring(s) for a filetype/language
Expand Down Expand Up @@ -237,7 +245,9 @@ end
---@see comment.utils.CommentCtx
function ft.calculate(ctx)
local buf = A.nvim_get_current_buf()
local ok, parser = pcall(vim.treesitter.get_parser, buf)
local filetype = vim.bo.filetype
local parsername = filetype_to_parsername[filetype] or filetype
local ok, parser = pcall(vim.treesitter.get_parser, buf, parsername)

if not ok then
return ft.get(vim.bo.filetype, ctx.ctype) --[[ @as string ]]
Expand Down