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

@ -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