Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 18 additions & 4 deletions lua/Comment/ft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,14 @@ end
---print('Lang:', tree:lang())
---@usage ]]
function ft.contains(tree, range)
for lang, child in pairs(tree:children()) do
if not tree then
return nil
end
local ok, children = pcall(tree.children, tree)
if not ok or not children then
return tree
end
for lang, child in pairs(children) do
if lang ~= 'comment' and child:contains(range) then
return ft.contains(child, range)
end
Expand All @@ -297,14 +304,21 @@ function ft.calculate(ctx)
return ft.get(vim.bo.filetype, ctx.ctype) --[[ @as string ]]
end

local lang = ft.contains(parser, {
local tree = ft.contains(parser, {
ctx.range.srow - 1,
ctx.range.scol,
ctx.range.erow - 1,
ctx.range.ecol,
}):lang()
})
local lang = tree and tree:lang()

return ft.get(lang, ctx.ctype) or ft.get(vim.bo.filetype, ctx.ctype) --[[ @as string ]]
if lang then
local result = ft.get(lang, ctx.ctype)
if result then
return result
end
end
return ft.get(vim.bo.filetype, ctx.ctype) --[[ @as string ]]
end

---@export ft
Expand Down
2 changes: 1 addition & 1 deletion lua/Comment/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ end
---@param ... unknown
function U.catch(fn, ...)
xpcall(fn, function(err)
vim.notify(string.format('[Comment.nvim] %s', err.msg), vim.log.levels.WARN)
vim.notify(string.format('[Comment.nvim] %s', tostring(err)), vim.log.levels.WARN)
end, ...)
end

Expand Down