Skip to content

Commit

Permalink
feat: Inject object count defaults into user table
Browse files Browse the repository at this point in the history
This commit introduces a function to inject default properties for
certain object types into a user-provided table of such properties, just
in case the user did not provide them. This allows the user to only
override what they want for the object types they want to be counted.
  • Loading branch information
jakewvincent committed Jun 18, 2024
1 parent 8443990 commit 66f4ba6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lua/mkdnflow/foldtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,28 @@ local count_blocks = function(line_objs)
return counts
end

-- Function to inject defaults for any object type for which the user didn't specify necessary
-- information. Not using tbl_deep_extend here since we don't want to add object types that the user
-- doesn't want, if they have specified their own count opts table.
local inject_object_count_defaults = function(object_count_opts)
for k, v in pairs(object_count_opts) do
if M.default_count_opts[k] then
if not v.icon then
v.icon = M.default_count_opts[k].icon
end
if not v.count_method then
v.count_method = M.default_count_opts[k].count_method
else -- See if any subparts are needed
-- Use tbl_extend here, prioritizing user definitions
v.count_method = vim.tbl_extend('force', M.default_count_opts[k].count_method, v.count_method)
end
end
end
return object_count_opts
end

local count_objects = function(lines)
local object_count_opts = config.foldtext.object_count_opts()
local object_count_opts = inject_object_count_defaults(config.foldtext.object_count_opts())
-- Organize the object counts by tally method
local tally_methods = {
blocks = {},
Expand Down

0 comments on commit 66f4ba6

Please sign in to comment.