refactor: rename supports_xfer

This commit is contained in:
Steven Arcangeli 2023-08-20 21:05:35 +00:00
parent f4819d8b43
commit 7aeb239a6a
4 changed files with 13 additions and 7 deletions

View file

@ -352,7 +352,7 @@ M.render_action = function(action)
M.to_short_os_path(dest_path, action.entry_type) M.to_short_os_path(dest_path, action.entry_type)
) )
else else
-- We should never hit this because we don't implement supports_xfer -- We should never hit this because we don't implement supported_adapters_for_copy
error("files adapter doesn't support cross-adapter move/copy") error("files adapter doesn't support cross-adapter move/copy")
end end
else else
@ -409,7 +409,7 @@ M.perform_action = function(action, cb)
dest_path = fs.posix_to_os_path(dest_path) dest_path = fs.posix_to_os_path(dest_path)
fs.recursive_move(action.entry_type, src_path, dest_path, vim.schedule_wrap(cb)) fs.recursive_move(action.entry_type, src_path, dest_path, vim.schedule_wrap(cb))
else else
-- We should never hit this because we don't implement supports_xfer -- We should never hit this because we don't implement supported_adapters_for_copy
cb("files adapter doesn't support cross-adapter move") cb("files adapter doesn't support cross-adapter move")
end end
elseif action.type == "copy" then elseif action.type == "copy" then
@ -423,7 +423,7 @@ M.perform_action = function(action, cb)
dest_path = fs.posix_to_os_path(dest_path) dest_path = fs.posix_to_os_path(dest_path)
fs.recursive_copy(action.entry_type, src_path, dest_path, cb) fs.recursive_copy(action.entry_type, src_path, dest_path, cb)
else else
-- We should never hit this because we don't implement supports_xfer -- We should never hit this because we don't implement supported_adapters_for_copy
cb("files adapter doesn't support cross-adapter copy") cb("files adapter doesn't support cross-adapter copy")
end end
else else

View file

@ -338,7 +338,7 @@ M.perform_action = function(action, cb)
end end
end end
M.supports_xfer = { files = true } M.supported_adapters_for_copy = { files = true }
---@param bufnr integer ---@param bufnr integer
M.read_file = function(bufnr) M.read_file = function(bufnr)

View file

@ -19,7 +19,7 @@ local M = {}
---@field perform_action? fun(action: oil.Action, cb: fun(err: nil|string)) Perform a mutation action. Only needed if adapter is modifiable. ---@field perform_action? fun(action: oil.Action, cb: fun(err: nil|string)) Perform a mutation action. Only needed if adapter is modifiable.
---@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 read_file? fun(bufnr: integer) Used for adapters that deal with remote/virtual files. Read the contents of the file into a buffer.
---@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 write_file? fun(bufnr: integer) Used for adapters that deal with remote/virtual files. Write the contents of a buffer to the destination.
---@field supports_xfer? table<string, boolean> This and all other parts of cross-adapter actions are WIP and not a stable API. ---@field supported_adapters_for_copy? table<string, boolean> Mapping of adapter name to true for all other adapters that can be used as a src or dest for move/copy actions.
-- 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

View file

@ -461,9 +461,15 @@ M.get_adapter_for_action = function(action)
if action.dest_url then if action.dest_url then
local dest_adapter = assert(config.get_adapter_by_scheme(action.dest_url)) local dest_adapter = assert(config.get_adapter_by_scheme(action.dest_url))
if adapter ~= dest_adapter then if adapter ~= dest_adapter then
if adapter.supports_xfer and adapter.supports_xfer[dest_adapter.name] then if
adapter.supported_adapters_for_copy
and adapter.supported_adapters_for_copy[dest_adapter.name]
then
return adapter return adapter
elseif dest_adapter.supports_xfer and dest_adapter.supports_xfer[adapter.name] then elseif
dest_adapter.supported_adapters_for_copy
and dest_adapter.supported_adapters_for_copy[adapter.name]
then
return dest_adapter return dest_adapter
else else
error( error(