diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index 4a13c1f61b..0d23dffc08 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -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 @@ -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 @@ -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) diff --git a/lua/lspconfig/configs/lean3ls.lua b/lua/lspconfig/configs/lean3ls.lua index 014798988c..645fbbbee5 100644 --- a/lua/lspconfig/configs/lean3ls.lua +++ b/lua/lspconfig/configs/lean3ls.lua @@ -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 diff --git a/lua/lspconfig/configs/leanls.lua b/lua/lspconfig/configs/leanls.lua index cde899d99e..c29b641769 100644 --- a/lua/lspconfig/configs/leanls.lua +++ b/lua/lspconfig/configs/leanls.lua @@ -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' diff --git a/lua/lspconfig/configs/relay_lsp.lua b/lua/lspconfig/configs/relay_lsp.lua index 2c14efb605..9f2b3776b6 100644 --- a/lua/lspconfig/configs/relay_lsp.lua +++ b/lua/lspconfig/configs/relay_lsp.lua @@ -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 }) diff --git a/lua/lspconfig/configs/rust_analyzer.lua b/lua/lspconfig/configs/rust_analyzer.lua index a8f11208ee..8bcde6c9b8 100644 --- a/lua/lspconfig/configs/rust_analyzer.lua +++ b/lua/lspconfig/configs/rust_analyzer.lua @@ -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') @@ -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 diff --git a/lua/lspconfig/manager.lua b/lua/lspconfig/manager.lua index 45a9e4254f..16bf17c0f6 100644 --- a/lua/lspconfig/manager.lua +++ b/lua/lspconfig/manager.lua @@ -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 @@ -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 diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 041f56e65f..f89ceb6f43 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -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