diff --git a/CHANGELOG.md b/CHANGELOG.md index a778c68..2e6c9dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lua/github-theme/init.lua b/lua/github-theme/init.lua index 37e4208..56bb5b1 100644 --- a/lua/github-theme/init.lua +++ b/lua/github-theme/init.lua @@ -72,26 +72,21 @@ 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') @@ -99,11 +94,22 @@ M.setup = function(opts) 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() diff --git a/lua/github-theme/override.lua b/lua/github-theme/override.lua index a3fc15f..8cd2a9e 100644 --- a/lua/github-theme/override.lua +++ b/lua/github-theme/override.lua @@ -1,4 +1,3 @@ -local collect = require('github-theme.lib.collect') local M = {} function M.reset()