-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(checker): checker will now save last check time and only check a…
…t configured frequency even after restarting Neovim
- Loading branch information
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local Util = require("lazy.util") | ||
local Config = require("lazy.core.config") | ||
|
||
---@type LazyState | ||
local M = {} | ||
|
||
---@class LazyState | ||
local defaults = { | ||
checker = { | ||
last_check = 0, | ||
}, | ||
} | ||
|
||
---@type LazyState | ||
local data = nil | ||
|
||
function M.read() | ||
pcall(function() | ||
---@diagnostic disable-next-line: cast-local-type | ||
data = vim.json.decode(Util.read_file(Config.options.state)) | ||
end) | ||
data = vim.tbl_deep_extend("force", {}, defaults, data or {}) | ||
end | ||
|
||
function M.write() | ||
vim.fn.mkdir(vim.fn.fnamemodify(Config.options.state, ":p:h"), "p") | ||
Util.write_file(Config.options.state, vim.json.encode(data)) | ||
end | ||
|
||
function M.__index(_, key) | ||
if not data then | ||
M.read() | ||
end | ||
return data[key] | ||
end | ||
|
||
function M.__setindex(_, key, value) | ||
if not data then | ||
M.read() | ||
end | ||
---@diagnostic disable-next-line: no-unknown | ||
data[key] = value | ||
end | ||
|
||
return setmetatable(M, M) |