@@ -4,6 +4,19 @@ local util = require("cyberdream.util")
4
4
local M = {}
5
5
local theme_cache_file = vim .fn .stdpath (" cache" ) .. " /cyberdream_cache.json"
6
6
7
+ -- sanitize a config object by removing functions
8
+ local function sanitize_config (cfg )
9
+ local sanitized = {}
10
+ for k , v in pairs (cfg ) do
11
+ if type (v ) == " table" then
12
+ sanitized [k ] = sanitize_config (v ) -- recursively sanitize nested tables
13
+ elseif type (v ) ~= " function" then
14
+ sanitized [k ] = v
15
+ end
16
+ end
17
+ return sanitized
18
+ end
19
+
7
20
--- build a cache file for a configured cyberdream theme
8
21
--- @param theme table
9
22
M .build = function (theme )
@@ -20,10 +33,13 @@ M.build = function(theme)
20
33
end
21
34
end
22
35
23
- theme .terminal_colors = # terminal_colors > 0 and terminal_colors or nil
24
- theme .config = config .options
36
+ -- Create a sanitized copy of the entire theme
37
+ local sanitized_theme = vim .deepcopy (theme )
38
+ sanitized_theme .config = sanitize_config (config .options )
39
+ sanitized_theme .terminal_colors = # terminal_colors > 0 and terminal_colors or nil
25
40
26
- cache :write (vim .json .encode (theme ))
41
+ -- Write the sanitized theme to cache
42
+ cache :write (vim .json .encode (sanitized_theme ))
27
43
util .notify (" Cache file written to " .. theme_cache_file )
28
44
end
29
45
@@ -69,8 +85,8 @@ M.load = function()
69
85
vim .api .nvim_set_hl (0 , group , opts )
70
86
end
71
87
72
- -- check if config has changed
73
- if not vim .deep_equal (theme .config , config .options ) then
88
+ -- check if config has changed (using sanitized comparison)
89
+ if not vim .deep_equal (theme .config , sanitize_config ( config .options ) ) then
74
90
M .build (require (" cyberdream.theme" ).setup ())
75
91
local notify = vim .defer_fn (function ()
76
92
util .notify (" Building cache...\n A restart may be required for changes to take effect." )
0 commit comments