feat(api): add get_current_url() for adapter-agnostic URL access (#119)

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:
Barrett Ruth 2026-03-10 22:21:52 -04:00 committed by GitHub
parent 9d29243faf
commit 9298b48c5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

View file

@ -395,7 +395,17 @@ toggle_hidden() *canola.toggle_hi
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:
{bufnr} `nil|integer`

View file

@ -114,7 +114,7 @@ issues against this fork.
| [#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 |
| [#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 |
| [#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 |

View file

@ -154,6 +154,19 @@ M.get_current_dir = function(bufnr)
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
---@private
---@param dir nil|string When nil, use the cwd