fix: lint warning and test mocks for async file read
Problem: selene flagged unused err3 variable, and test mock_enums still mocked io.open instead of the new vim.uv.fs_* calls. Solution: rename err3 to _, replace io.open mock with synchronous vim.uv.fs_open/fs_fstat/fs_read/fs_close mocks using a sentinel fd.
This commit is contained in:
parent
71d5505fb8
commit
3776133815
2 changed files with 35 additions and 13 deletions
|
|
@ -193,7 +193,7 @@ function M:get_completions(ctx, callback)
|
||||||
on_all_done()
|
on_all_done()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.uv.fs_read(fd, stat.size, 0, function(err3, data)
|
vim.uv.fs_read(fd, stat.size, 0, function(_, data)
|
||||||
vim.uv.fs_close(fd)
|
vim.uv.fs_close(fd)
|
||||||
enums_content = data or ''
|
enums_content = data or ''
|
||||||
on_all_done()
|
on_all_done()
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,15 @@ local function mock_system()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local MOCK_FD = 99
|
||||||
|
|
||||||
local function mock_enums()
|
local function mock_enums()
|
||||||
local original_exepath = vim.fn.exepath
|
local original_exepath = vim.fn.exepath
|
||||||
local original_realpath = vim.uv.fs_realpath
|
local original_realpath = vim.uv.fs_realpath
|
||||||
local original_open = io.open
|
local original_fs_open = vim.uv.fs_open
|
||||||
|
local original_fs_fstat = vim.uv.fs_fstat
|
||||||
|
local original_fs_read = vim.uv.fs_read
|
||||||
|
local original_fs_close = vim.uv.fs_close
|
||||||
|
|
||||||
vim.fn.exepath = function(name)
|
vim.fn.exepath = function(name)
|
||||||
if name == 'ghostty' then
|
if name == 'ghostty' then
|
||||||
|
|
@ -72,24 +77,41 @@ local function mock_enums()
|
||||||
end
|
end
|
||||||
return original_realpath(path)
|
return original_realpath(path)
|
||||||
end
|
end
|
||||||
-- selene: allow(incorrect_standard_library_use)
|
vim.uv.fs_open = function(path, flags, mode, callback)
|
||||||
io.open = function(path, mode)
|
|
||||||
if path:match('ghostty%.bash$') then
|
if path:match('ghostty%.bash$') then
|
||||||
return {
|
callback(nil, MOCK_FD)
|
||||||
read = function()
|
return
|
||||||
return BASH_COMPLETION
|
|
||||||
end,
|
|
||||||
close = function() end,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
return original_open(path, mode)
|
return original_fs_open(path, flags, mode, callback)
|
||||||
|
end
|
||||||
|
vim.uv.fs_fstat = function(fd, callback)
|
||||||
|
if fd == MOCK_FD then
|
||||||
|
callback(nil, { size = #BASH_COMPLETION })
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return original_fs_fstat(fd, callback)
|
||||||
|
end
|
||||||
|
vim.uv.fs_read = function(fd, size, offset, callback)
|
||||||
|
if fd == MOCK_FD then
|
||||||
|
callback(nil, BASH_COMPLETION)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return original_fs_read(fd, size, offset, callback)
|
||||||
|
end
|
||||||
|
vim.uv.fs_close = function(fd, ...)
|
||||||
|
if fd == MOCK_FD then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return original_fs_close(fd, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
vim.fn.exepath = original_exepath
|
vim.fn.exepath = original_exepath
|
||||||
vim.uv.fs_realpath = original_realpath
|
vim.uv.fs_realpath = original_realpath
|
||||||
-- selene: allow(incorrect_standard_library_use)
|
vim.uv.fs_open = original_fs_open
|
||||||
io.open = original_open
|
vim.uv.fs_fstat = original_fs_fstat
|
||||||
|
vim.uv.fs_read = original_fs_read
|
||||||
|
vim.uv.fs_close = original_fs_close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue