8686--- @field process1 ? boolean
8787--- @field profiler ? boolean
8888
89+ local gen_uuid = function ()
90+ -- return uv.random(10)
91+ return uv .hrtime ()
92+ end
93+
8994--- @param opts fzf-lua.SpawnOpts
9095--- @param fn_transform function ?
9196--- @param fn_done function ?
@@ -200,10 +205,11 @@ M.spawn = function(opts, fn_transform, fn_done)
200205 end )
201206 end
202207
203- local abc = require (" fzf-lua.libuv" ).serialize (opts , false )
208+ local uuid = gen_uuid () -- distinguish two call when use worker pool
209+ local optstr = require (" fzf-lua.libuv" ).serialize ({ t = fn_transform , opts = opts .opts }, false )
204210 --- @param data string data stream
205211 --- @return string , string ? line array , partial last line (no EOL )
206- local function split_lines (data , o )
212+ local function split_lines (data , o , id )
207213 -- io.stderr:write("[DEBUG] worker init")
208214 if not _G .fzf_lua_worker_init then
209215 -- TODO: we can pass serialize opts to first queue...
@@ -214,18 +220,25 @@ M.spawn = function(opts, fn_transform, fn_done)
214220 require (" fzf-lua.make_entry" )
215221 _G .fzf_lua_worker_init = true
216222 end
217- local trans = require (" fzf-lua.make_entry" ).file
218- local opts = _G ._opts
223+ if id ~= _G .uuid then -- refresh opts
224+ local d = require (" fzf-lua.libuv" ).deserialize (o , false )
225+ _G .trans = d .t
226+ _G .opts = d .opts
227+ _G .uuid = id
228+ end
229+ -- local trans = require("fzf-lua.make_entry").file
230+ -- local worker_opts = assert(_G.fzf_lua_worker_opts, "no opts")
231+ local trans = _G .trans
232+ local opts = _G .opts
219233 local ret = {}
220234 local start_idx = 1
221235 repeat
222236 local nl_idx = data :find (EOL_data or " \n " , start_idx , true )
223237 if nl_idx then
224238 local cr = data :byte (nl_idx - 1 , nl_idx - 1 ) == 13 -- \r
225239 local line = data :sub (start_idx , nl_idx - (cr and 2 or 1 ))
226- if trans then
227- line = trans (line , opts )
228- end
240+ -- line = trans(line, worker_opts)
241+ if trans then line = trans (line , opts ) end
229242 if line then ret [# ret + 1 ] = line end
230243 start_idx = nl_idx + 1
231244 end
@@ -245,7 +258,7 @@ M.spawn = function(opts, fn_transform, fn_done)
245258 if len == 0 then return end
246259 if ref [len - 1 ] ~= EOL_byte then strbuf :put (EOL_byte ) end -- make split_lines happy
247260 write_cb_count = write_cb_count + 1
248- return work_ctx :queue (strbuf :get ())
261+ return work_ctx :queue (strbuf :get (), optstr , uuid )
249262 end
250263 local eol = len
251264 for i = len - 1 , stop , - 1 do
@@ -261,7 +274,7 @@ M.spawn = function(opts, fn_transform, fn_done)
261274 local data = strbuf :get (eol + 1 )
262275 stop = # strbuf
263276 write_cb_count = write_cb_count + 1
264- work_ctx :queue (data )
277+ work_ctx :queue (data , optstr , uuid )
265278 end
266279 end
267280 if can_finish () then finish (0 , 0 , " [EOF]" , pid ) end
@@ -329,7 +342,7 @@ M.deserialize = function(str, b64)
329342 res = b64 ~= false and base64 .decode (res ) or res
330343 -- safe=false enable call function
331344 local _ , obj = serpent .load (res , { safe = false })
332- assert (type (obj ) == " table" )
345+ assert (type (obj ) == " table" , vim . inspect ( obj ) )
333346 return obj
334347end
335348
@@ -572,10 +585,12 @@ M.spawn_stdio = function(opts)
572585 process1 = opts .process1 ,
573586 profiler = opts .profiler ,
574587 EOL = EOL ,
588+ opts = opts ,
575589 },
576- fn_transform and function (x )
577- return fn_transform (x , opts )
578- end )
590+ fn_transform )
591+ -- fn_transform and function(x)
592+ -- return fn_transform(x, opts)
593+ -- end)
579594end
580595
581596
0 commit comments