mirror of
https://github.com/neovim/neovim.git
synced 2026-02-20 10:28:33 +00:00
fix: correctly capture uri scheme on windows (#16027)
closes https://github.com/neovim/neovim/issues/15261 * normalize uri path to forward slashes on windows * use a capture group on windows that avoids mistaking drive letters as uri scheme
This commit is contained in:
committed by
GitHub
parent
5fd4557573
commit
68b2a9e569
@@ -75,13 +75,22 @@ local function uri_from_fname(path)
|
||||
end
|
||||
|
||||
local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*):.*'
|
||||
local WINDOWS_URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*):[a-zA-Z]:.*'
|
||||
|
||||
--- Get a URI from a bufnr
|
||||
---@param bufnr (number): Buffer number
|
||||
---@return URI
|
||||
local function uri_from_bufnr(bufnr)
|
||||
local fname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local scheme = fname:match(URI_SCHEME_PATTERN)
|
||||
local volume_path = fname:match("^([a-zA-Z]:).*")
|
||||
local is_windows = volume_path ~= nil
|
||||
local scheme
|
||||
if is_windows then
|
||||
fname = fname:gsub("\\", "/")
|
||||
scheme = fname:match(WINDOWS_URI_SCHEME_PATTERN)
|
||||
else
|
||||
scheme = fname:match(URI_SCHEME_PATTERN)
|
||||
end
|
||||
if scheme then
|
||||
return fname
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user