Skip to content

Commit

Permalink
feat(cache): automatically reset topmods when a user changes a file f…
Browse files Browse the repository at this point in the history
…or a path on the rtp
  • Loading branch information
folke committed Mar 14, 2023
1 parent ea1a044 commit 5b7b8c5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lua/lazy/core/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,19 @@ function M.enable()
break
end
end
-- TODO: add an autocmd on BufWritePost that checks if its in a /lua folder
-- if thats the case, then reset the plugin path.
-- This will make sure we can properly load new top-level lua modules

-- this will reset the top-mods in case someone adds a new
-- top-level lua module to a path already on the rtp
vim.api.nvim_create_autocmd("BufWritePost", {
group = vim.api.nvim_create_augroup("cache_topmods_reset", { clear = true }),
callback = function(event)
local bufname = event.match ---@type string
local idx = bufname:find("/lua/", 1, true)
if idx then
M.reset(bufname:sub(1, idx - 1))
end
end,
})
end

--- Disables the cache:
Expand All @@ -391,6 +401,7 @@ function M.disable()
end
end
table.insert(package.loaders, 2, vim._load_package)
vim.api.nvim_del_augroup_by_name("cache_topmods_reset")
end

--- Return the top-level `/lua/*` modules for this path
Expand Down

0 comments on commit 5b7b8c5

Please sign in to comment.