Skip to content

Commit

Permalink
fix(compiler): compile all themes inst of 1 mult times
Browse files Browse the repository at this point in the history
Fix bug where the current theme gets compiled multiple times instead of
compiling all themes.
  • Loading branch information
tmillr committed Aug 7, 2023
1 parent 832d783 commit 44ab447
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

## [v1.0.1] - 23 July 2023

Expand Down
4 changes: 2 additions & 2 deletions lua/github-theme/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ function M.reset()
end

function M.get_compiled_info(opts)
opts = opts or {}
local output_path = opts.output_path or M.options.compile_path
local file_suffix = opts.file_suffix or M.options.compile_file_suffix
local style = opts.name or M.theme
return output_path, util.join_paths(output_path, style .. file_suffix)
return output_path, util.join_paths(output_path, (opts.theme or M.theme) .. file_suffix)
end

function M.hash()
Expand Down
12 changes: 9 additions & 3 deletions lua/github-theme/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ function M.reset()
require('github-theme.override').reset()
end

---Compiles all themes/styles with their current settings.
---@return nil
function M.compile()
require('github-theme.lib.log').clear()

local compiler = require('github-theme.lib.compiler')
local themes = require('github-theme.palette').themes
for _, style in ipairs(themes) do
compiler.compile({ style = style })
local current_theme = config.theme
for _, theme in ipairs(themes) do
-- Compile current theme last (see discussion in #290)
if theme ~= current_theme then
compiler.compile({ theme = theme })
end
end
compiler.compile({ theme = current_theme })
end

-- Avoid g:colors_name reloading
Expand Down
13 changes: 8 additions & 5 deletions lua/github-theme/lib/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ local function should_link(link)
return link and link ~= ''
end

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

Expand All @@ -39,7 +43,7 @@ vim.o.termguicolors = true
vim.g.colors_name = "%s"
vim.o.background = "%s"
]],
theme,
opts.theme,
background
),
}
Expand All @@ -65,8 +69,6 @@ vim.o.background = "%s"
end

table.insert(lines, 'end)')

opts.name = theme
local output_path, output_file = config.get_compiled_info(opts)
util.ensure_dir(output_path)

Expand Down Expand Up @@ -94,6 +96,7 @@ Bellow is the error message:
tmpfile
)
)

local efile = io.open(tmpfile, 'wb')
efile:write(table.concat(lines, '\n'))
efile:close()
Expand Down

0 comments on commit 44ab447

Please sign in to comment.