refactor: fix type annotations for adapters
This commit is contained in:
parent
ff62fc28cd
commit
866085407f
7 changed files with 30 additions and 39 deletions
|
|
@ -213,19 +213,13 @@ end
|
||||||
|
|
||||||
---@param url string
|
---@param url string
|
||||||
---@param column_defs string[]
|
---@param column_defs string[]
|
||||||
---@param callback fun(err: nil|string, entries: nil|oil.InternalEntry[])
|
---@param cb fun(err?: string, fetch_more?: fun())
|
||||||
M.list = function(url, column_defs, callback)
|
M.list = function(url, column_defs, cb)
|
||||||
local _, path = util.parse_url(url)
|
local _, path = util.parse_url(url)
|
||||||
assert(path)
|
assert(path)
|
||||||
local dir = fs.posix_to_os_path(path)
|
local dir = fs.posix_to_os_path(path)
|
||||||
local fetch_meta = columns.get_metadata_fetcher(M, column_defs)
|
local fetch_meta = columns.get_metadata_fetcher(M, column_defs)
|
||||||
cache.begin_update_url(url)
|
|
||||||
local function cb(err, data)
|
|
||||||
if err or not data then
|
|
||||||
cache.end_update_url(url)
|
|
||||||
end
|
|
||||||
callback(err, data)
|
|
||||||
end
|
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
uv.fs_opendir(dir, function(open_err, fd)
|
uv.fs_opendir(dir, function(open_err, fd)
|
||||||
if open_err then
|
if open_err then
|
||||||
|
|
@ -238,11 +232,7 @@ M.list = function(url, column_defs, callback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local read_next
|
local read_next
|
||||||
read_next = function(read_err)
|
read_next = function()
|
||||||
if read_err then
|
|
||||||
cb(read_err)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
uv.fs_readdir(fd, function(err, entries)
|
uv.fs_readdir(fd, function(err, entries)
|
||||||
if err then
|
if err then
|
||||||
uv.fs_closedir(fd, function()
|
uv.fs_closedir(fd, function()
|
||||||
|
|
@ -254,8 +244,7 @@ M.list = function(url, column_defs, callback)
|
||||||
if inner_err then
|
if inner_err then
|
||||||
cb(inner_err)
|
cb(inner_err)
|
||||||
else
|
else
|
||||||
cb(nil, true)
|
cb(nil, read_next)
|
||||||
read_next()
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
for _, entry in ipairs(entries) do
|
for _, entry in ipairs(entries) do
|
||||||
|
|
|
||||||
|
|
@ -206,18 +206,12 @@ end
|
||||||
|
|
||||||
---@param url string
|
---@param url string
|
||||||
---@param column_defs string[]
|
---@param column_defs string[]
|
||||||
---@param callback fun(err: nil|string, entries: nil|oil.InternalEntry[])
|
---@param callback fun(err: nil|string, fetch_more?: fun())
|
||||||
M.list = function(url, column_defs, callback)
|
M.list = function(url, column_defs, callback)
|
||||||
local res = M.parse_url(url)
|
local res = M.parse_url(url)
|
||||||
|
|
||||||
cache.begin_update_url(url)
|
|
||||||
local conn = get_connection(url)
|
local conn = get_connection(url)
|
||||||
conn:list_dir(url, res.path, function(err, data)
|
conn:list_dir(url, res.path, callback)
|
||||||
if err or not data then
|
|
||||||
cache.end_update_url(url)
|
|
||||||
end
|
|
||||||
callback(err, data)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,9 @@ end
|
||||||
|
|
||||||
local dir_meta = {}
|
local dir_meta = {}
|
||||||
|
|
||||||
|
---@param url string
|
||||||
|
---@param path string
|
||||||
|
---@param callback fun(err: nil|string, fetch_more?: fun())
|
||||||
function SSHFS:list_dir(url, path, callback)
|
function SSHFS:list_dir(url, path, callback)
|
||||||
local path_postfix = ""
|
local path_postfix = ""
|
||||||
if path ~= "" then
|
if path ~= "" then
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ end
|
||||||
|
|
||||||
---@param url string
|
---@param url string
|
||||||
---@param column_defs string[]
|
---@param column_defs string[]
|
||||||
---@param cb fun(err: nil|string, entries: nil|oil.InternalEntry[])
|
---@param cb fun(err?: string, fetch_more?: fun())
|
||||||
M.list = function(url, column_defs, cb)
|
M.list = function(url, column_defs, cb)
|
||||||
cb(nil, cache.list_url(url))
|
cb()
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
|
|
|
||||||
|
|
@ -88,12 +88,14 @@ M.create_and_store_entry = function(parent_url, name, type)
|
||||||
return entry
|
return entry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param parent_url string
|
||||||
M.begin_update_url = function(parent_url)
|
M.begin_update_url = function(parent_url)
|
||||||
parent_url = util.addslash(parent_url)
|
parent_url = util.addslash(parent_url)
|
||||||
tmp_url_directory[parent_url] = url_directory[parent_url]
|
tmp_url_directory[parent_url] = url_directory[parent_url]
|
||||||
url_directory[parent_url] = {}
|
url_directory[parent_url] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param parent_url string
|
||||||
M.end_update_url = function(parent_url)
|
M.end_update_url = function(parent_url)
|
||||||
parent_url = util.addslash(parent_url)
|
parent_url = util.addslash(parent_url)
|
||||||
if not tmp_url_directory[parent_url] then
|
if not tmp_url_directory[parent_url] then
|
||||||
|
|
|
||||||
|
|
@ -10,17 +10,16 @@ local M = {}
|
||||||
---@alias oil.TextChunk string|string[]
|
---@alias oil.TextChunk string|string[]
|
||||||
|
|
||||||
---@class oil.Adapter
|
---@class oil.Adapter
|
||||||
---@field name string
|
---@field name string The unique name of the adapter (this will be set automatically)
|
||||||
---@field list fun(path: string, column_defs: string[], cb: fun(err: nil|string, entries: nil|oil.InternalEntry[]))
|
---@field list fun(path: string, column_defs: string[], cb: fun(err: nil|string, fetch_more: nil|fun())) Async function to list a directory. Entries should be stored in the cache.
|
||||||
---@field is_modifiable fun(bufnr: integer): boolean
|
---@field is_modifiable fun(bufnr: integer): boolean Return true if this directory is modifiable (allows for directories with read-only permissions).
|
||||||
---@field get_column fun(name: string): nil|oil.ColumnDefinition
|
---@field get_column fun(name: string): nil|oil.ColumnDefinition If the adapter has any adapter-specific columns, return them when fetched by name.
|
||||||
---@field normalize_url fun(url: string, callback: fun(url: string))
|
---@field normalize_url fun(url: string, callback: fun(url: string)) Before oil opens a url it will be normalized. This allows for link following, path normalizing, and converting an oil file url to the actual path of a file.
|
||||||
---@field get_parent nil|fun(bufname: string): string
|
---@field render_action? fun(action: oil.Action): string Render a mutation action for display in the preview window. Only needed if adapter is modifiable.
|
||||||
---@field supports_xfer nil|table<string, boolean>
|
---@field perform_action? fun(action: oil.Action, cb: fun(err: nil|string)) Perform a mutation action. Only needed if adapter is modifiable.
|
||||||
---@field render_action nil|fun(action: oil.Action): string
|
---@field read_file? fun(bufnr: integer) Used for adapters that deal with remote/virtual files. Read the contents of the file into a buffer.
|
||||||
---@field perform_action nil|fun(action: oil.Action, cb: fun(err: nil|string))
|
---@field write_file? fun(bufnr: integer) Used for adapters that deal with remote/virtual files. Write the contents of a buffer to the destination.
|
||||||
---@field read_file fun(bufnr: integer)
|
---@field supports_xfer? table<string, boolean> This and all other parts of cross-adapter actions are WIP and not a stable API.
|
||||||
---@field write_file fun(bufnr: integer)
|
|
||||||
|
|
||||||
-- TODO remove after https://github.com/folke/neodev.nvim/pull/163 lands
|
-- TODO remove after https://github.com/folke/neodev.nvim/pull/163 lands
|
||||||
---@diagnostic disable: undefined-field
|
---@diagnostic disable: undefined-field
|
||||||
|
|
|
||||||
|
|
@ -578,12 +578,14 @@ M.render_buffer_async = function(bufnr, opts, callback)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
adapter.list(bufname, config.columns, function(err, has_more)
|
cache.begin_update_url(bufname)
|
||||||
|
adapter.list(bufname, config.columns, function(err, fetch_more)
|
||||||
loading.set_loading(bufnr, false)
|
loading.set_loading(bufnr, false)
|
||||||
if err then
|
if err then
|
||||||
|
cache.end_update_url(bufname)
|
||||||
handle_error(err)
|
handle_error(err)
|
||||||
return
|
return
|
||||||
elseif has_more then
|
elseif fetch_more then
|
||||||
local now = vim.loop.hrtime() / 1e6
|
local now = vim.loop.hrtime() / 1e6
|
||||||
local delta = now - start_ms
|
local delta = now - start_ms
|
||||||
-- If we've been chugging for more than 40ms, go ahead and render what we have
|
-- If we've been chugging for more than 40ms, go ahead and render what we have
|
||||||
|
|
@ -595,7 +597,9 @@ M.render_buffer_async = function(bufnr, opts, callback)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
first = false
|
first = false
|
||||||
|
vim.defer_fn(fetch_more, 4)
|
||||||
else
|
else
|
||||||
|
cache.end_update_url(bufname)
|
||||||
-- done iterating
|
-- done iterating
|
||||||
finish()
|
finish()
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue