2024-01-23 22:23:58 +01:00
|
|
|
---Tags used for filtering certain features
|
|
|
|
---@alias ComposerTag
|
|
|
|
--- | 'standalone' # True if running as a standalone application
|
|
|
|
--- | 'linux' # True if running on Linux
|
2024-01-22 23:14:16 +01:00
|
|
|
|
2024-01-23 22:23:58 +01:00
|
|
|
---@type table<ComposerTag, boolean>
|
2024-01-22 23:14:16 +01:00
|
|
|
local env = {
|
|
|
|
standalone = not vim.g.vscode,
|
|
|
|
linux = jit.os == 'Linux',
|
|
|
|
}
|
|
|
|
|
2024-01-23 22:23:58 +01:00
|
|
|
---@param tags ComposerTag | ComposerTag[]
|
|
|
|
---@return boolean
|
2024-01-22 23:14:16 +01:00
|
|
|
local function is(tags)
|
|
|
|
if type(tags) == 'string' then
|
|
|
|
return env[tags] or false
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, tag in ipairs(tags) do
|
|
|
|
if not env[tag] then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2024-01-23 22:23:58 +01:00
|
|
|
|
2024-01-22 23:14:16 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2024-01-23 22:23:58 +01:00
|
|
|
---@param tags ComposerTag | ComposerTag[]
|
2024-01-22 23:14:16 +01:00
|
|
|
local function when(tags)
|
|
|
|
local match = is(tags)
|
|
|
|
---@generic T
|
2024-01-23 22:23:58 +01:00
|
|
|
---@param value `T`
|
2024-01-22 23:14:16 +01:00
|
|
|
---@return T | nil
|
2024-01-23 22:23:58 +01:00
|
|
|
return function(value)
|
|
|
|
return match and value or nil
|
2024-01-22 23:14:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return function()
|
|
|
|
return is, when
|
|
|
|
end
|