Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): compile all themes inst of 1 mult times #290

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Issues Fix

- Fixed few regex-based/legacy highlight corrections (fixed #285)
- Closed #251
- Fixed darkened sidebars when disabling `options.sidebars.disabled`
- Fixes #311
- 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
- Fixed darkened sidebars when disabling `options.sidebars.disabled`
- Fixes #311

## [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 Down Expand Up @@ -68,8 +72,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 @@ -97,6 +99,7 @@ Bellow is the error message:
tmpfile
)
)

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