fix: use canonical path in windows (#977)
This commit is contained in:
@@ -118,7 +118,7 @@ function M.find_file(with_open)
|
||||
|
||||
local bufname = vim.fn.bufname()
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local filepath = vim.fn.fnamemodify(bufname, ':p')
|
||||
local filepath = utils.canonical_path(vim.fn.fnamemodify(bufname, ':p'))
|
||||
if not is_file_readable(filepath) then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -3,6 +3,8 @@ local uv = vim.loop
|
||||
|
||||
local M = {}
|
||||
|
||||
M.is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
|
||||
|
||||
function M.path_to_matching_str(path)
|
||||
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)'):gsub('(%_)', '(%%_)')
|
||||
end
|
||||
@@ -208,4 +210,13 @@ function M.file_exists(path)
|
||||
return error == nil
|
||||
end
|
||||
|
||||
--- @param path string
|
||||
--- @return string
|
||||
function M.canonical_path(path)
|
||||
if M.is_windows and path:match '^%a:' then
|
||||
return path:sub(1, 1):upper() .. path:sub(2)
|
||||
end
|
||||
return path
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user