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 Jul 31, 2023
1 parent 796ecdd commit 282aea9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Issues Fix

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

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: 7 additions & 5 deletions lua/github-theme/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ 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 })
for _, theme in ipairs(themes) do
compiler.compile({ theme = theme })
end
end

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

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

if cached ~= hash then
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 282aea9

Please sign in to comment.