From 953fc89655316180ce00c343e4cddae1c36d3571 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Tue, 25 Apr 2023 20:21:10 +0100 Subject: [PATCH] perf: return a table of results from the command finder When reading the output of a command we are now reading the stream line by line and building the table of results. This will save us a loop of the results later, if we returned a string we need to split the string before adding each line to the completion buffer because nvim only supports replacing one line at a time. --- lua/ivy/utils.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/ivy/utils.lua b/lua/ivy/utils.lua index e54f07b..7340c00 100644 --- a/lua/ivy/utils.lua +++ b/lua/ivy/utils.lua @@ -37,10 +37,14 @@ utils.command_finder = function(command, min) if handle == nil then return {} end - local result = handle:read "*a" - handle:close() - return result + local results = {}; + for line in handle:lines() do + table.insert(results, { content = line }) + end + + handle:close() + return results end end