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
3 changes: 3 additions & 0 deletions lua/origami/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ local defaultConfig = {
enabled = true,
padding = 3,
lineCount = {
---@type string | fun():string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function signature does not match the type used (3 parameters), which is why the nvim type check fails.

template = "%d lines", -- `%d` is replaced with the number of folded lines
hlgroup = "Comment",
},
---@type boolean | fun():boolean
diagnosticsCount = true, -- uses hlgroups and icons from `vim.diagnostic.config().signs`
---@type boolean | fun():boolean
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function signature does not match the type used (3 parameters), which is why the nvim type check fails.

gitsignsCount = true, -- requires `gitsigns.nvim`
},
autoFold = {
Expand Down
22 changes: 19 additions & 3 deletions lua/origami/features/foldtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,33 @@ local function renderFoldedSegments(win, buf, foldstart)
local foldend = vim.fn.foldclosedend(foldstart)

-- get virtual text components
local lineCountText = config.foldtext.lineCount.template:format(foldend - foldstart)
local resolvedTemplate = config.foldtext.lineCount.template
if type(resolvedTemplate) == 'function' then
resolvedTemplate = resolvedTemplate(buf, foldstart, foldend)
end
local lineCountText = resolvedTemplate:format(foldend - foldstart)
local virtText = { ---@type Origami.VirtTextChunk[]
{ (" "):rep(config.foldtext.padding) },
{ lineCountText, { config.foldtext.lineCount.hlgroup } },
}
if config.foldtext.diagnosticsCount then
local show_diagnostics
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole block can be simplified as:

local showDiagnostics = config.foldtext.diagnosticsCount
if type(showDiagnostics) == "function" then showDiagnostics = showDiagnostics() end

if type(config.foldtext.diagnosticsCount) == "function" then
show_diagnostics = config.foldtext.diagnosticsCount()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the gitsigns function expect 3 parameters, but this one does not expect one? Wouldn't it make more sense to have both of them expect the same input?

else
show_diagnostics = config.foldtext.diagnosticsCount
end
if show_diagnostics then
local diagnostics = getDiagnosticsInFold(buf, foldstart, foldend)
if #diagnostics > 0 then table.insert(virtText, { " " }) end
vim.list_extend(virtText, diagnostics)
end
if config.foldtext.gitsignsCount then
local show_gitsigns
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same simplification as mentioned above can be done here

if type(config.foldtext.gitsignsCount) == "function" then
show_gitsigns = config.foldtext.gitsignsCount(buf, foldstart, foldend)
else
show_gitsigns = config.foldtext.gitsignsCount
end
if show_gitsigns then
local hunks = getGitHunksInFold(buf, foldstart, foldend)
if #hunks > 0 then table.insert(virtText, { " " }) end
vim.list_extend(virtText, hunks)
Expand Down
Loading