Skip to content

Commit aa1e1ec

Browse files
committed
fix #2981: nvim-tree root changed when navigating with LSP
1 parent 82ab19e commit aa1e1ec

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lua/nvim-tree/utils.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ local function has_parentheses_and_brackets(path)
7070
return false
7171
end
7272

73+
--- Path normalizations for windows only
74+
local function win_norm_path(path)
75+
local norm_path = path
76+
-- Normalize for issue #2862 and #2961
77+
if has_parentheses_and_brackets(norm_path) then
78+
norm_path = norm_path:gsub("/", "\\")
79+
end
80+
-- Normalize the drive letter
81+
norm_path = string.upper(string.sub(norm_path, 1, 1)) .. string.sub(norm_path, 2)
82+
return norm_path
83+
end
84+
7385
--- Get a path relative to another path.
7486
---@param path string
7587
---@param relative_to string|nil
@@ -80,8 +92,8 @@ function M.path_relative(path, relative_to)
8092
end
8193

8294
local norm_path = path
83-
if M.is_windows and has_parentheses_and_brackets(path) then
84-
norm_path = path:gsub("/", "\\")
95+
if M.is_windows then
96+
norm_path = win_norm_path(norm_path)
8597
end
8698

8799
local _, r = norm_path:find(M.path_add_trailing(relative_to), 1, true)

0 commit comments

Comments
 (0)