Skip to content

Commit

Permalink
Refactor create_items function to enhance pattern processing and recu…
Browse files Browse the repository at this point in the history
…rsive path handling.

    Replaced single-level pattern expansion with a more robust method that accommodates recursive patterns within {}.
  • Loading branch information
Mirsmog committed Oct 3, 2024
1 parent 2089cb6 commit 8272ec1
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions lua/telescope/_extensions/file_browser/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,37 @@ local create = function(file, finder)
end

local function create_items(input, finder)
if not input then
if not input or input == "" then
return
end
local prefix, middle, suffix = input:match "^(.-){(.-)}(.-)$"
local files = {}

if not (prefix and middle and suffix) then
local file = create(input, finder)
if file then
table.insert(files, file)
local function process_pattern(path)
local prefix, middle, suffix = path:match "^(.-){(.-)}(.-)$"
local results = {}

if not (prefix and middle and suffix) then
return { path }
end

local parts = vim.split(middle, ",", { plain = true })

for _, part in ipairs(parts) do
local expanded_path = prefix .. part .. suffix
local nested_results = process_pattern(expanded_path)

for _, nested_result in ipairs(nested_results) do
table.insert(results, nested_result)
end
end
return files

return results
end

local file_names = vim.split(middle, ",", { plain = true })
for _, file_name in ipairs(file_names) do
local resolved_path = prefix .. file_name .. suffix
local file = create(resolved_path, finder)
local expanded_paths = process_pattern(input)
local files = {}

for _, path in ipairs(expanded_paths) do
local file = create(path, finder)
if file then
table.insert(files, file)
end
Expand Down

0 comments on commit 8272ec1

Please sign in to comment.