-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Compiled colorscheme doesn't adapt to plugin changes/updates? #262
Comments
We only recompile if user's config changed or there was some changes in vim.api.nvim_create_user_command("GithubThemeCompile", function()
for name, _ in pairs(package.loaded) do
if name:match "^github-theme." then package.loaded[name] = nil end
end
require("github-theme").compile()
require("github-theme").load()
end, {}) We can also add an autocmd similar to catppuccin/nvim#L188-195 that recompile on save if the current buffer's path matches if vim.g.github_theme_debug then
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = "*/github-theme/*",
callback = function(opts)
vim.schedule(function()
require("github-theme").compile()
require("github-theme").load()
end)
end
})
end
This is what compile feature initially behaved in nightfox.nvim, we relied on impatient.nvim (which is now known as
I don't think so, the implementation is like 6 lines longer? local lines = {
[[return string.dump(function()]],
file_content,
[[end]]
}
local f = loadstring(table.concat(lines, "\n") |
I see that. I don't think this will catch uncommitted changes however (nor work with I believe there is already such a command provided by this repo/plugin. The thing is, I shouldn't have to manually run this command every time the plugin gets updated just for updates to take effect. Right now, at least in this repo/plugin, it seems that it doesn't work properly when I make a brand-new repo clone (which is indeed a changed git dir, no?) and completely restart Neovim. I'll investigate/test further when I get the chance, but I believe I found a bug in the implementation, and I can propose a fix soon.
Thanks. I understand. I believe this repo already has something similar to this as well.
I don't think bundling it is going to avoid double compilation because you have no way to know, or control, whether the user is using impatient.nvim, or the new Lua-loader, or some other solution, anyway. If I'm not mistaken, you may even be compiling unnecessarily due to this fact, which might even worsen performance (and lead to additional unnecessary files on the fs). I believe that, in the not-so-distant future (if not now already), the proper way to handle this will be Neovim's builtin compilation, and for several reasons. Firstly, the user gets to choose what they'd like to do and only has to choose one time in one central location (instead of trying to keep several different plugin configs in-sync with each other). Secondly, as is also the case when utilizing any other feature that's already built-in to the host environment, there'll be less code (duplication), simpler/cleaner codebases, fewer tests to write and maintain, and less maintenance overhead. I mean, just look at all the headaches that packer causes due to its custom compilation feature...I see notices/warnings on every other nvim plugin's README warning about it causing problems with their plugin, and now, it seems to be causing similar issues with this plugin too. I'm assuming that Neovim's loader won't have these issues, but even if it does, the user can easily disable it globally via one simple option in their vimrc instead of having to go through every single plugin config while keeping them all in-sync. Furthermore, is it really that much more beneficial to have just a few or so plugins capable of this feature (compiling/caching byte-code) when the majority of plugins do not? Most users have many/multiple plugins, and most of them do not have custom compilation built-in. In practice, the performance benefits are probably going to be relatively small compared to the alternative.
In this repo, the current implementation for this appears to be broken. That's why I created this issue, and hence the necessity for thorough/proper testing. I suggest considering Neovim's builtin compilation instead for this reason (among others). FWIW, the compiler file/module in this repo is actually 106 lines, not 6, and that's not including the additional code that it takes to use it. But it's not just about the size of the extra code/file, it's also the additional: maintenance overhead (e.g. refactoring, or writing/maintaining tests to make sure everything is working properly, both on its own, and when integrated), complexity of the codebase, number of tests, etc. Re-implementing several things that the host environment already provides leads to unnecessary maintenance overhead and duplicated code (including "duplicated" tests as these things are probably already tested upstream). It's just not as simple or clean, and it can complicate the codebase unnecessarily. That's fine if it's done for performance reasons, but only if the performance benefits are substantial enough (and worth the additional overhead). It's not just about the compiler feature either. I came across a few things in this repo that appeared to be re-implementing functionality that is already provided by Neovim or LuaJIT (e.g. bit operations, tables to string conversion, hashing, etc.), although maybe there is a reason for all of it that I am not aware of. |
No, this repo is based on nightfox which I haven't ported these features to yet.
The compiled files don't have the
These complications goes beyond just compiling to lua bytecode. It skips loading a bunch of modules like
In the past, catppuccin/nvim#94 was considered a slow colorscheme because of too many features. It was slower than even nvim-cmp and people didn't like that. Which is why we added the compiler to make startuptime goes straight from 10ms to 0.5ms
Where is the hashing function in luajit? Also it is an unordered table hashing which (to my knowledge) was never done before in a lua module. It was a result of hours of experimenting on my part.
I think it's pretty stable now as there's no issue reported on github or discord for a while. It's a trade-off that @ful1e5 was willing to take between adding more features and performance. |
github-nvim-theme/plugin/github_theme.vim Lines 4 to 5 in f09a14e
It's right here and it is also documented. |
That doesn't include the lua modules reloading -> compile -> load the theme again vim.api.nvim_create_user_command("GithubThemeCompile", function()
for name, _ in pairs(package.loaded) do
if name:match "^github-theme." then package.loaded[name] = nil end
end
require("github-theme").compile()
require("github-theme").load()
end, {}) |
I don't believe luajit has one, however, both Vim and Neovim have a sha256 fn
I see. So maybe it is necessary then (as a dependency for the compile feature). I could be wrong, but I think this sort of order-resistant hashing could be accomplished just by deterministically converting the table to a string (e.g. with
The compiler feature? I see. Nightfox might actually not have the bug I've been mentioning, but this repo does. The issue is here: local git_path = util.join_paths(debug.getinfo(1).source:sub(2, -23), ".git") and has to do with the fact that Are these colorschemes intended to be compatible with vim as well? Because I saw some references to |
These functions are very, very slow.
This is just a fast and "reliable" way to get the repo's root. But yeah, PR this change.
|
Currently, in the file `lua/github-theme/init.lua`, the code `util.join_paths(debug.getinfo(1).source:sub(2, -23), '.git')` returns an absolute path ending in `**/lua/.git` which is not, and will never be, a valid path to the `.git` directory. This means that recompilation does not currently occur when the plugin updates or changes (unless user config changes too) and that users may miss crucial updates (e.g. bug fixes). 1. Fix bug by changing `util.join_paths(debug.getinfo(1).source:sub(2, -23), '.git')` to `debug.getinfo(1).source .. '/../../../.git'`, and then use luv's/libuv's `fs_stat()` to get the last modified time of this path. This change does not rely on any particular filenames existing in the path, but it still relies on a hard-coded depth. If the path does not exist or the stat is unsuccessful, force recompilation (as otherwise plugin updates could be missed by many users). 2. Use libuv/luv `fs_stat()` to get `.git` dir's mtime with nanosecond precision (NOTE: this function is only available by default in Neovim, not Vim, however, it appears that this plugin isn't compatible with Vim currently anyway, so this shouldn't be an issue). 3. Correctly handle `.git` files, as `.git` is not always a directory. See projekt0n#262
Currently, in the file `lua/github-theme/init.lua`, the code `util.join_paths(debug.getinfo(1).source:sub(2, -23), '.git')` returns an absolute path ending in `**/lua/.git` which is not, and will never be, a valid path to the `.git` directory. This means that recompilation does not currently occur when the plugin updates or changes (unless user config changes too) and that users may miss crucial updates (e.g. bug fixes). 1. Fix bug by changing `util.join_paths(debug.getinfo(1).source:sub(2, -23), '.git')` to `debug.getinfo(1).source .. '/../../../.git'`, and then use luv's/libuv's `fs_stat()` to get the last modified time of this path. This change does not rely on any particular filenames existing in the path, but it still relies on a hard-coded depth. If the path does not exist or the stat is unsuccessful, force recompilation (as otherwise plugin updates could be missed by many users). 2. Use libuv/luv `fs_stat()` to get `.git` dir's mtime with nanosecond precision (NOTE: this function is only available by default in Neovim, not Vim, however, it appears that this plugin isn't compatible with Vim currently anyway, so this shouldn't be an issue). 3. Correctly handle `.git` files, as `.git` is not always a directory. See projekt0n#262
Currently, in the file `lua/github-theme/init.lua`, the code `util.join_paths(debug.getinfo(1).source:sub(2, -23), '.git')` returns an absolute path ending in `**/lua/.git` which is not, and will never be, a valid path to the `.git` directory. This means that recompilation does not currently occur when the plugin updates or changes (unless user config changes too) and that users may miss crucial updates (e.g. bug fixes). 1. Fix bug by changing `util.join_paths(debug.getinfo(1).source:sub(2, -23), '.git')` to `debug.getinfo(1).source .. '/../../../.git'`, and then use luv's/libuv's `fs_stat()` to get the last modified time of this path. This change does not rely on any particular filenames existing in the path, but it still relies on a hard-coded depth. If the path does not exist or the stat is unsuccessful, force recompilation (as otherwise plugin updates could be missed by many users). 2. Use libuv/luv `fs_stat()` to get `.git` dir's mtime with nanosecond precision (NOTE: this function is only available by default in Neovim, not Vim, however, it appears that this plugin isn't compatible with Vim currently anyway, so this shouldn't be an issue). 3. Correctly handle `.git` files, as `.git` is not always a directory. See projekt0n#262
While #270 appears to have fixed the |
The reason Vim support is still included in the codebase is because it is built on Nightfox, which also has support for Vim and Neovim. During the refactoring process, I had to release the major version quickly as I had already delayed the release for too long. My intention was to have a strong foundation of theme structure to work with while retaining the previously supported features. Hence, I chose not to remove certain Vim implementations. There are a few key reasons why I decided against providing full Vim support. First, Vim has its own distinct ecosystem and a range of plugins specifically designed for it. Including full Vim support would require extensive effort to ensure compatibility with these plugins. Additionally, Neovim and Vim are evolving in different directions, which could potentially result in complications in the future. |
After doing some debugging recently, I think I stumbled upon something which may be the cause for the stale-cache issues that I'm experiencing (although I'd need to investigate more to be certain). Either way it should be fixed. The final hash is a direct string combination/concatenation of 2 parts, the hash of all settings (incl options, overrides, etc.) and then the literal mtime of the What needs to be done is to change the current impl to convert the path from
|
This appears to be mostly fixed at this point. 👍 (see #332 for a couple remaining edge-cases) The only other thing that I've noticed causing strange, hard-to-track-down bugs has to do with closures (captured values) and/or the use of Within this plugin it might be best to set (for downstream users), but not use ourselves, the |
- Hash entire config instead of just the table passed to `setup()`. This helps to ensure that a re-compile occurs when overrides are set outside of `setup()`. - Loading/sourcing colorscheme now causes re-compilation if config or overrides have changed, even if `setup()` has been called before. - Clear `vim.g.colors_name` before setting `vim.o.background` so that colorscheme is not reloaded recursively when setting `vim.o.background` (as opposed to using a variable to check for nested colorscheme load, which is what we were doing before). - fix(compiler): always write hash to filesystem whenever a compilation occurs, incl when `require('github-theme').compile()` is called directly. Related: projekt0n#262, projekt0n#340, projekt0n#341 Please enter the commit message for your changes. Lines starting th '%' will be ignored, and an empty message aborts the commit.
- Hash entire config instead of just the table passed to `setup()`. This helps to ensure that a recompilation occurs when overrides are set outside of `setup()`. - Loading/sourcing colorscheme now causes recompilation if config or overrides have changed, even if `setup()` has been called before. - Clear `vim.g.colors_name` before setting `vim.o.background` so that colorscheme is not reloaded recursively when setting `vim.o.background` (as opposed to using a variable to check for nested colorscheme load, which is what we were doing before). - fix(compiler): always write hash to filesystem when a compilation occurs, incl. when `require('github-theme').compile()` is called directly. Related: projekt0n#262, projekt0n#340, projekt0n#341 Please enter the commit message for your changes. Lines starting th '%' will be ignored, and an empty message aborts the commit.
- Hash entire config instead of just the table passed to `setup()`. This helps to ensure that a recompilation occurs when overrides are set outside of `setup()`. - Loading/sourcing colorscheme now causes recompilation if config or overrides have changed, even if `setup()` has been called before. - Clear `vim.g.colors_name` before setting `vim.o.background` so that colorscheme is not reloaded recursively when setting `vim.o.background` (as opposed to using a variable to check for nested colorscheme load, which is what we were doing before). - fix(compiler): always write hash to filesystem when a compilation occurs, incl. when `require('github-theme').compile()` is called directly. Related: #262, #340, #341
I'm not sure exactly what's going on (or the cause of this), but here's what happened. BTW I'm using
Plug
.In my vimrc, I changed
Plug 'projekt0n/github-nvim-theme'
toPlug '~/code/github-nvim-theme'
(i.e. I changed it to use my local fork that I'm currently developing on so that it'd be easier for me to observe and test changes that I make to the plugin's source code). I then restarted Neovim and realized that many, if not all, of the changes I had made in my fork weren't present or taking effect. To fix the issue, I had to manually runrm ~/.cache/nvim/github-theme/github*
and then restart Neovim again.Also, FWIW, Neovim introduced a new Lua loader in
v0.9.0
which shimsloadfile()
to compile and cache any Lua file that gets loaded in Neovim (including, presumably, any required file sinceloadfile()
probably underpinsrequire()
). However, it is documented as experimental atm and is only available fromv0.9.0
onwards I believe. Perhaps it is worth looking-into instead? It would cut-down on repo/plugin size, number of tests, and maintenance overhead if this new feature covers the our use-case(s). It would be on the user to enable this themselves in their vimrc. If I'm not mistaken, this new feature should be able to accomplish more or less the same thing as the current implementation that is bundled within this plugin does. See:help lua-loader
for details.The text was updated successfully, but these errors were encountered: