feat(api): add get_current_url() for adapter-agnostic URL access
Problem: `get_current_dir()` returns nil for non-local adapters (SSH, S3, trash), leaving users with no public API to get the current buffer's location. Solution: add `get_current_url()` which returns the full canola URL for any adapter, or nil if not in a canola buffer. Based on: stevearc/oil.nvim#646
This commit is contained in:
parent
c6d41c6d75
commit
ee46f7278e
3 changed files with 25 additions and 2 deletions
|
|
@ -395,7 +395,17 @@ toggle_hidden() *canola.toggle_hi
|
||||||
|
|
||||||
|
|
||||||
get_current_dir({bufnr}): nil|string *canola.get_current_dir*
|
get_current_dir({bufnr}): nil|string *canola.get_current_dir*
|
||||||
Get the current directory
|
Get the current directory as a local filesystem path. Returns nil for
|
||||||
|
non-local adapters (SSH, S3, trash). See |canola.get_current_url| for an
|
||||||
|
adapter-agnostic alternative.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
{bufnr} `nil|integer`
|
||||||
|
|
||||||
|
get_current_url({bufnr}): nil|string *canola.get_current_url*
|
||||||
|
Get the current buffer's canola URL (e.g. "canola:///path/" or
|
||||||
|
"canola-ssh://host/path/"). Works for all adapters. Returns nil if the
|
||||||
|
buffer is not a canola buffer.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
{bufnr} `nil|integer`
|
{bufnr} `nil|integer`
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ issues against this fork.
|
||||||
| [#641](https://github.com/stevearc/oil.nvim/issues/641) | Flicker on `actions.parent` | open |
|
| [#641](https://github.com/stevearc/oil.nvim/issues/641) | Flicker on `actions.parent` | open |
|
||||||
| [#642](https://github.com/stevearc/oil.nvim/issues/642) | W10 warning under `nvim -R` | fixed |
|
| [#642](https://github.com/stevearc/oil.nvim/issues/642) | W10 warning under `nvim -R` | fixed |
|
||||||
| [#645](https://github.com/stevearc/oil.nvim/issues/645) | `close_float` action | fixed |
|
| [#645](https://github.com/stevearc/oil.nvim/issues/645) | `close_float` action | fixed |
|
||||||
| [#646](https://github.com/stevearc/oil.nvim/issues/646) | `get_current_dir` nil on SSH | open |
|
| [#646](https://github.com/stevearc/oil.nvim/issues/646) | `get_current_dir` nil on SSH | fixed — `get_current_url()` API |
|
||||||
| [#650](https://github.com/stevearc/oil.nvim/issues/650) | LSP `workspace.fileOperations` events | fixed |
|
| [#650](https://github.com/stevearc/oil.nvim/issues/650) | LSP `workspace.fileOperations` events | fixed |
|
||||||
| [#655](https://github.com/stevearc/oil.nvim/issues/655) | File statistics as virtual text | open |
|
| [#655](https://github.com/stevearc/oil.nvim/issues/655) | File statistics as virtual text | open |
|
||||||
| [#659](https://github.com/stevearc/oil.nvim/issues/659) | Mark and diff files in buffer | open |
|
| [#659](https://github.com/stevearc/oil.nvim/issues/659) | Mark and diff files in buffer | open |
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,19 @@ M.get_current_dir = function(bufnr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Get the current buffer's canola URL (e.g. "canola:///path/" or "canola-ssh://host/path/")
|
||||||
|
---@param bufnr? integer
|
||||||
|
---@return nil|string
|
||||||
|
M.get_current_url = function(bufnr)
|
||||||
|
local config = require('canola.config')
|
||||||
|
local util = require('canola.util')
|
||||||
|
local buf_name = vim.api.nvim_buf_get_name(bufnr or 0)
|
||||||
|
local scheme = util.parse_url(buf_name)
|
||||||
|
if scheme and config.adapters[scheme] then
|
||||||
|
return buf_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---Get the canola url for a given directory
|
---Get the canola url for a given directory
|
||||||
---@private
|
---@private
|
||||||
---@param dir nil|string When nil, use the cwd
|
---@param dir nil|string When nil, use the cwd
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue