Files
Justin M. Keyes 5a37eb7a49 feat(lua): vim.uri #24527
Problem:
- `vim.fs.abspath('fugitive:///a')` returns "<CWD>/fugitive:/a", so
  filetype functions get a mangled path for URI buffers.
- `vim.fs.root()` doesn't accept "file://" URIs.
- No URI parser, so modules use ad-hoc scheme patterns, e.g.
  `vim.ui.open('~/a:b')` treats the path as a URL.

Solution:
- Introduce `vim.uri.parse()`, and use it everywhere.
  - DWIM: a one-letter "scheme" is a drive letter.
- `vim.fs.abspath()` returns URLs as-is.
- Expose `vim.uri` a module. Deprecate the old `vim.uri_xx()` names.
2026-11-01 13:20:08 -05:00

113 lines
1.9 KiB
Lua

if vim.g.loaded_nvim_zip_plugin ~= nil or vim.fn.exists('#zip') == 1 then
return
end
vim.g.loaded_nvim_zip_plugin = true
local api = vim.api
-- Extension aliases inherited from the legacy plugin:
-- https://github.com/neovim/neovim/blob/7ba955fe079d4aa2554fea8e7235651fafd40efb/runtime/plugin/zipPlugin.vim#L34-L35
---@type string[]
local extensions = {
'aar',
'apk',
'cbz',
'celzip',
'crtx',
'docm',
'docx',
'dotm',
'dotx',
'ear',
'epub',
'gcsx',
'glox',
'gqsx',
'ja',
'jar',
'kmz',
'odb',
'odc',
'odf',
'odg',
'odi',
'odm',
'odp',
'ods',
'odt',
'otc',
'otf',
'otg',
'oth',
'oti',
'otp',
'ots',
'ott',
'oxt',
'pkpass',
'potm',
'potx',
'ppam',
'ppsm',
'ppsx',
'pptm',
'pptx',
'sldx',
'thmx',
'vdw',
'war',
'whl',
'wsz',
'xap',
'xlam',
'xlsb',
'xlsm',
'xlsx',
'xltm',
'xltx',
'xpi',
'zip',
}
---@type string[]
local archive_patterns = {}
for _, extension in ipairs(extensions) do
archive_patterns[#archive_patterns + 1] = ('*.%s'):format(extension)
end
vim.keymap.set('n', '<Plug>(nvim-zip-extract)', function()
require('nvim.zip')._extract()
end, { silent = true, desc = 'Extract zip archive entry' })
local group = api.nvim_create_augroup('nvim.zip', { clear = true })
---@return boolean
local function legacy_loaded()
return vim.fn.exists('#zip') == 1
end
api.nvim_create_autocmd('BufReadCmd', {
group = group,
pattern = 'zip://*',
desc = 'Read zip archive entry',
callback = function(ev)
if legacy_loaded() then
return true
end
require('nvim.zip').read(ev.buf, ev.match)
end,
})
api.nvim_create_autocmd('BufReadCmd', {
group = group,
pattern = archive_patterns,
desc = 'Browse zip archives',
callback = function(ev)
if legacy_loaded() then
return true
end
if vim._core.path_is_url(ev.match) then
return
end
require('nvim.zip').browse(ev.buf, ev.match)
end,
})