-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguages.lua
More file actions
63 lines (53 loc) · 1.54 KB
/
languages.lua
File metadata and controls
63 lines (53 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---@class peter.util.languages
local M = {}
--[[ ---------------------------------------------------------------------- ]]
--
--[[ ------------------- START OF PUBLIC API FUNCTIONS. ------------------- ]]
--
--[[ ---------------------------------------------------------------------- ]]
---Run `fn` on all language configs.
---@param fn fun(name:string, cfg:peter.lang.Config) Function to run for each language.
function M.for_each(fn)
local ok, languages = pcall(require, "peter.languages")
if not ok then
return
end
for name, cfg in pairs(languages or {}) do
fn(name, cfg)
end
end
---Extract "special" plugin specs from language config files.
---@return LazyPluginSpec[]
function M.extract_plugin_specs()
local function promote_plugin(cfg, plugin, fn)
local value = cfg.plugins[plugin]
if not value then
return
end
table.insert(cfg.plugins, fn(value))
cfg.plugins[plugin] = nil
end
local function promote_known_plugins(cfg)
local L = require("peter.util.plugins.languages")
for name, fn in pairs(L) do
promote_plugin(cfg, name, fn)
end
end
local LANG_MOD = require("peter.languages")
return vim
.iter(LANG_MOD)
:filter(function(_, cfg)
-- Maybe just use this:
-- return cfg.plugins
return cfg.plugins ~= nil and type(cfg.plugins) == "table"
end)
:map(function(name, cfg)
promote_known_plugins(cfg)
return name, cfg
end)
:fold({}, function(acc, _, cfg)
vim.list_extend(acc, cfg.plugins or {})
return acc
end)
end
return M