Skip to content

Commit 757818d

Browse files
committed
_normalize_path: removed redundant table.remove in discarding drive path logic which I did not notice.
1 parent d90fc39 commit 757818d

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lua/plenary/path.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ path.sep = (function()
3838
else
3939
--qqq
4040
--vim.notify("os: " .. vim.inspect(os) .. ", U.is_msys: " .. vim.inspect(U.is_msys2), vim.log.levels.ERROR)
41-
-- msys2 works fine with backslashes as well as cmd.exe/powershell.exe
41+
-- msys2 works fine with forward slashes as well as cmd.exe/powershell.exe
4242
-- but not UNC paths if the paths will ever be supported.
4343
-- Maybe returning "/" as path separator can break something in existing logic.
4444
--return "/"
@@ -138,15 +138,23 @@ local function _normalize_path(filename, cwd)
138138

139139
local has = string.find(filename, path.sep .. "..", 1, true) or string.find(filename, ".." .. path.sep, 1, true)
140140

141+
--qqq
142+
--vim.notify("_normalize_path: has = " .. vim.inspect(has), vim.log.levels.WARN)
143+
--!qqq
144+
141145
if has then
142146
local is_abs = is_absolute(filename, path.sep)
147+
--qqq
148+
--vim.notify("_normalize_path: is_abs = " .. vim.inspect(is_abs), vim.log.levels.WARN)
149+
--!qqq
143150
local split_without_disk_name = function(filename_local)
144151
local parts = _split_by_separator(filename_local)
145152
-- Remove disk name part on Windows
146153
if is_abs and (path.sep == "\\" or U.is_msys2) then
154+
--qqq
155+
--vim.notify("_normalize_path: parts = " .. vim.inspect(parts), vim.log.levels.WARN)
156+
--!qqq
147157
table.remove(parts, 1)
148-
table.remove(parts, 1)
149-
--table.remove(parts, 1)
150158
end
151159
return parts
152160
end
@@ -188,6 +196,10 @@ local function _normalize_path(filename, cwd)
188196
return out_file
189197
end
190198

199+
--qqq
200+
--vim.notify("_normalize_path: call returned " .. vim.inspect(_normalize_path("C:\\msys64\\home\\..\\123", "C:\\msys64\\123")), vim.log.levels.WARN)
201+
--!qqq
202+
191203
local clean = function(pathname)
192204
if is_uri(pathname) then
193205
return pathname

lua/plenary/utils.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function M.posix_to_windows(posix_path)
5959

6060

6161
-- For edgy-ephemeral cases when vim.fn.expand() eats posix-style path.
62-
-- In that case we get forward slashes everywhere which we don't need
62+
-- In that case we get backslashes everywhere which we don't need
6363
-- when working with libuv which uses WinAPI under the hood.
6464
-- E.g. vim.fn.expand("/home/User") gives "\home\User".
6565
posix_path = posix_path:gsub("\\", "/")
@@ -92,26 +92,27 @@ function M.posix_to_windows(posix_path)
9292
-- Idk if WezTerm paths behaviour leaks to msys2 actually...
9393
if not prefix_changed then
9494
if #posix_path == 2 and posix_path:find("/[A-Za-z]") then
95-
--vim.notify("Only '[A-Za-z]:' case: " .. posix_path, vim.log.levels.WARN)
95+
--vim.notify("Only '/[A-Za-z]' case: " .. posix_path, vim.log.levels.WARN)
9696
posix_path = posix_path:gsub("^/([A-Za-z])", "%1:\\")
9797
prefix_changed = true
9898
else
99-
--vim.notify("'[A-Za-z]:?/' case: " .. posix_path, vim.log.levels.WARN)
99+
--vim.notify("'/[A-Za-z]:?/' case: " .. posix_path, vim.log.levels.WARN)
100100
posix_path = posix_path:gsub("^/([A-Za-z]):?/", "%1:\\")
101101
prefix_changed = true
102102
end
103103
end
104104

105-
-- Lets try to be msys2 compliant for testing.
105+
-- Lets try to use posix-style paths for testing.
106106
--posix_path = posix_path:gsub("^/([A-Za-z]):?([^0-9A-Za-z_-]?)", "/%1%2")
107107

108108

109109
-- Replace remaining forward slashes with backslashes.
110110
posix_path = posix_path:gsub("/", "\\")
111111

112-
-- For bash.exe (nvim shell) it is better to use backslashes
113-
-- cause forward slashes must be escaped. Need to come up with something
114-
-- cause nvim for windows (even clang64 binary) prefers windows-style paths (with backslashes?).
112+
-- For bash.exe (nvim shell) it is better to use forward slashes
113+
-- cause backslashes must to be escaped. Need to come up with something
114+
-- cause nvim for windows (even clang64 binary) prefers windows-style paths (but works with forward slashes as well?).
115+
-- UPD. "set shellslash" makes the trick by converting backslashes to forward slashes in shell invocations.
115116
--posix_path = posix_path:gsub("\\", "/")
116117

117118

0 commit comments

Comments
 (0)