Skip to content

Commit

Permalink
feat(ft): add quarto support (#301)
Browse files Browse the repository at this point in the history
`quarto` is built on top `markdown` syntax. Docs: https://quarto.org/
  • Loading branch information
jmbuhr committed Feb 13, 2023
1 parent 1cd8e25 commit 418d311
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lua/Comment/ft.lua
Expand Up @@ -104,6 +104,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 @@ -146,6 +147,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 @@ -238,7 +246,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

0 comments on commit 418d311

Please sign in to comment.