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

refactor: remove internal implementation of util.path.dirname #3460

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function configs.__newindex(t, config_name, config_def)
if not api.nvim_buf_is_valid(bufnr) or (#bufname ~= 0 and not util.bufname_valid(bufname)) then
return
end
local pseudo_root = #bufname == 0 and pwd or util.path.dirname(util.path.sanitize(bufname))
local pseudo_root = #bufname == 0 and pwd or vim.fs.dirname(util.path.sanitize(bufname))
M.manager:add(pseudo_root, true, bufnr, config.silent)
end
end)
Expand Down
2 changes: 1 addition & 1 deletion lua/lspconfig/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function M:try_add(bufnr, project_root, silent)
if root_dir then
self:add(root_dir, false, bufnr, silent)
elseif self.config.single_file_support then
local pseudo_root = #bufname == 0 and pwd or util.path.dirname(buf_path)
local pseudo_root = #bufname == 0 and pwd or vim.fs.dirname(buf_path)
self:add(pseudo_root, true, bufnr, silent)
end
end)
Expand Down
19 changes: 3 additions & 16 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,7 @@ M.path = (function()
--- @param path T
--- @return T
local function dirname(path)
Copy link
Member

@justinmk justinmk Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a @deprecated token would help too, and the docstring can mention "use vim.fs"

done in #3462

local strip_dir_pat = '/([^/]+)$'
local strip_sep_pat = '/$'
if not path or #path == 0 then
return path
end
local result = path:gsub(strip_sep_pat, ''):gsub(strip_dir_pat, '')
if #result == 0 then
if iswin then
return path:sub(1, 2):upper()
else
return '/'
end
end
return result
return vim.fs.dirname(path)
end

local function path_join(...)
Expand All @@ -181,7 +168,7 @@ M.path = (function()
local dir = path
-- Just in case our algo is buggy, don't infinite loop.
for _ = 1, 100 do
dir = dirname(dir)
dir = vim.fs.dirname(dir)
if not dir then
return
end
Expand All @@ -199,7 +186,7 @@ M.path = (function()
local function iterate_parents(path)
local function it(_, v)
if v and not is_fs_root(v) then
v = dirname(v)
v = vim.fs.dirname(v)
else
return
end
Expand Down
Loading