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 util.path.escape_wildcards #3510

Merged
merged 1 commit into from
Dec 14, 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
11 changes: 5 additions & 6 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ end

-- Some path utilities
M.path = (function()
local function escape_wildcards(path)
return path:gsub('([%[%]%?%*])', '\\%1')
end

--- @param path string
--- @return boolean
local function is_fs_root(path)
Expand Down Expand Up @@ -179,7 +175,6 @@ M.path = (function()
local path_separator = iswin and ';' or ':'

return {
escape_wildcards = escape_wildcards,
is_absolute = is_absolute,
join = path_join,
traverse_parents = traverse_parents,
Expand Down Expand Up @@ -216,13 +211,17 @@ function M.get_lsp_clients(filter)
return nvim_eleven and lsp.get_clients(filter) or lsp.get_active_clients(filter)
end

local function escape_wildcards(path)
return path:gsub('([%[%]%?%*])', '\\%1')
end

function M.root_pattern(...)
local patterns = M.tbl_flatten { ... }
return function(startpath)
startpath = M.strip_archive_subpath(startpath)
for _, pattern in ipairs(patterns) do
local match = M.search_ancestors(startpath, function(path)
for _, p in ipairs(vim.fn.glob(M.path.join(M.path.escape_wildcards(path), pattern), true, true)) do
for _, p in ipairs(vim.fn.glob(M.path.join(escape_wildcards(path), pattern), true, true)) do
if vim.loop.fs_stat(p) then
return path
end
Expand Down
15 changes: 0 additions & 15 deletions test/lspconfig_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ describe('lspconfig', function()

describe('util', function()
describe('path', function()
describe('escape_wildcards', function()
it('doesnt escape if not needed', function()
local lspconfig = require 'lspconfig'

local res = lspconfig.util.path.escape_wildcards '/usr/local/test/fname.lua'
eq('/usr/local/test/fname.lua', res)
end)
it('escapes if needed', function()
local lspconfig = require 'lspconfig'

local res = lspconfig.util.path.escape_wildcards '/usr/local/test/[sq brackets] fname?*.lua'
eq('/usr/local/test/\\[sq brackets\\] fname\\?\\*.lua', res)
end)
end)

describe('is_absolute', function()
it('is absolute', function()
local lspconfig = require 'lspconfig'
Expand Down
Loading