19
19
--- instantiation.
20
20
21
21
--- TODO: rework `split_root` logic according to python 3.12
22
+ --- TODO: rework `_filename` according to `_format_parsed_parts`
22
23
23
24
local uv = vim .loop
24
25
local iswin = uv .os_uname ().sysname == " Windows_NT"
@@ -28,6 +29,7 @@ local hasshellslash = vim.fn.exists "+shellslash" == 1
28
29
--- @field sep string
29
30
--- @field altsep string
30
31
--- @field has_drv boolean
32
+ --- @field case_sensitive boolean
31
33
--- @field convert_altsep fun ( self : plenary._Path , p : string ): string
32
34
--- @field split_root fun ( self : plenary._Path , part : string ): string , string , string
33
35
@@ -36,6 +38,7 @@ local _WindowsPath = {
36
38
sep = " \\ " ,
37
39
altsep = " /" ,
38
40
has_drv = true ,
41
+ case_sensitive = true ,
39
42
}
40
43
41
44
setmetatable (_WindowsPath , { __index = _WindowsPath })
@@ -123,6 +126,7 @@ local _PosixPath = {
123
126
sep = " /" ,
124
127
altsep = " " ,
125
128
has_drv = false ,
129
+ case_sensitive = true ,
126
130
}
127
131
setmetatable (_PosixPath , { __index = _PosixPath })
128
132
@@ -245,10 +249,6 @@ local function parse_parts(parts, _path)
245
249
end
246
250
end
247
251
248
- if drv or root then
249
- table.insert (parsed , drv .. root )
250
- end
251
-
252
252
local n = # parsed
253
253
for i = 1 , math.floor (n / 2 ) do
254
254
parsed [i ], parsed [n - i + 1 ] = parsed [n - i + 1 ], parsed [i ]
262
262
--- @field private _path plenary._Path
263
263
--- @field drv string drive name , eg. ' C:' (only for Windows )
264
264
--- @field root string root path (excludes drive name )
265
- --- @field parts string[] path parts excluding separators
265
+ --- @field relparts string[] relative path parts excluding separators
266
266
---
267
267
--- @field filename string
268
268
--- @field cwd string
@@ -309,9 +309,10 @@ Path.__eq = function(self, other)
309
309
assert (Path .is_path (self ))
310
310
assert (Path .is_path (other ) or type (other ) == " string" )
311
311
-- TODO
312
- if true then
313
- error " not yet implemented"
314
- end
312
+ -- if true then
313
+ -- error "not yet implemented"
314
+ -- end
315
+ return self .filename == other .filename
315
316
end
316
317
317
318
--- @alias plenary.Path2Args string | plenary.Path2 | (string | plenary.Path2 )[]
@@ -336,22 +337,22 @@ function Path:new(...)
336
337
end
337
338
end
338
339
339
- local parts = {}
340
+ local relparts = {}
340
341
for _ , a in ipairs (args ) do
341
342
if self .is_path (a ) then
342
- vim .list_extend (parts , a .parts )
343
+ vim .list_extend (relparts , a .relparts )
343
344
else
344
345
if a ~= " " then
345
- table.insert (parts , a )
346
+ table.insert (relparts , a )
346
347
end
347
348
end
348
349
end
349
350
350
351
local _path = iswin and _WindowsPath or _PosixPath
351
352
local drv , root
352
- drv , root , parts = parse_parts (parts , _path )
353
+ drv , root , relparts = parse_parts (relparts , _path )
353
354
354
- local proxy = { _path = _path , drv = drv , root = root , parts = parts }
355
+ local proxy = { _path = _path , drv = drv , root = root , relparts = relparts }
355
356
setmetatable (proxy , Path )
356
357
357
358
local obj = { __inner = proxy }
@@ -368,7 +369,6 @@ function Path:new(...)
368
369
end ,
369
370
-- stylua: ignore start
370
371
__div = function (t , other ) return Path .__div (t , other ) end ,
371
- __concat = function (t , other ) return Path .__concat (t , other ) end ,
372
372
__tostring = function (t ) return Path .__tostring (t ) end ,
373
373
__eq = function (t , other ) return Path .__eq (t , other ) end ,
374
374
__metatable = Path ,
381
381
--- @private
382
382
--- @param drv string ?
383
383
--- @param root string ?
384
- --- @param parts string[] ?
384
+ --- @param relparts string[] ?
385
385
--- @return string
386
- function Path :_filename (drv , root , parts )
386
+ function Path :_filename (drv , root , relparts )
387
387
drv = vim .F .if_nil (drv , self .drv )
388
388
drv = self .drv ~= " " and self .drv :gsub (self ._path .sep , path .sep ) or " "
389
389
@@ -394,10 +394,10 @@ function Path:_filename(drv, root, parts)
394
394
root = self .root ~= " " and path .sep :rep (# self .root ) or " "
395
395
end
396
396
397
- parts = vim .F .if_nil (parts , self .parts )
398
- local relparts = table.concat (vim . list_slice ( parts , 2 ), path .sep )
397
+ relparts = vim .F .if_nil (relparts , self .relparts )
398
+ local relpath = table.concat (relparts , path .sep )
399
399
400
- return drv .. root .. relparts
400
+ return drv .. root .. relpath
401
401
end
402
402
403
403
--- @param x any
@@ -441,11 +441,11 @@ function Path:is_file()
441
441
return false
442
442
end
443
443
444
- --- @param parts string[] path parts
444
+ --- @param relparts string[] path parts
445
445
--- @return string[]
446
- local function resolve_dots (parts )
446
+ local function resolve_dots (relparts )
447
447
local new_parts = {}
448
- for _ , part in ipairs (parts ) do
448
+ for _ , part in ipairs (relparts ) do
449
449
if part == " .." then
450
450
if # new_parts > 0 and new_parts [# new_parts ] ~= " .." then
451
451
table.remove (new_parts )
@@ -472,9 +472,9 @@ function Path:absolute()
472
472
return self ._absolute
473
473
end
474
474
475
- local parts = resolve_dots (self .parts )
475
+ local relparts = resolve_dots (self .relparts )
476
476
if self :is_absolute () then
477
- self ._absolute = self :_filename (nil , nil , parts )
477
+ self ._absolute = self :_filename (nil , nil , relparts )
478
478
else
479
479
-- using fs_realpath over fnamemodify
480
480
-- fs_realpath resolves symlinks whereas fnamemodify doesn't but we're
@@ -519,8 +519,8 @@ function Path:make_relative(to)
519
519
-- SEE: `Path.relative_to` implementation (3.12) specifically `walk_up` param
520
520
521
521
local matches = true
522
- for i = 1 , # to .parts do
523
- if to .parts [i ] ~= self .parts [i ] then
522
+ for i = 1 , # to .relparts do
523
+ if to .relparts [i ] ~= self .relparts [i ] then
524
524
matches = false
525
525
break
526
526
end
0 commit comments