refactor: separate adapter-to-scheme lookup table
This commit is contained in:
parent
2e6d68453f
commit
1879339442
3 changed files with 11 additions and 11 deletions
|
|
@ -81,7 +81,7 @@ local _connections = {}
|
|||
---@param allow_retry nil|boolean
|
||||
local function get_connection(url, allow_retry)
|
||||
local res = parse_url(url)
|
||||
res.scheme = config.adapters.ssh
|
||||
res.scheme = config.adapter_to_scheme.ssh
|
||||
res.path = ""
|
||||
local key = url_to_str(res)
|
||||
local conn = _connections[key]
|
||||
|
|
|
|||
|
|
@ -75,7 +75,10 @@ M.setup = function(opts)
|
|||
M[k] = v
|
||||
end
|
||||
|
||||
vim.tbl_add_reverse_lookup(M.adapters)
|
||||
M.adapter_to_scheme = {}
|
||||
for k, v in pairs(M.adapters) do
|
||||
M.adapter_to_scheme[v] = k
|
||||
end
|
||||
M._adapter_by_scheme = {}
|
||||
if type(M.trash) == "string" then
|
||||
M.trash = vim.fn.fnamemodify(vim.fn.expand(M.trash), ":p")
|
||||
|
|
@ -116,7 +119,7 @@ M.get_trash_url = function()
|
|||
fs.mkdirp(oil_trash_dir)
|
||||
M.trash = oil_trash_dir
|
||||
end
|
||||
return M.adapters.files .. fs.os_to_posix_path(M.trash)
|
||||
return M.adapter_to_scheme.files .. fs.os_to_posix_path(M.trash)
|
||||
end
|
||||
|
||||
---@param scheme string
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ M.get_url_for_path = function(dir)
|
|||
if dir then
|
||||
local abspath = vim.fn.fnamemodify(dir, ":p")
|
||||
local path = fs.os_to_posix_path(abspath)
|
||||
return config.adapters.files .. path
|
||||
return config.adapter_to_scheme.files .. path
|
||||
else
|
||||
local bufname = vim.api.nvim_buf_get_name(0)
|
||||
return M.get_buffer_parent_url(bufname)
|
||||
|
|
@ -175,7 +175,7 @@ M.get_buffer_parent_url = function(bufname)
|
|||
local scheme, path = util.parse_url(bufname)
|
||||
if not scheme then
|
||||
local parent, basename
|
||||
scheme = config.adapters.files
|
||||
scheme = config.adapter_to_scheme.files
|
||||
if bufname == "" then
|
||||
parent = fs.os_to_posix_path(vim.fn.getcwd())
|
||||
else
|
||||
|
|
@ -189,7 +189,7 @@ M.get_buffer_parent_url = function(bufname)
|
|||
local adapter = config.get_adapter_by_scheme(scheme)
|
||||
local parent_url
|
||||
if adapter.get_parent then
|
||||
local adapter_scheme = config.adapters[adapter.name]
|
||||
local adapter_scheme = config.adapter_to_scheme[adapter.name]
|
||||
parent_url = adapter.get_parent(adapter_scheme .. path)
|
||||
else
|
||||
local parent = pathutil.parent(path)
|
||||
|
|
@ -410,7 +410,7 @@ local function maybe_hijack_directory_buffer(bufnr)
|
|||
end
|
||||
util.rename_buffer(
|
||||
bufnr,
|
||||
util.addslash(config.adapters.files .. vim.fn.fnamemodify(bufname, ":p"))
|
||||
util.addslash(config.adapter_to_scheme.files .. vim.fn.fnamemodify(bufname, ":p"))
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -504,10 +504,7 @@ M.setup = function(opts)
|
|||
|
||||
local patterns = {}
|
||||
for scheme in pairs(config.adapters) do
|
||||
-- We added a reverse lookup to config.adapters, so filter the keys
|
||||
if vim.endswith(scheme, "://") then
|
||||
table.insert(patterns, scheme .. "*")
|
||||
end
|
||||
table.insert(patterns, scheme .. "*")
|
||||
end
|
||||
local scheme_pattern = table.concat(patterns, ",")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue