Skip to content

Commit

Permalink
refactor: remove internal implementation of util.path.sanitize neov…
Browse files Browse the repository at this point in the history
…im#3464

Return value from `vim.fs.normalize` instead.
  • Loading branch information
dundargoc authored Nov 26, 2024
1 parent 16008a6 commit 830ec38
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function configs.__newindex(t, config_name, config_def)
async.run(function()
local root_dir
if type(get_root_dir) == 'function' then
root_dir = get_root_dir(util.path.sanitize(bufname), bufnr)
root_dir = get_root_dir(vim.fs.normalize(bufname), bufnr)
async.reenter()
if not api.nvim_buf_is_valid(bufnr) then
return
Expand Down Expand Up @@ -162,7 +162,7 @@ function configs.__newindex(t, config_name, config_def)
for _, buf in ipairs(api.nvim_list_bufs()) do
local buf_name = api.nvim_buf_get_name(buf)
if util.bufname_valid(buf_name) then
local buf_dir = util.path.sanitize(buf_name)
local buf_dir = vim.fs.normalize(buf_name)
if buf_dir:sub(1, root_dir:len()) == root_dir then
M.manager:try_add_wrapper(buf, root_dir)
end
Expand All @@ -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 vim.fs.dirname(util.path.sanitize(bufname))
local pseudo_root = #bufname == 0 and pwd or vim.fs.dirname(vim.fs.normalize(bufname))
M.manager:add(pseudo_root, true, bufnr, config.silent)
end
end)
Expand Down
2 changes: 1 addition & 1 deletion lua/lspconfig/configs/lean3ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ return {
filetypes = { 'lean3' },
offset_encoding = 'utf-32',
root_dir = function(fname)
fname = util.path.sanitize(fname)
fname = vim.fs.normalize(fname)
-- check if inside elan stdlib
local stdlib_dir
do
Expand Down
2 changes: 1 addition & 1 deletion lua/lspconfig/configs/leanls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ return {
filetypes = { 'lean' },
root_dir = function(fname)
-- check if inside elan stdlib
fname = util.path.sanitize(fname)
fname = vim.fs.normalize(fname)
local stdlib_dir
do
local _, endpos = fname:find '/src/lean'
Expand Down
2 changes: 1 addition & 1 deletion lua/lspconfig/configs/relay_lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ return {
end

if config.path_to_config then
config.path_to_config = util.path.sanitize(config.path_to_config)
config.path_to_config = vim.fs.normalize(config.path_to_config)
local path_to_config = util.path.join(root_dir, config.path_to_config)
if util.path.exists(path_to_config) then
vim.list_extend(config.cmd, { config.path_to_config })
Expand Down
4 changes: 2 additions & 2 deletions lua/lspconfig/configs/rust_analyzer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local function reload_workspace(bufnr)
end

local function is_library(fname)
local user_home = util.path.sanitize(vim.env.HOME)
local user_home = vim.fs.normalize(vim.env.HOME)
local cargo_home = os.getenv 'CARGO_HOME' or util.path.join(user_home, '.cargo')
local registry = util.path.join(cargo_home, 'registry', 'src')
local git_registry = util.path.join(cargo_home, 'git', 'checkouts')
Expand Down Expand Up @@ -62,7 +62,7 @@ return {
if result and result[1] then
result = vim.json.decode(table.concat(result, ''))
if result['workspace_root'] then
cargo_workspace_root = util.path.sanitize(result['workspace_root'])
cargo_workspace_root = vim.fs.normalize(result['workspace_root'])
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lua/lspconfig/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ end
---@param bufnr integer
---@param silent boolean
function M:add(root_dir, single_file, bufnr, silent)
root_dir = util.path.sanitize(root_dir)
root_dir = vim.fs.normalize(root_dir)
local new_config = self.make_config(root_dir)
self:_start_client(bufnr, new_config, root_dir, single_file, silent)
end
Expand Down Expand Up @@ -199,7 +199,7 @@ function M:try_add(bufnr, project_root, silent)
return
end

local buf_path = util.path.sanitize(bufname)
local buf_path = vim.fs.normalize(bufname)

local get_root_dir = self.config.root_dir

Expand Down
9 changes: 2 additions & 7 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,9 @@ M.path = (function()
return path:gsub('([%[%]%?%*])', '\\%1')
end

--- @param path string
--- @return string
--- @deprecated use `vim.fs.normalize` instead
local function sanitize(path)
if iswin then
path = path:sub(1, 1):upper() .. path:sub(2)
path = path:gsub('\\', '/')
end
return path
return vim.fs.normalize(path)
end

--- @param filename string
Expand Down

0 comments on commit 830ec38

Please sign in to comment.