mirror of
https://github.com/dcarrillo/dotfiles.git
synced 2024-12-22 17:28:01 +00:00
[neovim] Use vim.loop to read custom files
This commit is contained in:
parent
f28515a1d3
commit
47b946d65a
@ -19,14 +19,32 @@ local lazy_opts = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local projects = function ()
|
local uv = vim.loop
|
||||||
local file = io.open(os.getenv("HOME") .. "/.config/nvim/neovim-projects.json", "rb")
|
local function readFile(path)
|
||||||
if not file then return {} end
|
local fd = uv.fs_open(path, "r", 438)
|
||||||
|
if fd == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local stat = uv.fs_fstat(fd)
|
||||||
|
if fd == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local data = uv.fs_read(fd, stat.size, 0)
|
||||||
|
if data == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
assert(uv.fs_close(fd))
|
||||||
|
|
||||||
local jsonString = file:read "*a"
|
return data
|
||||||
file:close()
|
end
|
||||||
|
|
||||||
return vim.json.decode(jsonString)
|
local projects = function()
|
||||||
|
local data = readFile(os.getenv("HOME") .. "/.config/nvim/neovim-projects.json")
|
||||||
|
if data then
|
||||||
|
return vim.json.decode(data)
|
||||||
|
else
|
||||||
|
return {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require("lazy").setup({
|
require("lazy").setup({
|
||||||
|
Loading…
Reference in New Issue
Block a user