@@ -8,6 +8,10 @@ local uv = vim.loop
8
8
9
9
local F = require " plenary.functional"
10
10
11
+ -- qqq
12
+ local U = require " plenary.utils"
13
+ -- !qqq
14
+
11
15
local S_IF = {
12
16
-- S_IFDIR = 0o040000 # directory
13
17
DIR = 0x4000 ,
@@ -16,14 +20,29 @@ local S_IF = {
16
20
}
17
21
18
22
local path = {}
19
- path .home = vim .loop .os_homedir ()
23
+ -- qqq
24
+ -- vim.loop.os_homedir() ignores HOME env var in msys2
25
+ if U .is_msys2 then
26
+ path .home = U .posix_to_windows (vim .fn .expand (" ~" ))
27
+ else
28
+ path .home = vim .loop .os_homedir ()
29
+ end
30
+ -- !qqq
31
+ -- path.home = vim.loop.os_homedir()
20
32
21
33
path .sep = (function ()
22
34
if jit then
23
35
local os = string.lower (jit .os )
24
- if os ~= " windows" then
36
+ if os ~= " windows" and not U . is_msys2 then
25
37
return " /"
26
38
else
39
+ -- qqq
40
+ -- 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
42
+ -- but not UNC paths if the paths will ever be supported.
43
+ -- Maybe returning "/" as path separator can break something in existing logic.
44
+ -- return "/"
45
+ -- !qqq
27
46
return " \\ "
28
47
end
29
48
else
@@ -39,7 +58,17 @@ path.root = (function()
39
58
else
40
59
return function (base )
41
60
base = base or vim .loop .cwd ()
42
- return base :sub (1 , 1 ) .. " :\\ "
61
+ -- qqq
62
+ if U .is_msys2 then
63
+ base = U .posix_to_windows (base )
64
+ -- if not base:find("^[A-Za-z]:" .. path.sep) then
65
+ -- vim.notify("path.root IIFE: base has incorrect path style for msys2!", vim.log.levels.ERROR)
66
+ -- end
67
+ end
68
+ return base :sub (1 , 1 ) .. " :" .. path .sep
69
+ -- return base:sub(1, 3)
70
+ -- !qqq
71
+ -- return base:sub(1, 1) .. ":\\"
43
72
end
44
73
end
45
74
end )()
@@ -55,8 +84,14 @@ local concat_paths = function(...)
55
84
end
56
85
57
86
local function is_root (pathname )
58
- if path .sep == " \\ " then
59
- return string.match (pathname , " ^[A-Z]:\\ ?$" )
87
+ if path .sep == " \\ " or U .is_msys2 then
88
+ -- qqq
89
+ if U .is_msys2 then
90
+ pathname = U .posix_to_windows (pathname )
91
+ end
92
+ return string.match (pathname , " ^[A-Za-z]:[\\ /]?$" )
93
+ -- !qqq
94
+ -- return string.match(pathname, "^[A-Z]:\\?$")
60
95
end
61
96
return pathname == " /"
62
97
end
@@ -77,7 +112,12 @@ local is_uri = function(filename)
77
112
end
78
113
79
114
local is_absolute = function (filename , sep )
80
- if sep == " \\ " then
115
+ if sep == " \\ " or U .is_msys2 then
116
+ -- qqq
117
+ if U .is_msys2 then
118
+ filename = U .posix_to_windows (filename )
119
+ end
120
+ -- !qqq
81
121
return string.match (filename , " ^[%a]:[\\ /].*$" ) ~= nil
82
122
end
83
123
return string.sub (filename , 1 , 1 ) == sep
@@ -103,8 +143,10 @@ local function _normalize_path(filename, cwd)
103
143
local split_without_disk_name = function (filename_local )
104
144
local parts = _split_by_separator (filename_local )
105
145
-- Remove disk name part on Windows
106
- if path .sep == " \\ " and is_abs then
146
+ if is_abs and ( path .sep == " \\ " or U . is_msys2 ) then
107
147
table.remove (parts , 1 )
148
+ table.remove (parts , 1 )
149
+ -- table.remove(parts, 1)
108
150
end
109
151
return parts
110
152
end
@@ -137,6 +179,12 @@ local function _normalize_path(filename, cwd)
137
179
out_file = prefix .. table.concat (parts , path .sep )
138
180
end
139
181
182
+ -- qqq
183
+ if U .is_msys2 then
184
+ out_file = U .posix_to_windows (out_file )
185
+ end
186
+ -- !qqq
187
+
140
188
return out_file
141
189
end
142
190
@@ -182,12 +230,22 @@ Path.__index = function(t, k)
182
230
183
231
if k == " _cwd" then
184
232
local cwd = uv .fs_realpath " ."
233
+ -- qqq
234
+ if U .is_msys2 then
235
+ cwd = U .posix_to_windows (cwd )
236
+ end
237
+ -- !qqq
185
238
t ._cwd = cwd
186
239
return cwd
187
240
end
188
241
189
242
if k == " _absolute" then
190
243
local absolute = uv .fs_realpath (t .filename )
244
+ -- qqq
245
+ if U .is_msys2 then
246
+ absolute = U .posix_to_windows (absolute )
247
+ end
248
+ -- !qqq
191
249
t ._absolute = absolute
192
250
return absolute
193
251
end
@@ -234,6 +292,13 @@ function Path:new(...)
234
292
-- If we already have a Path, it's fine.
235
293
-- Just return it
236
294
if Path .is_path (path_input ) then
295
+ -- qqq
296
+ -- Maybe we should fix fields with paths here as well
297
+ -- if U.is_msys2 then
298
+ -- vim.notify("Path:new(...): returning already defined Path object " .. vim.inspect(path_input), vim.log.levels.ERROR)
299
+ -- path_input.filename = U.posix_to_windows(path_input.filename)
300
+ -- end
301
+ -- !qqq
237
302
return path_input
238
303
end
239
304
@@ -259,8 +324,18 @@ function Path:new(...)
259
324
end
260
325
261
326
path_string = table.concat (path_objs , sep )
327
+ -- qqq
328
+ if U .is_msys2 then
329
+ path_string = U .posix_to_windows (path_string )
330
+ end
331
+ -- !qqq
262
332
else
263
333
assert (type (path_input ) == " string" , vim .inspect (path_input ))
334
+ -- qqq
335
+ if U .is_msys2 then
336
+ path_input = U .posix_to_windows (path_input )
337
+ end
338
+ -- !qqq
264
339
path_string = path_input
265
340
end
266
341
@@ -319,7 +394,15 @@ function Path:expand()
319
394
-- TODO support windows
320
395
local expanded
321
396
if string.find (self .filename , " ~" ) then
322
- expanded = string.gsub (self .filename , " ^~" , vim .loop .os_homedir ())
397
+ -- qqq
398
+ -- vim.loop.os_homedir() ignores HOME env variable in msys2
399
+ if U .is_msys2 then
400
+ expanded = string.gsub (self .filename , " ^~" , vim .fn .expand (" ~" ))
401
+ else
402
+ expanded = string.gsub (self .filename , " ^~" , vim .loop .os_homedir ())
403
+ end
404
+ -- !qqq
405
+ -- expanded = string.gsub(self.filename, "^~", vim.loop.os_homedir())
323
406
elseif string.find (self .filename , " ^%." ) then
324
407
expanded = vim .loop .fs_realpath (self .filename )
325
408
if expanded == nil then
@@ -336,9 +419,22 @@ function Path:expand()
336
419
else
337
420
expanded = self .filename
338
421
end
422
+ -- qqq
423
+ if expanded and U .is_msys2 then
424
+ -- vim.notify("Path:expand(): " .. "vim.inspect(expanded), vim.log.levels.ERROR")
425
+ expanded = U .posix_to_windows (expanded )
426
+ end
427
+ -- !qqq
339
428
return expanded and expanded or error " Path not valid"
340
429
end
341
430
431
+ -- qqq
432
+ -- Can be tough to achieve in msys2 for posix-style paths.
433
+ -- Like from C:\\msys64\\home\\User\\personal\\project\\src\\file.lua (rel. src\\file.lua)
434
+ -- to /home/User/personal/project/src/file.lua (rel. src/file.lua).
435
+ -- This will probably require back-and-forth path conversions.
436
+ -- But do we actually need to bother about that instead of leaving Windows-style rel. path?
437
+ -- !qqq
342
438
function Path :make_relative (cwd )
343
439
if is_uri (self .filename ) then
344
440
return self .filename
@@ -358,6 +454,12 @@ function Path:make_relative(cwd)
358
454
end
359
455
end
360
456
457
+ -- qqq
458
+ if U .is_msys2 then
459
+ self .filename = U .posix_to_windows (self .filename )
460
+ end
461
+ -- !qqq
462
+
361
463
return self .filename
362
464
end
363
465
@@ -435,7 +537,7 @@ local shorten = (function()
435
537
return shorten_len (filename , 1 )
436
538
end
437
539
438
- if jit and path .sep ~= " \\ " then
540
+ if jit and path .sep ~= " \\ " then -- and not U.is_msys2 then
439
541
local ffi = require " ffi"
440
542
ffi .cdef [[
441
543
typedef unsigned char char_u;
@@ -489,7 +591,7 @@ function Path:mkdir(opts)
489
591
for _ , dir in ipairs (dirs ) do
490
592
if dir ~= " " then
491
593
local joined = concat_paths (processed , dir )
492
- if processed == " " and self ._sep == " \\ " then
594
+ if processed == " " and ( self ._sep == " \\ " ) then -- or U.is_msys2) then
493
595
joined = dir
494
596
end
495
597
local stat = uv .fs_stat (joined ) or {}
0 commit comments