Skip to content

Commit 121f5c9

Browse files
authored
fix: use canonical path in windows (#977)
1 parent fdf63e5 commit 121f5c9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lua/nvim-tree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function M.find_file(with_open)
118118

119119
local bufname = vim.fn.bufname()
120120
local bufnr = api.nvim_get_current_buf()
121-
local filepath = vim.fn.fnamemodify(bufname, ':p')
121+
local filepath = utils.canonical_path(vim.fn.fnamemodify(bufname, ':p'))
122122
if not is_file_readable(filepath) then
123123
return
124124
end

lua/nvim-tree/utils.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ local uv = vim.loop
33

44
local M = {}
55

6+
M.is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
7+
68
function M.path_to_matching_str(path)
79
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)'):gsub('(%_)', '(%%_)')
810
end
@@ -208,4 +210,13 @@ function M.file_exists(path)
208210
return error == nil
209211
end
210212

213+
--- @param path string
214+
--- @return string
215+
function M.canonical_path(path)
216+
if M.is_windows and path:match '^%a:' then
217+
return path:sub(1, 1):upper() .. path:sub(2)
218+
end
219+
return path
220+
end
221+
211222
return M

0 commit comments

Comments
 (0)