Skip to content

Commit d0fe351

Browse files
committed
fix: type annotations and errors
1 parent 1051c25 commit d0fe351

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

lua/resession/config.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
local M = {}
22

3+
local uv = vim.uv or vim.loop
4+
35
local default_config = {
46
-- Options for automatically saving sessions on a timer
57
autosave = {
@@ -62,7 +64,7 @@ M.setup = function(config)
6264
resession.save_all({ notify = false })
6365
end,
6466
})
65-
autosave_timer = vim.loop.new_timer()
67+
autosave_timer = assert(uv.new_timer())
6668
autosave_timer:start(
6769
M.autosave.interval * 1000,
6870
M.autosave.interval * 1000,

lua/resession/files.lua

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
local M = {}
22

3+
local uv = vim.uv or vim.loop
4+
35
---@type boolean
4-
M.is_windows = vim.loop.os_uname().version:match("Windows")
6+
M.is_windows = uv.os_uname().version:match("Windows")
57

68
---@type boolean
7-
M.is_mac = vim.loop.os_uname().sysname == "Darwin"
9+
M.is_mac = uv.os_uname().sysname == "Darwin"
810

911
---@type string
1012
M.sep = M.is_windows and "\\" or "/"
@@ -23,7 +25,7 @@ end
2325
---@param filepath string
2426
---@return boolean
2527
M.exists = function(filepath)
26-
local stat = vim.loop.fs_stat(filepath)
28+
local stat = uv.fs_stat(filepath)
2729
return stat ~= nil and stat.type ~= nil
2830
end
2931

@@ -59,10 +61,10 @@ M.read_file = function(filepath)
5961
if not M.exists(filepath) then
6062
return nil
6163
end
62-
local fd = vim.loop.fs_open(filepath, "r", 420) -- 0644
63-
local stat = vim.loop.fs_fstat(fd)
64-
local content = vim.loop.fs_read(fd, stat.size)
65-
vim.loop.fs_close(fd)
64+
local fd = assert(uv.fs_open(filepath, "r", 420)) -- 0644
65+
local stat = assert(uv.fs_fstat(fd))
66+
local content = uv.fs_read(fd, stat.size)
67+
uv.fs_close(fd)
6668
return content
6769
end
6870

@@ -86,30 +88,31 @@ M.mkdir = function(dirname, perms)
8688
if not M.exists(parent) then
8789
M.mkdir(parent)
8890
end
89-
vim.loop.fs_mkdir(dirname, perms)
91+
uv.fs_mkdir(dirname, perms)
9092
end
9193
end
9294

9395
---@param filename string
9496
---@param contents string
9597
M.write_file = function(filename, contents)
9698
M.mkdir(vim.fn.fnamemodify(filename, ":h"))
97-
local fd = vim.loop.fs_open(filename, "w", 420) -- 0644
98-
vim.loop.fs_write(fd, contents)
99-
vim.loop.fs_close(fd)
99+
local fd = assert(uv.fs_open(filename, "w", 420)) -- 0644
100+
uv.fs_write(fd, contents)
101+
uv.fs_close(fd)
100102
end
101103

102104
---@param filename string
103105
M.delete_file = function(filename)
104106
if M.exists(filename) then
105-
vim.loop.fs_unlink(filename)
107+
uv.fs_unlink(filename)
106108
return true
107109
end
108110
end
109111

110112
---@param filename string
111113
---@param obj any
112114
M.write_json_file = function(filename, obj)
115+
---@diagnostic disable-next-line param-type-mismatch
113116
M.write_file(filename, vim.json.encode(obj))
114117
end
115118

lua/resession/init.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
local M = {}
22

3+
local uv = vim.uv or vim.loop
4+
35
local has_setup = false
46
local pending_config
57
local current_session
@@ -83,8 +85,11 @@ M.list = function(opts)
8385
if not files.exists(session_dir) then
8486
return {}
8587
end
86-
local fd = vim.loop.fs_opendir(session_dir, nil, 32)
87-
local entries = vim.loop.fs_readdir(fd)
88+
---@diagnostic disable-next-line param-type-mismatch
89+
local fd = assert(uv.fs_opendir(session_dir, nil, 32))
90+
---@diagnostic disable-next-line cast-type-mismatch
91+
---@cast fd luv_dir_t
92+
local entries = uv.fs_readdir(fd)
8893
local ret = {}
8994
while entries do
9095
for _, entry in ipairs(entries) do
@@ -95,9 +100,9 @@ M.list = function(opts)
95100
end
96101
end
97102
end
98-
entries = vim.loop.fs_readdir(fd)
103+
entries = uv.fs_readdir(fd)
99104
end
100-
vim.loop.fs_closedir(fd)
105+
uv.fs_closedir(fd)
101106
return ret
102107
end
103108

lua/resession/util.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local function get_option_scope(opt)
88
if vim.api.nvim_get_option_info2 then
99
return vim.api.nvim_get_option_info2(opt, {}).scope
1010
else
11+
---@diagnostic disable-next-line redundant-parameter
1112
return vim.api.nvim_get_option_info(opt).scope
1213
end
1314
end

0 commit comments

Comments
 (0)