* fix #2981: nvim-tree root changed when navigating with LSP * add error checks
This commit is contained in:
parent
2156bc08c9
commit
c22124b374
@ -70,6 +70,23 @@ local function has_parentheses_and_brackets(path)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Path normalizations for windows only
|
||||||
|
local function win_norm_path(path)
|
||||||
|
if path == nil then
|
||||||
|
return path
|
||||||
|
end
|
||||||
|
local norm_path = path
|
||||||
|
-- Normalize for issue #2862 and #2961
|
||||||
|
if has_parentheses_and_brackets(norm_path) then
|
||||||
|
norm_path = norm_path:gsub("/", "\\")
|
||||||
|
end
|
||||||
|
-- Normalize the drive letter
|
||||||
|
norm_path = norm_path:gsub("^%l:", function(drive)
|
||||||
|
return drive:upper()
|
||||||
|
end)
|
||||||
|
return norm_path
|
||||||
|
end
|
||||||
|
|
||||||
--- Get a path relative to another path.
|
--- Get a path relative to another path.
|
||||||
---@param path string
|
---@param path string
|
||||||
---@param relative_to string|nil
|
---@param relative_to string|nil
|
||||||
@ -80,8 +97,8 @@ function M.path_relative(path, relative_to)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local norm_path = path
|
local norm_path = path
|
||||||
if M.is_windows and has_parentheses_and_brackets(path) then
|
if M.is_windows then
|
||||||
norm_path = path:gsub("/", "\\")
|
norm_path = win_norm_path(norm_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, r = norm_path:find(M.path_add_trailing(relative_to), 1, true)
|
local _, r = norm_path:find(M.path_add_trailing(relative_to), 1, true)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user