aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-09-23 06:05:58 -0700
committerGitHub <noreply@github.com>2024-09-23 06:05:58 -0700
commit47e6b2233feffc6e9d94f6086fb904eb5688fa25 (patch)
treef3c3e062ecd7aafef95ac0c77d038eb143aab074
parent5acdc4499e2036c90172b2b085f207ee4d5cfee4 (diff)
downloadrneovim-47e6b2233feffc6e9d94f6086fb904eb5688fa25.tar.gz
rneovim-47e6b2233feffc6e9d94f6086fb904eb5688fa25.tar.bz2
rneovim-47e6b2233feffc6e9d94f6086fb904eb5688fa25.zip
fix(vim.fs): dirname() returns "." on mingw/msys2 #30480
Problem: `vim.fs.dirname([[C:\User\XXX\AppData\Local]])` returns "." on mingw/msys2. Solution: - Check for "mingw" when deciding `iswin`. - Use `has("win32")` where possible, it works in "fast" contexts since b02eeb6a7281df0561a021d7ae595c84be9a01be.
-rw-r--r--runtime/lua/vim/fs.lua4
-rw-r--r--runtime/lua/vim/loader.lua3
-rw-r--r--runtime/lua/vim/lsp/rpc.lua2
-rw-r--r--runtime/lua/vim/provider/health.lua2
-rw-r--r--test/testutil.lua12
5 files changed, 12 insertions, 11 deletions
diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua
index d145c5d531..0d2e2f907f 100644
--- a/runtime/lua/vim/fs.lua
+++ b/runtime/lua/vim/fs.lua
@@ -2,7 +2,9 @@ local uv = vim.uv
local M = {}
-local iswin = uv.os_uname().sysname == 'Windows_NT'
+-- Can't use `has('win32')` because the `nvim -ll` test runner doesn't support `vim.fn` yet.
+local sysname = uv.os_uname().sysname:lower()
+local iswin = not not (sysname:find('windows') or sysname:find('mingw'))
local os_sep = iswin and '\\' or '/'
--- Iterate over all the parents of the given path.
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
index 2a881d1602..0211e8d4a1 100644
--- a/runtime/lua/vim/loader.lua
+++ b/runtime/lua/vim/loader.lua
@@ -208,8 +208,7 @@ end
---@return string|function
---@private
function Loader.loader_lib(modname)
- local sysname = uv.os_uname().sysname:lower() or ''
- local is_win = sysname:find('win', 1, true) and not sysname:find('darwin', 1, true)
+ local is_win = vim.fn.has('win32') == 1
local ret = M.find(modname, { patterns = is_win and { '.dll' } or { '.so' } })[1]
if ret then
-- Making function name in Lua 5.1 (see src/loadlib.c:mkfuncname) is
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index d81eae20d1..bc24501eae 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -3,7 +3,7 @@ local log = require('vim.lsp.log')
local protocol = require('vim.lsp.protocol')
local validate, schedule, schedule_wrap = vim.validate, vim.schedule, vim.schedule_wrap
-local is_win = uv.os_uname().version:find('Windows')
+local is_win = vim.fn.has('win32') == 1
--- Checks whether a given path exists and is a directory.
---@param filename string path to check
diff --git a/runtime/lua/vim/provider/health.lua b/runtime/lua/vim/provider/health.lua
index 47d66307e9..47c2080e3c 100644
--- a/runtime/lua/vim/provider/health.lua
+++ b/runtime/lua/vim/provider/health.lua
@@ -1,5 +1,5 @@
local health = vim.health
-local iswin = vim.uv.os_uname().sysname == 'Windows_NT'
+local iswin = vim.fn.has('win32') == 1
local M = {}
diff --git a/test/testutil.lua b/test/testutil.lua
index 02f343891d..a920f658a1 100644
--- a/test/testutil.lua
+++ b/test/testutil.lua
@@ -392,7 +392,7 @@ function M.check_logs()
)
end
-function M.sysname()
+local function sysname()
return uv.os_uname().sysname:lower()
end
@@ -403,11 +403,11 @@ function M.is_os(s)
error('unknown platform: ' .. tostring(s))
end
return not not (
- (s == 'win' and (M.sysname():find('windows') or M.sysname():find('mingw')))
- or (s == 'mac' and M.sysname() == 'darwin')
- or (s == 'freebsd' and M.sysname() == 'freebsd')
- or (s == 'openbsd' and M.sysname() == 'openbsd')
- or (s == 'bsd' and M.sysname():find('bsd'))
+ (s == 'win' and (sysname():find('windows') or sysname():find('mingw')))
+ or (s == 'mac' and sysname() == 'darwin')
+ or (s == 'freebsd' and sysname() == 'freebsd')
+ or (s == 'openbsd' and sysname() == 'openbsd')
+ or (s == 'bsd' and sysname():find('bsd'))
)
end