From 7aeb239a6a36c01c1f6a7256adf9615560b9bd21 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Sun, 20 Aug 2023 21:05:35 +0000 Subject: [PATCH] refactor: rename supports_xfer --- lua/oil/adapters/files.lua | 6 +++--- lua/oil/adapters/ssh.lua | 2 +- lua/oil/init.lua | 2 +- lua/oil/util.lua | 10 ++++++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lua/oil/adapters/files.lua b/lua/oil/adapters/files.lua index 9dc23c0..3cf5fa7 100644 --- a/lua/oil/adapters/files.lua +++ b/lua/oil/adapters/files.lua @@ -352,7 +352,7 @@ M.render_action = function(action) M.to_short_os_path(dest_path, action.entry_type) ) 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") end else @@ -409,7 +409,7 @@ M.perform_action = function(action, cb) dest_path = fs.posix_to_os_path(dest_path) fs.recursive_move(action.entry_type, src_path, dest_path, vim.schedule_wrap(cb)) 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") end elseif action.type == "copy" then @@ -423,7 +423,7 @@ M.perform_action = function(action, cb) dest_path = fs.posix_to_os_path(dest_path) fs.recursive_copy(action.entry_type, src_path, dest_path, cb) 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") end else diff --git a/lua/oil/adapters/ssh.lua b/lua/oil/adapters/ssh.lua index fc783c9..ac7ac93 100644 --- a/lua/oil/adapters/ssh.lua +++ b/lua/oil/adapters/ssh.lua @@ -338,7 +338,7 @@ M.perform_action = function(action, cb) end end -M.supports_xfer = { files = true } +M.supported_adapters_for_copy = { files = true } ---@param bufnr integer M.read_file = function(bufnr) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 1bc69bd..efdfec7 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -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 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 supports_xfer? table This and all other parts of cross-adapter actions are WIP and not a stable API. +---@field supported_adapters_for_copy? table 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 ---@diagnostic disable: undefined-field diff --git a/lua/oil/util.lua b/lua/oil/util.lua index 489fd51..55a151b 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -461,9 +461,15 @@ M.get_adapter_for_action = function(action) if action.dest_url then local dest_adapter = assert(config.get_adapter_by_scheme(action.dest_url)) 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 - 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 else error(