Skip to content

Commit d96cc5f

Browse files
authored
feat: async-aware user config
1 parent 57453a3 commit d96cc5f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lua/cord/internal/activity/builder.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local logger = require 'cord.api.log'
22
local mappings = require 'cord.internal.activity.mappings'
33
local icons = require 'cord.api.icon'
44
local config = require 'cord.api.config'
5+
local async = require 'cord.core.async'
56

67
local function get_custom_asset(config, filename, filetype)
78
if not config.assets then return end
@@ -50,11 +51,11 @@ local function get_option(option, args)
5051
function() return 'config.get: variable ${' .. var .. '} = ' .. tostring(arg) end
5152
)
5253
if type(arg) == 'function' then
53-
local result = tostring(arg(args))
54+
local result = async.is_async(arg) and arg(args):get() or arg(args)
5455
logger.trace(
55-
function() return 'config.get: function variable ${' .. var .. '} = ' .. result end
56+
function() return 'config.get: function variable ${' .. var .. '} = ' .. tostring(result) end
5657
)
57-
return result
58+
return tostring(result)
5859
elseif arg ~= nil then
5960
return tostring(arg)
6061
end
@@ -66,7 +67,9 @@ local function get_option(option, args)
6667
logger.trace(function() return 'config.get: final string: ' .. tostring(option) end)
6768
end
6869

69-
local result = ty == 'function' and option(args) or option
70+
local result = ty == 'function'
71+
and (async.is_async(option) and option(args):get() or option(args))
72+
or option
7073
logger.trace(function() return 'config.get: returning ' .. tostring(type(result)) end)
7174
return result
7275
end
@@ -102,8 +105,8 @@ local function build_activity(opts)
102105
opts.text = get_option(custom_icon.text, opts)
103106
opts.filetype = override_type or opts.filetype
104107
opts.icon = get_option(custom_icon.icon, opts)
105-
or (custom_icon.type and icons.get(mappings.get_default_icon(custom_icon.type)))
106-
or opts.icon
108+
or (custom_icon.type and icons.get(mappings.get_default_icon(custom_icon.type)))
109+
or opts.icon
107110
end
108111
end
109112

lua/cord/internal/manager.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ local uv = vim.loop or vim.uv
6464
---@param ... any Arguments to pass if value is a function
6565
---@return T
6666
local function resolve(value, ...)
67-
if type(value) == 'function' then return value(...) end
67+
if type(value) == 'function' then
68+
if async.is_async(value) then
69+
return value(...):get()
70+
end
71+
return value(...)
72+
end
6873
return value
6974
end
7075

0 commit comments

Comments
 (0)