Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winpathfix #591

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lua/plenary/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\\"
Expand All @@ -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)()
Expand All @@ -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]:[\\/]?$")
end
return pathname == "/"
end
Expand All @@ -77,7 +79,7 @@ local is_uri = function(filename)
end

local is_absolute = function(filename, sep)
if sep == "\\" then
if sls_exists then
return string.match(filename, "^[%a]:[\\/].*$") ~= nil
end
return string.sub(filename, 1, 1) == sep
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {}
Expand Down