Skip to content

Commit f4072c4

Browse files
committed
change parts to relparts
simpler
1 parent 049335c commit f4072c4

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

lua/plenary/path2.lua

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--- instantiation.
2020

2121
--- TODO: rework `split_root` logic according to python 3.12
22+
--- TODO: rework `_filename` according to `_format_parsed_parts`
2223

2324
local uv = vim.loop
2425
local iswin = uv.os_uname().sysname == "Windows_NT"
@@ -28,6 +29,7 @@ local hasshellslash = vim.fn.exists "+shellslash" == 1
2829
---@field sep string
2930
---@field altsep string
3031
---@field has_drv boolean
32+
---@field case_sensitive boolean
3133
---@field convert_altsep fun(self: plenary._Path, p:string): string
3234
---@field split_root fun(self: plenary._Path, part:string): string, string, string
3335

@@ -36,6 +38,7 @@ local _WindowsPath = {
3638
sep = "\\",
3739
altsep = "/",
3840
has_drv = true,
41+
case_sensitive = true,
3942
}
4043

4144
setmetatable(_WindowsPath, { __index = _WindowsPath })
@@ -123,6 +126,7 @@ local _PosixPath = {
123126
sep = "/",
124127
altsep = "",
125128
has_drv = false,
129+
case_sensitive = true,
126130
}
127131
setmetatable(_PosixPath, { __index = _PosixPath })
128132

@@ -245,10 +249,6 @@ local function parse_parts(parts, _path)
245249
end
246250
end
247251

248-
if drv or root then
249-
table.insert(parsed, drv .. root)
250-
end
251-
252252
local n = #parsed
253253
for i = 1, math.floor(n / 2) do
254254
parsed[i], parsed[n - i + 1] = parsed[n - i + 1], parsed[i]
@@ -262,7 +262,7 @@ end
262262
---@field private _path plenary._Path
263263
---@field drv string drive name, eg. 'C:' (only for Windows)
264264
---@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
266266
---
267267
---@field filename string
268268
---@field cwd string
@@ -309,9 +309,10 @@ Path.__eq = function(self, other)
309309
assert(Path.is_path(self))
310310
assert(Path.is_path(other) or type(other) == "string")
311311
-- 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
315316
end
316317

317318
---@alias plenary.Path2Args string|plenary.Path2|(string|plenary.Path2)[]
@@ -336,22 +337,22 @@ function Path:new(...)
336337
end
337338
end
338339

339-
local parts = {}
340+
local relparts = {}
340341
for _, a in ipairs(args) do
341342
if self.is_path(a) then
342-
vim.list_extend(parts, a.parts)
343+
vim.list_extend(relparts, a.relparts)
343344
else
344345
if a ~= "" then
345-
table.insert(parts, a)
346+
table.insert(relparts, a)
346347
end
347348
end
348349
end
349350

350351
local _path = iswin and _WindowsPath or _PosixPath
351352
local drv, root
352-
drv, root, parts = parse_parts(parts, _path)
353+
drv, root, relparts = parse_parts(relparts, _path)
353354

354-
local proxy = { _path = _path, drv = drv, root = root, parts = parts }
355+
local proxy = { _path = _path, drv = drv, root = root, relparts = relparts }
355356
setmetatable(proxy, Path)
356357

357358
local obj = { __inner = proxy }
@@ -368,7 +369,6 @@ function Path:new(...)
368369
end,
369370
-- stylua: ignore start
370371
__div = function(t, other) return Path.__div(t, other) end,
371-
__concat = function(t, other) return Path.__concat(t, other) end,
372372
__tostring = function(t) return Path.__tostring(t) end,
373373
__eq = function(t, other) return Path.__eq(t, other) end,
374374
__metatable = Path,
@@ -381,9 +381,9 @@ end
381381
---@private
382382
---@param drv string?
383383
---@param root string?
384-
---@param parts string[]?
384+
---@param relparts string[]?
385385
---@return string
386-
function Path:_filename(drv, root, parts)
386+
function Path:_filename(drv, root, relparts)
387387
drv = vim.F.if_nil(drv, self.drv)
388388
drv = self.drv ~= "" and self.drv:gsub(self._path.sep, path.sep) or ""
389389

@@ -394,10 +394,10 @@ function Path:_filename(drv, root, parts)
394394
root = self.root ~= "" and path.sep:rep(#self.root) or ""
395395
end
396396

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)
399399

400-
return drv .. root .. relparts
400+
return drv .. root .. relpath
401401
end
402402

403403
---@param x any
@@ -441,11 +441,11 @@ function Path:is_file()
441441
return false
442442
end
443443

444-
---@param parts string[] path parts
444+
---@param relparts string[] path parts
445445
---@return string[]
446-
local function resolve_dots(parts)
446+
local function resolve_dots(relparts)
447447
local new_parts = {}
448-
for _, part in ipairs(parts) do
448+
for _, part in ipairs(relparts) do
449449
if part == ".." then
450450
if #new_parts > 0 and new_parts[#new_parts] ~= ".." then
451451
table.remove(new_parts)
@@ -472,9 +472,9 @@ function Path:absolute()
472472
return self._absolute
473473
end
474474

475-
local parts = resolve_dots(self.parts)
475+
local relparts = resolve_dots(self.relparts)
476476
if self:is_absolute() then
477-
self._absolute = self:_filename(nil, nil, parts)
477+
self._absolute = self:_filename(nil, nil, relparts)
478478
else
479479
-- using fs_realpath over fnamemodify
480480
-- fs_realpath resolves symlinks whereas fnamemodify doesn't but we're
@@ -519,8 +519,8 @@ function Path:make_relative(to)
519519
-- SEE: `Path.relative_to` implementation (3.12) specifically `walk_up` param
520520

521521
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
524524
matches = false
525525
break
526526
end

0 commit comments

Comments
 (0)