diff --git a/lua/oil/adapters/files.lua b/lua/oil/adapters/files.lua index a02a789..73d6972 100644 --- a/lua/oil/adapters/files.lua +++ b/lua/oil/adapters/files.lua @@ -6,13 +6,14 @@ local fs = require("oil.fs") local permissions = require("oil.adapters.files.permissions") local trash = require("oil.adapters.files.trash") local util = require("oil.util") +local uv = vim.uv or vim.loop local M = {} local FIELD_NAME = constants.FIELD_NAME local FIELD_META = constants.FIELD_META local function read_link_data(path, cb) - vim.loop.fs_readlink( + uv.fs_readlink( path, vim.schedule_wrap(function(link_err, link) if link_err then @@ -22,7 +23,7 @@ local function read_link_data(path, cb) if not fs.is_absolute(link) then stat_path = fs.join(vim.fn.fnamemodify(path, ":h"), link) end - vim.loop.fs_stat(stat_path, function(stat_err, stat) + uv.fs_stat(stat_path, function(stat_err, stat) cb(nil, link, stat) end) end @@ -48,7 +49,7 @@ local fs_stat_meta_fields = { local _, path = util.parse_url(parent_url) assert(path) local dir = fs.posix_to_os_path(path) - vim.loop.fs_stat(fs.join(dir, entry[FIELD_NAME]), cb) + uv.fs_stat(fs.join(dir, entry[FIELD_NAME]), cb) end, } @@ -121,7 +122,7 @@ if not fs.is_windows then local _, path = util.parse_url(action.url) assert(path) path = fs.posix_to_os_path(path) - vim.loop.fs_stat(path, function(err, stat) + uv.fs_stat(path, function(err, stat) if err then return callback(err) end @@ -129,7 +130,7 @@ if not fs.is_windows then -- We are only changing the lower 12 bits of the mode local mask = bit.bnot(bit.lshift(1, 12) - 1) local old_mode = bit.band(stat.mode, mask) - vim.loop.fs_chmod(path, bit.bor(old_mode, action.value), callback) + uv.fs_chmod(path, bit.bor(old_mode, action.value), callback) end) end, } @@ -184,9 +185,9 @@ M.normalize_url = function(url, callback) local scheme, path = util.parse_url(url) assert(path) local os_path = vim.fn.fnamemodify(fs.posix_to_os_path(path), ":p") - vim.loop.fs_realpath(os_path, function(err, new_os_path) + uv.fs_realpath(os_path, function(err, new_os_path) local realpath = new_os_path or os_path - vim.loop.fs_stat( + uv.fs_stat( realpath, vim.schedule_wrap(function(stat_err, stat) local is_directory @@ -225,7 +226,8 @@ M.list = function(url, column_defs, callback) end callback(err, data) end - vim.loop.fs_opendir(dir, function(open_err, fd) + ---@diagnostic disable-next-line: param-type-mismatch + uv.fs_opendir(dir, function(open_err, fd) if open_err then if open_err:match("^ENOENT: no such file or directory") then -- If the directory doesn't exist, treat the list as a success. We will be able to traverse @@ -241,9 +243,9 @@ M.list = function(url, column_defs, callback) cb(read_err) return end - vim.loop.fs_readdir(fd, function(err, entries) + uv.fs_readdir(fd, function(err, entries) if err then - vim.loop.fs_closedir(fd, function() + uv.fs_closedir(fd, function() cb(err) end) return @@ -287,7 +289,7 @@ M.list = function(url, column_defs, callback) end) end else - vim.loop.fs_closedir(fd, function(close_err) + uv.fs_closedir(fd, function(close_err) if close_err then cb(close_err) else @@ -298,6 +300,7 @@ M.list = function(url, column_defs, callback) end) end read_next() + ---@diagnostic disable-next-line: param-type-mismatch end, 100) -- TODO do some testing for this end @@ -308,7 +311,7 @@ M.is_modifiable = function(bufnr) local _, path = util.parse_url(bufname) assert(path) local dir = fs.posix_to_os_path(path) - local stat = vim.loop.fs_stat(dir) + local stat = uv.fs_stat(dir) if not stat then return true end @@ -318,8 +321,8 @@ M.is_modifiable = function(bufnr) return true end - local uid = vim.loop.getuid() - local gid = vim.loop.getgid() + local uid = uv.getuid() + local gid = uv.getgid() local rwx if uid == stat.uid then rwx = bit.rshift(stat.mode, 6) @@ -376,7 +379,7 @@ M.perform_action = function(action, cb) assert(path) path = fs.posix_to_os_path(path) if action.entry_type == "directory" then - vim.loop.fs_mkdir(path, 493, function(err) + uv.fs_mkdir(path, 493, function(err) -- Ignore if the directory already exists if not err or err:match("^EEXIST:") then cb() @@ -393,7 +396,7 @@ M.perform_action = function(action, cb) junction = false, } end - vim.loop.fs_symlink(target, path, flags, cb) + uv.fs_symlink(target, path, flags, cb) else fs.touch(path, cb) end diff --git a/lua/oil/adapters/ssh/connection.lua b/lua/oil/adapters/ssh/connection.lua index 3ebee70..00e0916 100644 --- a/lua/oil/adapters/ssh/connection.lua +++ b/lua/oil/adapters/ssh/connection.lua @@ -94,6 +94,7 @@ function SSHConnection.new(url) util.run_in_fullscreen_win(term_bufnr, function() term_id = vim.api.nvim_open_term(term_bufnr, { on_input = function(_, _, _, data) + ---@diagnostic disable-next-line: invisible pcall(vim.api.nvim_chan_send, self.jid, data) end, }) diff --git a/lua/oil/fs.lua b/lua/oil/fs.lua index ab6431b..3f2a489 100644 --- a/lua/oil/fs.lua +++ b/lua/oil/fs.lua @@ -1,9 +1,11 @@ local M = {} ----@type boolean -M.is_windows = vim.loop.os_uname().version:match("Windows") +local uv = vim.uv or vim.loop -M.is_mac = vim.loop.os_uname().sysname == "Darwin" +---@type boolean +M.is_windows = uv.os_uname().version:match("Windows") + +M.is_mac = uv.os_uname().sysname == "Darwin" ---@type string M.sep = M.is_windows and "\\" or "/" @@ -27,12 +29,12 @@ end ---@param path string ---@param cb fun(err: nil|string) M.touch = function(path, cb) - vim.loop.fs_open(path, "a", 420, function(err, fd) -- 0644 + uv.fs_open(path, "a", 420, function(err, fd) -- 0644 if err then cb(err) else assert(fd) - vim.loop.fs_close(fd, cb) + uv.fs_close(fd, cb) end end) end @@ -69,7 +71,7 @@ M.os_to_posix_path = function(path) end end -local home_dir = assert(vim.loop.os_homedir()) +local home_dir = assert(uv.os_homedir()) ---@param path string ---@return string @@ -98,30 +100,32 @@ M.mkdirp = function(dir) while mod ~= "" do mod = mod:sub(3) path = vim.fn.fnamemodify(dir, mod) - vim.loop.fs_mkdir(path, 493) + uv.fs_mkdir(path, 493) end end ---@param dir string ---@param cb fun(err: nil|string, entries: nil|{type: oil.EntryType, name: string}) M.listdir = function(dir, cb) - vim.loop.fs_opendir(dir, function(open_err, fd) + ---@diagnostic disable-next-line: param-type-mismatch + uv.fs_opendir(dir, function(open_err, fd) if open_err then return cb(open_err) end local read_next read_next = function() - vim.loop.fs_readdir(fd, function(err, entries) + uv.fs_readdir(fd, function(err, entries) if err then - vim.loop.fs_closedir(fd, function() + uv.fs_closedir(fd, function() cb(err) end) return elseif entries then + ---@diagnostic disable-next-line: param-type-mismatch cb(nil, entries) read_next() else - vim.loop.fs_closedir(fd, function(close_err) + uv.fs_closedir(fd, function(close_err) if close_err then cb(close_err) else @@ -132,6 +136,7 @@ M.listdir = function(dir, cb) end) end read_next() + ---@diagnostic disable-next-line: param-type-mismatch end, 100) -- TODO do some testing for this end @@ -140,15 +145,16 @@ end ---@param cb fun(err: nil|string) M.recursive_delete = function(entry_type, path, cb) if entry_type ~= "directory" then - return vim.loop.fs_unlink(path, cb) + return uv.fs_unlink(path, cb) end - vim.loop.fs_opendir(path, function(open_err, fd) + ---@diagnostic disable-next-line: param-type-mismatch + uv.fs_opendir(path, function(open_err, fd) if open_err then return cb(open_err) end local poll poll = function(inner_cb) - vim.loop.fs_readdir(fd, function(err, entries) + uv.fs_readdir(fd, function(err, entries) if err then return inner_cb(err) elseif entries then @@ -173,12 +179,13 @@ M.recursive_delete = function(entry_type, path, cb) end) end poll(function(err) - vim.loop.fs_closedir(fd) + uv.fs_closedir(fd) if err then return cb(err) end - vim.loop.fs_rmdir(path, cb) + uv.fs_rmdir(path, cb) end) + ---@diagnostic disable-next-line: param-type-mismatch end, 100) -- TODO do some testing for this end @@ -188,35 +195,36 @@ end ---@param cb fun(err: nil|string) M.recursive_copy = function(entry_type, src_path, dest_path, cb) if entry_type == "link" then - vim.loop.fs_readlink(src_path, function(link_err, link) + uv.fs_readlink(src_path, function(link_err, link) if link_err then return cb(link_err) end assert(link) - vim.loop.fs_symlink(link, dest_path, 0, cb) + uv.fs_symlink(link, dest_path, 0, cb) end) return end if entry_type ~= "directory" then - vim.loop.fs_copyfile(src_path, dest_path, { excl = true }, cb) + uv.fs_copyfile(src_path, dest_path, { excl = true }, cb) return end - vim.loop.fs_stat(src_path, function(stat_err, src_stat) + uv.fs_stat(src_path, function(stat_err, src_stat) if stat_err then return cb(stat_err) end assert(src_stat) - vim.loop.fs_mkdir(dest_path, src_stat.mode, function(mkdir_err) + uv.fs_mkdir(dest_path, src_stat.mode, function(mkdir_err) if mkdir_err then return cb(mkdir_err) end - vim.loop.fs_opendir(src_path, function(open_err, fd) + ---@diagnostic disable-next-line: param-type-mismatch + uv.fs_opendir(src_path, function(open_err, fd) if open_err then return cb(open_err) end local poll poll = function(inner_cb) - vim.loop.fs_readdir(fd, function(err, entries) + uv.fs_readdir(fd, function(err, entries) if err then return inner_cb(err) elseif entries then @@ -246,6 +254,7 @@ M.recursive_copy = function(entry_type, src_path, dest_path, cb) end) end poll(cb) + ---@diagnostic disable-next-line: param-type-mismatch end, 100) -- TODO do some testing for this end) end) @@ -256,7 +265,7 @@ end ---@param dest_path string ---@param cb fun(err: nil|string) M.recursive_move = function(entry_type, src_path, dest_path, cb) - vim.loop.fs_rename(src_path, dest_path, function(err) + uv.fs_rename(src_path, dest_path, function(err) if err then -- fs_rename fails for cross-partition or cross-device operations. -- We then fall back to a copy + delete diff --git a/lua/oil/init.lua b/lua/oil/init.lua index ba16347..ef9a832 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -6,7 +6,7 @@ local M = {} ---@field id nil|integer Will be nil if it hasn't been persisted to disk yet ---@field parsed_name nil|string ----@alias oil.EntryType "file"|"directory"|"socket"|"link" +---@alias oil.EntryType "file"|"directory"|"socket"|"link"|"fifo" ---@alias oil.TextChunk string|string[] ---@class oil.Adapter @@ -22,6 +22,9 @@ local M = {} ---@field read_file fun(bufnr: integer) ---@field write_file fun(bufnr: integer) +-- TODO remove after https://github.com/folke/neodev.nvim/pull/163 lands +---@diagnostic disable: undefined-field + ---Get the entry on a specific line (1-indexed) ---@param bufnr integer ---@param lnum integer @@ -214,7 +217,8 @@ M.get_buffer_parent_url = function(bufname) assert(path) -- TODO maybe we should remove this special case and turn it into a config if scheme == "term://" then - path = vim.fn.expand(path:match("^(.*)//")) + ---@type string + path = vim.fn.expand(path:match("^(.*)//")) ---@diagnostic disable-line: assign-type-mismatch return config.adapter_to_scheme.files .. util.addslash(path) end @@ -903,6 +907,7 @@ M.setup = function(opts) if not util.is_oil_bufnr(0) then vim.w.oil_original_buffer = vim.api.nvim_get_current_buf() vim.w.oil_original_view = vim.fn.winsaveview() + ---@diagnostic disable-next-line: param-type-mismatch vim.w.oil_original_alternate = vim.fn.bufnr("#") end end, diff --git a/lua/oil/mutator/init.lua b/lua/oil/mutator/init.lua index 3aa0eb5..5dd7ba3 100644 --- a/lua/oil/mutator/init.lua +++ b/lua/oil/mutator/init.lua @@ -504,6 +504,7 @@ M.try_write_changes = function(confirm) { all_errors[curbuf][1].lnum + 1, all_errors[curbuf][1].col } ) else + ---@diagnostic disable-next-line: param-type-mismatch local bufnr, errs = next(pairs(all_errors)) vim.api.nvim_win_set_buf(0, bufnr) pcall(vim.api.nvim_win_set_cursor, 0, { errs[1].lnum + 1, errs[1].col }) diff --git a/lua/oil/mutator/trie.lua b/lua/oil/mutator/trie.lua index 85ec40e..dbbe62c 100644 --- a/lua/oil/mutator/trie.lua +++ b/lua/oil/mutator/trie.lua @@ -116,7 +116,7 @@ end ---Add all actions affecting children of the url ---@param url string ---@param ret oil.InternalEntry[] ----@param filter nil|fun(entry: oil.InternalEntry): boolean +---@param filter nil|fun(entry: oil.Action): boolean function Trie:accum_children_of(url, ret, filter) local pieces = self:_url_to_path_pieces(url) local current = self.root @@ -136,7 +136,7 @@ end ---Add all actions at a specific path ---@param url string ---@param ret oil.InternalEntry[] ----@param filter? fun(entry: oil.InternalEntry): boolean +---@param filter? fun(entry: oil.Action): boolean function Trie:accum_actions_at(url, ret, filter) local pieces = self:_url_to_path_pieces(url) local current = self.root diff --git a/lua/oil/util.lua b/lua/oil/util.lua index dd2f5df..489fd51 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -150,6 +150,7 @@ M.rename_buffer = function(src_bufnr, dest_buf_name) -- rename logic. The only reason we can't use nvim_buf_set_name on files is because vim will -- think that the new buffer conflicts with the file next time it tries to save. if not vim.loop.fs_stat(dest_buf_name) then + ---@diagnostic disable-next-line: param-type-mismatch local altbuf = vim.fn.bufnr("#") -- This will fail if the dest buf name already exists local ok = pcall(vim.api.nvim_buf_set_name, src_bufnr, dest_buf_name)