Skip to content

Commit

Permalink
fix(compiler): consider entire config when hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
tmillr committed Jul 16, 2024
1 parent c8c1e09 commit 4947fce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Closed #305 (no longer valid, fixed)
- Closed #292 (no longer valid, fixed)
- fix(config): `options.darken.floats` is not used (#345)
- fix(compiler): consider entire config when hashing (#350) (related to #262, #340, #341)

## [v1.0.2] - 03 May 2023

Expand Down
34 changes: 20 additions & 14 deletions lua/github-theme/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,44 @@ function M.load(opts)
end

M.setup = function(opts)
local override = require('github-theme.override')
local keys = { 'palettes', 'specs', 'groups' }
did_setup = true
opts = opts or {}

local override = require('github-theme.override')

-- New configs
if opts.options then
config.set_options(opts.options)
end

if opts.palettes ~= nil then
override.palettes = opts.palettes
end

if opts.specs ~= nil then
override.specs = opts.specs
end

if opts.groups ~= nil then
override.groups = opts.groups
for _, k in ipairs(keys) do
local v = opts[k]
if v ~= nil then
override[k] = v
end
end

local util = require('github-theme.util')
util.ensure_dir(config.options.compile_path)

local cached_path = util.join_paths(config.options.compile_path, 'cache')
local cached = read_file(cached_path)

local git_path =
vim.fn.fnamemodify(vim.fn.resolve(debug.getinfo(1).source:sub(2)), ':p:h:h:h')
local git = vim.fn.getftime(util.join_paths(git_path, '.git'))
local hash = require('github-theme.lib.hash')(opts) .. (git == -1 and git_path or git)

-- This is needed because neither `opts` nor `config` necessarily contain
-- everything we need to hash. For example, `opts` may not contain all
-- overrides and config currently in use (`setup()` might have been called
-- before, or maybe overrides were set directly and outside of `setup()`), and
-- `config` does not contain any of the overrides in use. Therefore, we need
-- to create a new table which contains everything in-use.
local dummy = { options = config.options }
for _, k in ipairs(keys) do
dummy[k] = override[k]
end

local hash = require('github-theme.lib.hash')(dummy) .. (git == -1 and git_path or git)

if cached ~= hash then
M.compile()
Expand Down
1 change: 0 additions & 1 deletion lua/github-theme/override.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local collect = require('github-theme.lib.collect')
local M = {}

function M.reset()
Expand Down

0 comments on commit 4947fce

Please sign in to comment.