Compare commits
2 commits
9fc34cb6fd
...
79237aef8a
| Author | SHA1 | Date | |
|---|---|---|---|
| 79237aef8a | |||
| 12d161c1ce |
1 changed files with 11 additions and 3 deletions
|
|
@ -38,7 +38,8 @@
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local logger = require('cp.log')
|
local CACHE_VERSION = 1
|
||||||
|
|
||||||
local cache_file = vim.fn.stdpath('data') .. '/cp-nvim.json'
|
local cache_file = vim.fn.stdpath('data') .. '/cp-nvim.json'
|
||||||
local cache_data = {}
|
local cache_data = {}
|
||||||
local loaded = false
|
local loaded = false
|
||||||
|
|
@ -65,9 +66,15 @@ function M.load()
|
||||||
|
|
||||||
local ok, decoded = pcall(vim.json.decode, table.concat(content, '\n'))
|
local ok, decoded = pcall(vim.json.decode, table.concat(content, '\n'))
|
||||||
if ok then
|
if ok then
|
||||||
cache_data = decoded
|
if decoded._version ~= CACHE_VERSION then
|
||||||
|
cache_data = {}
|
||||||
|
M.save()
|
||||||
else
|
else
|
||||||
logger.log('Could not decode json in cache file', vim.log.levels.ERROR)
|
cache_data = decoded
|
||||||
|
end
|
||||||
|
else
|
||||||
|
cache_data = {}
|
||||||
|
M.save()
|
||||||
end
|
end
|
||||||
loaded = true
|
loaded = true
|
||||||
end
|
end
|
||||||
|
|
@ -78,6 +85,7 @@ function M.save()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.fn.mkdir(vim.fn.fnamemodify(cache_file, ':h'), 'p')
|
vim.fn.mkdir(vim.fn.fnamemodify(cache_file, ':h'), 'p')
|
||||||
|
|
||||||
|
cache_data._version = CACHE_VERSION
|
||||||
local encoded = vim.json.encode(cache_data)
|
local encoded = vim.json.encode(cache_data)
|
||||||
local lines = vim.split(encoded, '\n')
|
local lines = vim.split(encoded, '\n')
|
||||||
vim.fn.writefile(lines, cache_file)
|
vim.fn.writefile(lines, cache_file)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue