From 425e411f250d6dfc0a0d4111d7fd1db7c994326f Mon Sep 17 00:00:00 2001 From: CheeseTurtle <4154751+CheeseTurtle@users.noreply.github.com> Date: Mon, 27 May 2024 00:08:09 -0500 Subject: [PATCH 1/2] Adjusted path sep logic Added support for Windows-style paths with forward slash (i.e. when `vim.fn.exists('+shellslash')` and `vim.opt.shellslash._value` are both `true`). Previously the code assumed that sep would be '/' iff the OS was not Windows. I have reworked the code to avoid this assumption. I also added an additional call to the built-in path normalizer at the end of the Plenary normalization function, just in case. --- lua/plenary/path.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lua/plenary/path.lua b/lua/plenary/path.lua index 51229f186..6f557b441 100644 --- a/lua/plenary/path.lua +++ b/lua/plenary/path.lua @@ -18,10 +18,12 @@ local S_IF = { local path = {} path.home = vim.loop.os_homedir() +local sls_exists = vim.fn.exists('+shellslash') + path.sep = (function() if jit then local os = string.lower(jit.os) - if os ~= "windows" then + if os ~= "windows" or vim.opt.shellslash._value then return "/" else return "\\" @@ -32,14 +34,14 @@ path.sep = (function() end)() path.root = (function() - if path.sep == "/" then + if path.sep == "/" and not sls_exists then return function() return "/" end else return function(base) base = base or vim.loop.cwd() - return base:sub(1, 1) .. ":\\" + return base:sub(1, 1) .. ":" .. path.sep end end end)() @@ -55,8 +57,8 @@ local concat_paths = function(...) end local function is_root(pathname) - if path.sep == "\\" then - return string.match(pathname, "^[A-Z]:\\?$") + if sls_exists then + return string.match(pathname, "^[A-Z]:" .. path.sep .. "?$") end return pathname == "/" end @@ -77,8 +79,8 @@ local is_uri = function(filename) end local is_absolute = function(filename, sep) - if sep == "\\" then return string.match(filename, "^[%a]:[\\/].*$") ~= nil + if sls_exists then end return string.sub(filename, 1, 1) == sep end @@ -103,7 +105,7 @@ local function _normalize_path(filename, cwd) local split_without_disk_name = function(filename_local) local parts = _split_by_separator(filename_local) -- Remove disk name part on Windows - if path.sep == "\\" and is_abs then + if sls_exists and is_abs then table.remove(parts, 1) end return parts @@ -137,7 +139,7 @@ local function _normalize_path(filename, cwd) out_file = prefix .. table.concat(parts, path.sep) end - return out_file + return vim.fs.normalize(out_file, {expand_env=false}) end local clean = function(pathname) @@ -435,7 +437,7 @@ local shorten = (function() return shorten_len(filename, 1) end - if jit and path.sep ~= "\\" then + if jit and not sls_exists then local ffi = require "ffi" ffi.cdef [[ typedef unsigned char char_u; @@ -489,7 +491,7 @@ function Path:mkdir(opts) for _, dir in ipairs(dirs) do if dir ~= "" then local joined = concat_paths(processed, dir) - if processed == "" and self._sep == "\\" then + if processed == "" and sls_exists then joined = dir end local stat = uv.fs_stat(joined) or {} From 166c768156f3144e38b1e40ca9b5e4ffd98e8924 Mon Sep 17 00:00:00 2001 From: CheeseTurtle <4154751+CheeseTurtle@users.noreply.github.com> Date: Mon, 27 May 2024 00:12:40 -0500 Subject: [PATCH 2/2] Fixed a couple transposed lines Replaced path.sep with regex class of forward and backwards slash for path checking of absolute/root on Windows --- lua/plenary/path.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/plenary/path.lua b/lua/plenary/path.lua index 6f557b441..765d66ad9 100644 --- a/lua/plenary/path.lua +++ b/lua/plenary/path.lua @@ -58,7 +58,7 @@ end local function is_root(pathname) if sls_exists then - return string.match(pathname, "^[A-Z]:" .. path.sep .. "?$") + return string.match(pathname, "^[A-Z]:[\\/]?$") end return pathname == "/" end @@ -79,8 +79,8 @@ local is_uri = function(filename) end local is_absolute = function(filename, sep) - return string.match(filename, "^[%a]:[\\/].*$") ~= nil if sls_exists then + return string.match(filename, "^[%a]:[\\/].*$") ~= nil end return string.sub(filename, 1, 1) == sep end