Skip to content

Commit c22124b

Browse files
authored
fix(#2981): windows: root changed when navigating with LSP (#2982)
* fix #2981: nvim-tree root changed when navigating with LSP * add error checks
1 parent 2156bc0 commit c22124b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lua/nvim-tree/utils.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ 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+
if path == nil then
76+
return path
77+
end
78+
local norm_path = path
79+
-- Normalize for issue #2862 and #2961
80+
if has_parentheses_and_brackets(norm_path) then
81+
norm_path = norm_path:gsub("/", "\\")
82+
end
83+
-- Normalize the drive letter
84+
norm_path = norm_path:gsub("^%l:", function(drive)
85+
return drive:upper()
86+
end)
87+
return norm_path
88+
end
89+
7390
--- Get a path relative to another path.
7491
---@param path string
7592
---@param relative_to string|nil
@@ -80,8 +97,8 @@ function M.path_relative(path, relative_to)
8097
end
8198

8299
local norm_path = path
83-
if M.is_windows and has_parentheses_and_brackets(path) then
84-
norm_path = path:gsub("/", "\\")
100+
if M.is_windows then
101+
norm_path = win_norm_path(norm_path)
85102
end
86103

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

0 commit comments

Comments
 (0)