Skip to content

Commit 79abae4

Browse files
committed
feat: load plugin groups asynchronously
1 parent be74efb commit 79abae4

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

lua/one_monokai/highlights/groups/init.lua

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
local groups = {}
44

55
---@type string[]
6-
local modules = {
6+
local plugins = {
77
"blink_cmp",
88
"bufferline",
99
"checkhealth",
1010
"conflict_markers",
11-
"core",
1211
"crates",
1312
"dashboard",
1413
"diff",
@@ -35,11 +34,23 @@ local modules = {
3534
"whichkey",
3635
}
3736

38-
for _, module in ipairs(modules) do
37+
for _, plugin in ipairs(plugins) do
3938
---@type table<string, vim.api.keyset.highlight>
40-
local hl_groups = require(("one_monokai.highlights.groups.%s"):format(module))
39+
local default_groups = require(("one_monokai.highlights.groups.%s"):format(plugin))
4140

42-
for name, attrs in pairs(hl_groups) do
41+
for name, attrs in pairs(default_groups) do
42+
groups[name] = attrs
43+
end
44+
end
45+
46+
local config = require "one_monokai.config"
47+
local colors = require "one_monokai.colors"
48+
49+
if config.highlights then
50+
---@type table<string, vim.api.keyset.highlight>
51+
local user_groups = config.highlights(colors)
52+
53+
for name, attrs in pairs(user_groups) do
4354
groups[name] = attrs
4455
end
4556
end

lua/one_monokai/highlights/init.lua

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,70 @@
11
---@class one_monokai.highlights
22
local highlights = {}
33

4+
---@type string[]
5+
local plugins = {
6+
"blink_cmp",
7+
"bufferline",
8+
"checkhealth",
9+
"conflict_markers",
10+
"crates",
11+
"dashboard",
12+
"diff",
13+
"flash",
14+
"fzf",
15+
"git_conflict",
16+
"indent_blankline",
17+
"lazy",
18+
"leap",
19+
"lsp",
20+
"mason",
21+
"mini",
22+
"nvim_cmp",
23+
"nvim_navic",
24+
"nvim_notify",
25+
"nvimtree",
26+
"oil",
27+
"rainbow_delimiters",
28+
"sj",
29+
"snacks",
30+
"telescope",
31+
"treesitter",
32+
"vim_illuminate",
33+
"whichkey",
34+
}
35+
436
---Set highlight groups.
537
---@param groups one_monokai.highlights.groups #Highlight groups.
638
local function set_highlight(groups)
739
local logs = require "one_monokai.logs"
840
local set_hl = vim.api.nvim_set_hl
941

1042
for name, attrs in pairs(groups) do
11-
local status_ok, err = pcall(set_hl, 0, name, attrs)
43+
local ok, err = pcall(set_hl, 0, name, attrs)
1244

13-
if not status_ok then
45+
if not ok then
1446
logs.error("highlights(%s): %s", name, err)
1547
end
1648
end
1749
end
1850

1951
---Load all highlight groups.
2052
function highlights.load()
21-
local config = require "one_monokai.config"
22-
local default = require "one_monokai.highlights.groups"
53+
local core_groups = require "one_monokai.highlights.groups.core"
54+
set_highlight(core_groups)
2355

24-
set_highlight(default)
56+
local async
57+
async = vim.uv.new_async(vim.schedule_wrap(function()
58+
local default_groups = require "one_monokai.highlights.groups"
59+
set_highlight(default_groups)
2560

26-
if config.highlights then
27-
local colors = require "one_monokai.colors"
61+
if async ~= nil then
62+
async:close()
63+
end
64+
end))
2865

29-
set_highlight(config.highlights(colors))
66+
if async ~= nil then
67+
async:send()
3068
end
3169
end
3270

0 commit comments

Comments
 (0)