fix(root): root dir for windows. Fixes #1749

This commit is contained in:
Folke Lemaitre 2023-10-16 08:35:35 +02:00
parent 152e1c6692
commit 9517e64009
No known key found for this signature in database
GPG key ID: 36B7C1C85AAC487F
2 changed files with 10 additions and 4 deletions

View file

@ -75,7 +75,7 @@ function M.pretty_path(opts)
if path == "" then if path == "" then
return "" return ""
end end
local root = Util.root.get() local root = Util.root.get({ normalize = true })
local cwd = Util.root.cwd() local cwd = Util.root.cwd()
if opts.relative == "cwd" and path:find(cwd, 1, true) == 1 then if opts.relative == "cwd" and path:find(cwd, 1, true) == 1 then
@ -111,7 +111,7 @@ function M.root_dir(opts)
local function get() local function get()
local cwd = Util.root.cwd() local cwd = Util.root.cwd()
local root = Util.root.get() local root = Util.root.get({ normalize = true })
local name = vim.fs.basename(root) local name = vim.fs.basename(root)
if root == cwd then if root == cwd then

View file

@ -141,10 +141,16 @@ end
-- * lsp root_dir -- * lsp root_dir
-- * root pattern of filename of the current buffer -- * root pattern of filename of the current buffer
-- * root pattern of cwd -- * root pattern of cwd
---@param opts {normalize?:boolean}
---@return string ---@return string
function M.get() function M.get(opts)
opts = opts or {}
local roots = M.detect({ all = false }) local roots = M.detect({ all = false })
return roots[1] and roots[1].paths[1] or vim.loop.cwd() local ret = roots[1] and roots[1].paths[1] or vim.loop.cwd()
if opts.normalize then
return ret
end
return Util.is_win() and ret:gsub("/", "\\") or ret
end end
---@param opts? {hl_last?: string} ---@param opts? {hl_last?: string}