Skip to content

Commit 282aea9

Browse files
committed
fix(compiler): compile all themes inst of 1 mult times
Fix bug where the current theme gets compiled multiple times instead of compiling all themes.
1 parent 796ecdd commit 282aea9

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
### Issues Fix
2020

21+
- Fixed bug where the current theme gets compiled multiple times instead of compiling all themes
2122
- Fixed few regex-based/legacy highlight corrections (fixed #285)
2223
- Closed #251
2324

lua/github-theme/config.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ function M.reset()
9999
end
100100

101101
function M.get_compiled_info(opts)
102+
opts = opts or {}
102103
local output_path = opts.output_path or M.options.compile_path
103104
local file_suffix = opts.file_suffix or M.options.compile_file_suffix
104-
local style = opts.name or M.theme
105-
return output_path, util.join_paths(output_path, style .. file_suffix)
105+
return output_path, util.join_paths(output_path, (opts.theme or M.theme) .. file_suffix)
106106
end
107107

108108
function M.hash()

lua/github-theme/init.lua

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ function M.reset()
2424
require('github-theme.override').reset()
2525
end
2626

27+
---Compiles all themes/styles with their current settings.
28+
---@return nil
2729
function M.compile()
2830
require('github-theme.lib.log').clear()
29-
3031
local compiler = require('github-theme.lib.compiler')
3132
local themes = require('github-theme.palette').themes
32-
for _, style in ipairs(themes) do
33-
compiler.compile({ style = style })
33+
for _, theme in ipairs(themes) do
34+
compiler.compile({ theme = theme })
3435
end
3536
end
3637

@@ -94,8 +95,9 @@ M.setup = function(opts)
9495
local cached_path = util.join_paths(config.options.compile_path, 'cache')
9596
local cached = read_file(cached_path)
9697

97-
local git_path = util.join_paths(debug.getinfo(1).source:sub(2, -27), '.git')
98-
local git = vim.fn.getftime(git_path)
98+
local git_path =
99+
vim.fn.resolve(vim.fn.fnamemodify(debug.getinfo(1).source:sub(2, -27), ':p'))
100+
local git = vim.fn.getftime(util.join_paths(git_path:gsub('[\\/]+$', ''), '.git'))
99101
local hash = require('github-theme.lib.hash')(opts) .. (git == -1 and git_path or git)
100102

101103
if cached ~= hash then

lua/github-theme/lib/compiler.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ local function should_link(link)
2222
return link and link ~= ''
2323
end
2424

25+
---Compiles a single theme/style. `opts.theme` specifies the theme to compile,
26+
---otherwise the currently-set theme will be compiled.
27+
---@param opts? { theme: string }
28+
---@return nil
2529
function M.compile(opts)
2630
opts = opts or {}
27-
local theme = config.theme
28-
local spec = require('github-theme.spec').load(theme)
31+
opts.theme = opts.theme or config.theme
32+
local spec = require('github-theme.spec').load(opts.theme)
2933
local groups = require('github-theme.group').from(spec)
3034
local background = spec.palette.meta.light and 'light' or 'dark'
3135

@@ -39,7 +43,7 @@ vim.o.termguicolors = true
3943
vim.g.colors_name = "%s"
4044
vim.o.background = "%s"
4145
]],
42-
theme,
46+
opts.theme,
4347
background
4448
),
4549
}
@@ -65,8 +69,6 @@ vim.o.background = "%s"
6569
end
6670

6771
table.insert(lines, 'end)')
68-
69-
opts.name = theme
7072
local output_path, output_file = config.get_compiled_info(opts)
7173
util.ensure_dir(output_path)
7274

@@ -94,6 +96,7 @@ Bellow is the error message:
9496
tmpfile
9597
)
9698
)
99+
97100
local efile = io.open(tmpfile, 'wb')
98101
efile:write(table.concat(lines, '\n'))
99102
efile:close()

0 commit comments

Comments
 (0)