-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat(foldtext): allow function() for virtual text components #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,13 @@ local defaultConfig = { | |
| enabled = true, | ||
| padding = 3, | ||
| lineCount = { | ||
| ---@type string | fun():string | ||
| 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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
There was a problem hiding this comment.
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.