From 5fb17faa1ac856bfd2e74ea4ab96ebfb58b70ff3 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 14 Dec 2024 16:18:50 +0100 Subject: [PATCH] refactor: deprecate util.path.is_absolute Work on https://github.com/neovim/nvim-lspconfig/issues/2079. --- lua/lspconfig/util.lua | 18 +++++++----------- test/lspconfig_spec.lua | 13 ------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 4bd82b5be8..58804b030a 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -111,16 +111,6 @@ M.path = (function() end end - --- @param filename string - --- @return boolean - local function is_absolute(filename) - if iswin then - return filename:match '^%a:' or filename:match '^\\\\' - else - return filename:match '^/' - end - end - local function path_join(...) return table.concat(M.tbl_flatten { ... }, '/') end @@ -180,7 +170,6 @@ M.path = (function() return { escape_wildcards = escape_wildcards, - is_absolute = is_absolute, join = path_join, traverse_parents = traverse_parents, iterate_parents = iterate_parents, @@ -370,6 +359,13 @@ M.path.dirname = vim.fs.dirname --- @deprecated use `vim.fs.normalize` instead M.path.sanitize = vim.fs.normalize +--- @deprecated use `vim.fn.isabsolutepath(filename) == 1` instead +--- @param filename string +--- @return boolean +function M.path.is_absolute(filename) + return vim.fn.isabsolutepath(filename) == 1 +end + --- @deprecated use `vim.loop.fs_stat` instead --- @param filename string --- @return string|false diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index 256faba203..63a5cd9422 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -25,19 +25,6 @@ describe('lspconfig', function() end) end) - describe('is_absolute', function() - it('is absolute', function() - local lspconfig = require 'lspconfig' - eq(true, lspconfig.util.path.is_absolute '/foo/bar' ~= nil) - end) - - it('is not absolute', function() - local lspconfig = require 'lspconfig' - assert.is_nil(lspconfig.util.path.is_absolute 'foo/bar') - assert.is_nil(lspconfig.util.path.is_absolute '../foo/bar') - end) - end) - describe('join', function() it('', function() local lspconfig = require 'lspconfig'