feat: add vim.fs.relpath

This is needed to replace the nvim-lspconfig function is_descendant that
some lspconfg configurations still use.
This commit is contained in:
dundargoc
2024-12-30 16:01:00 +01:00
committed by dundargoc
parent a3ef29d570
commit 0631492f9c
5 changed files with 114 additions and 15 deletions

View File

@ -22,13 +22,6 @@ local M = {
paths = Paths,
}
--- @param p string
--- @return string
local function relpath(p)
p = vim.fs.normalize(p)
return (p:gsub('^' .. uv.cwd, ''))
end
--- @param path string
--- @return boolean
function M.isdir(path)
@ -45,14 +38,15 @@ end
--- (Only on Windows) Replaces yucky "\\" slashes with delicious "/" slashes in a string, or all
--- string values in a table (recursively).
---
--- @param obj string|table
--- @return any
--- @generic T: string|table
--- @param obj T
--- @return T|nil
function M.fix_slashes(obj)
if not M.is_os('win') then
return obj
end
if type(obj) == 'string' then
local ret = obj:gsub('\\', '/')
local ret = string.gsub(obj, '\\', '/')
return ret
elseif type(obj) == 'table' then
--- @cast obj table<any,any>
@ -482,7 +476,8 @@ function M.check_cores(app, force) -- luacheck: ignore
-- "./Xtest-tmpdir/" => "Xtest%-tmpdir"
local local_tmpdir = nil
if tmpdir_is_local and tmpdir then
local_tmpdir = vim.pesc(relpath(tmpdir):gsub('^[ ./]+', ''):gsub('%/+$', ''))
local_tmpdir =
vim.pesc(vim.fs.relpath(assert(vim.uv.cwd()), tmpdir):gsub('^[ ./]+', ''):gsub('%/+$', ''))
end
local db_cmd --- @type string