From 963c8d2c5538c4a896a31f396b8a5a2683e254dc Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Mon, 29 Dec 2025 15:27:20 -0500 Subject: [PATCH] fix: handle empty LSP glob patterns (#702) * fix: handle empty LSP glob patterns * fix: use non-greedy pattern matching * lint: fix shadowed variable --------- Co-authored-by: Steven Arcangeli <506791+stevearc@users.noreply.github.com> --- lua/oil/lsp/workspace.lua | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lua/oil/lsp/workspace.lua b/lua/oil/lsp/workspace.lua index d113b13..8e48276 100644 --- a/lua/oil/lsp/workspace.lua +++ b/lua/oil/lsp/workspace.lua @@ -76,17 +76,26 @@ local function get_matching_paths(client, filters, paths) ---@type string|vim.lpeg.Pattern local glob_to_match = glob if vim.glob and vim.glob.to_lpeg then - -- HACK around https://github.com/neovim/neovim/issues/28931 - -- find alternations and sort them by length to try to match the longest first - if vim.fn.has("nvim-0.11") == 0 then - glob = glob:gsub("{(.*)}", function(s) - local pieces = vim.split(s, ",") - table.sort(pieces, function(a, b) + glob = glob:gsub("{(.-)}", function(s) + local patterns = vim.split(s, ",") + local filtered = {} + for _, pat in ipairs(patterns) do + if pat ~= "" then + table.insert(filtered, pat) + end + end + if #filtered == 0 then + return "" + end + -- HACK around https://github.com/neovim/neovim/issues/28931 + -- find alternations and sort them by length to try to match the longest first + if vim.fn.has("nvim-0.11") == 0 then + table.sort(filtered, function(a, b) return a:len() > b:len() end) - return "{" .. table.concat(pieces, ",") .. "}" - end) - end + end + return "{" .. table.concat(filtered, ",") .. "}" + end) glob_to_match = vim.glob.to_lpeg(glob) end