@@ -144,10 +144,9 @@ function ProviderSwitch:switch(next_pipeline)
144
144
self .pipeline = next_pipeline
145
145
end
146
146
147
- --- @param name string
148
147
--- @param query string ?
149
148
--- @param context PipelineContext ?
150
- function ProviderSwitch :provide (name , query , context )
149
+ function ProviderSwitch :provide (query , context )
151
150
local provider_config = self .provider_configs [self .pipeline ]
152
151
-- log.debug(
153
152
-- "|fzfx.general - ProviderSwitch:provide| pipeline:%s, provider_config:%s, context:%s",
@@ -157,17 +156,15 @@ function ProviderSwitch:provide(name, query, context)
157
156
-- )
158
157
log .ensure (
159
158
type (provider_config ) == " table" ,
160
- " invalid provider config in %s! pipeline: %s, provider config: %s" ,
161
- vim .inspect (name ),
159
+ " invalid provider config in %s! provider config: %s" ,
162
160
vim .inspect (self .pipeline ),
163
161
vim .inspect (provider_config )
164
162
)
165
163
log .ensure (
166
164
type (provider_config .provider ) == " table"
167
165
or type (provider_config .provider ) == " string"
168
166
or type (provider_config .provider ) == " function" ,
169
- " invalid provider in %s! pipeline: %s, provider: %s" ,
170
- vim .inspect (name ),
167
+ " invalid provider in %s! provider: %s" ,
171
168
vim .inspect (self .pipeline ),
172
169
vim .inspect (provider_config )
173
170
)
@@ -177,8 +174,7 @@ function ProviderSwitch:provide(name, query, context)
177
174
or provider_config .provider_type == ProviderTypeEnum .COMMAND
178
175
or provider_config .provider_type == ProviderTypeEnum .COMMAND_LIST
179
176
or provider_config .provider_type == ProviderTypeEnum .LIST ,
180
- " invalid provider type in %s! pipeline: %s, provider type: %s" ,
181
- vim .inspect (name ),
177
+ " invalid provider type in %s! provider type: %s" ,
182
178
vim .inspect (self .pipeline ),
183
179
vim .inspect (provider_config )
184
180
)
@@ -240,7 +236,7 @@ function ProviderSwitch:provide(name, query, context)
240
236
utils .writefile (self .resultfile , " " )
241
237
log .err (
242
238
" failed to call pipeline %s command provider %s! query:%s, context:%s, error:%s" ,
243
- vim .inspect (name ),
239
+ vim .inspect (self . pipeline ),
244
240
vim .inspect (provider_config ),
245
241
vim .inspect (query ),
246
242
vim .inspect (context ),
@@ -271,7 +267,7 @@ function ProviderSwitch:provide(name, query, context)
271
267
utils .writefile (self .resultfile , " " )
272
268
log .err (
273
269
" failed to call pipeline %s command_list provider %s! query:%s, context:%s, error:%s" ,
274
- vim .inspect (name ),
270
+ vim .inspect (self . pipeline ),
275
271
vim .inspect (provider_config ),
276
272
vim .inspect (query ),
277
273
vim .inspect (context ),
@@ -299,7 +295,7 @@ function ProviderSwitch:provide(name, query, context)
299
295
utils .writefile (self .resultfile , " " )
300
296
log .err (
301
297
" failed to call pipeline %s list provider %s! query:%s, context:%s, error:%s" ,
302
- vim .inspect (name ),
298
+ vim .inspect (self . pipeline ),
303
299
vim .inspect (provider_config ),
304
300
vim .inspect (query ),
305
301
vim .inspect (context ),
@@ -335,10 +331,11 @@ end
335
331
--- @class PreviewerSwitch
336
332
--- @field pipeline PipelineName
337
333
--- @field previewer_configs table<PipelineName , PreviewerConfig>
338
- --- @field previewer_labels table<PipelineName , string ? >
334
+ --- @field last_previewer_label string ?
339
335
--- @field metafile string
340
336
--- @field resultfile string
341
337
--- @field fzfportfile string
338
+ --- @field fzfport string ?
342
339
local PreviewerSwitch = {}
343
340
344
341
--- @param name string
@@ -369,10 +366,11 @@ function PreviewerSwitch:new(name, pipeline, previewer_configs)
369
366
local o = {
370
367
pipeline = pipeline ,
371
368
previewer_configs = previewer_configs_map ,
372
- previewer_labels = {} ,
369
+ last_previewer_label = nil ,
373
370
metafile = _make_cache_filename (" previewer" , " metafile" , name ),
374
371
resultfile = _make_cache_filename (" previewer" , " resultfile" , name ),
375
372
fzfportfile = _make_cache_filename (" previewer" , " fzfport" , name ),
373
+ fzfport = nil ,
376
374
}
377
375
setmetatable (o , self )
378
376
self .__index = self
@@ -385,11 +383,10 @@ function PreviewerSwitch:switch(next_pipeline)
385
383
self .pipeline = next_pipeline
386
384
end
387
385
388
- --- @param name string
389
386
--- @param line string
390
387
--- @param context PipelineContext ?
391
388
--- @return PreviewerType
392
- function PreviewerSwitch :preview (name , line , context )
389
+ function PreviewerSwitch :preview (line , context )
393
390
local previewer_config = self .previewer_configs [self .pipeline ]
394
391
-- log.debug(
395
392
-- "|fzfx.general - PreviewerSwitch:preview| pipeline:%s, previewer_config:%s, context:%s",
@@ -399,24 +396,21 @@ function PreviewerSwitch:preview(name, line, context)
399
396
-- )
400
397
log .ensure (
401
398
type (previewer_config ) == " table" ,
402
- " invalid previewer config in %s! pipeline: %s, previewer config: %s" ,
403
- vim .inspect (name ),
399
+ " invalid previewer config in %s! previewer config: %s" ,
404
400
vim .inspect (self .pipeline ),
405
401
vim .inspect (previewer_config )
406
402
)
407
403
log .ensure (
408
404
type (previewer_config .previewer ) == " function" ,
409
- " invalid previewer in %s! pipeline: %s, previewer: %s" ,
410
- vim .inspect (name ),
405
+ " invalid previewer in %s! previewer: %s" ,
411
406
vim .inspect (self .pipeline ),
412
407
vim .inspect (previewer_config )
413
408
)
414
409
log .ensure (
415
410
previewer_config .previewer_type == PreviewerTypeEnum .COMMAND
416
411
or previewer_config .previewer_type == PreviewerTypeEnum .COMMAND_LIST
417
412
or previewer_config .previewer_type == PreviewerTypeEnum .LIST ,
418
- " invalid previewer type in %s! pipeline: %s, previewer type: %s" ,
419
- vim .inspect (name ),
413
+ " invalid previewer type in %s! previewer type: %s" ,
420
414
vim .inspect (self .pipeline ),
421
415
vim .inspect (previewer_config )
422
416
)
@@ -436,7 +430,7 @@ function PreviewerSwitch:preview(name, line, context)
436
430
utils .writefile (self .resultfile , " " )
437
431
log .err (
438
432
" failed to call pipeline %s command previewer %s! line:%s, context:%s, error:%s" ,
439
- vim .inspect (name ),
433
+ vim .inspect (self . pipeline ),
440
434
vim .inspect (previewer_config .previewer ),
441
435
vim .inspect (line ),
442
436
vim .inspect (context ),
@@ -468,7 +462,7 @@ function PreviewerSwitch:preview(name, line, context)
468
462
utils .writefile (self .resultfile , " " )
469
463
log .err (
470
464
" failed to call pipeline %s command_list previewer %s! line:%s, context:%s, error:%s" ,
471
- vim .inspect (name ),
465
+ vim .inspect (self . pipeline ),
472
466
vim .inspect (previewer_config .previewer ),
473
467
vim .inspect (line ),
474
468
vim .inspect (context ),
@@ -502,7 +496,7 @@ function PreviewerSwitch:preview(name, line, context)
502
496
utils .writefile (self .resultfile , " " )
503
497
log .err (
504
498
" failed to call pipeline %s list previewer %s! line:%s, context:%s, error:%s" ,
505
- vim .inspect (name ),
499
+ vim .inspect (self . pipeline ),
506
500
vim .inspect (previewer_config .previewer ),
507
501
vim .inspect (line ),
508
502
vim .inspect (context ),
@@ -526,11 +520,10 @@ function PreviewerSwitch:preview(name, line, context)
526
520
return previewer_config .previewer_type
527
521
end
528
522
529
- --- @param name string
530
523
--- @param line string ?
531
524
--- @param context PipelineContext
532
525
--- @return string ?
533
- function PreviewerSwitch :preview_label (name , line , context )
526
+ function PreviewerSwitch :preview_label (line , context )
534
527
local previewer_config = self .previewer_configs [self .pipeline ]
535
528
-- log.debug(
536
529
-- "|fzfx.general - PreviewerSwitch:preview_label| pipeline:%s, previewer_config:%s, context:%s",
@@ -540,8 +533,7 @@ function PreviewerSwitch:preview_label(name, line, context)
540
533
-- )
541
534
log .ensure (
542
535
type (previewer_config ) == " table" ,
543
- " invalid previewer config in %s! pipeline: %s, previewer config: %s" ,
544
- vim .inspect (name ),
536
+ " invalid previewer config in %s! previewer config: %s" ,
545
537
vim .inspect (self .pipeline ),
546
538
vim .inspect (previewer_config )
547
539
)
@@ -550,8 +542,7 @@ function PreviewerSwitch:preview_label(name, line, context)
550
542
or previewer_config .previewer_label == nil
551
543
or type (previewer_config .previewer_label ) == " boolean"
552
544
or type (previewer_config .previewer_label ) == " string" ,
553
- " invalid previewer label in %s! pipeline: %s, previewer: %s" ,
554
- vim .inspect (name ),
545
+ " invalid previewer label in %s! previewer: %s" ,
555
546
vim .inspect (self .pipeline ),
556
547
vim .inspect (previewer_config )
557
548
)
@@ -564,34 +555,38 @@ function PreviewerSwitch:preview_label(name, line, context)
564
555
then
565
556
return
566
557
end
567
- local label = type (previewer_config .previewer_label ) == " function"
568
- and previewer_config .previewer_label (line , context )
569
- or previewer_config .previewer_label
570
- log .debug (
571
- " |fzfx.general - PreviewerSwitch:preview_label| line:%s, label:%s" ,
572
- vim .inspect (line ),
573
- vim .inspect (label )
574
- )
575
- if type (label ) ~= " string" then
576
- return
577
- end
578
- self .previewer_labels [self .pipeline ] = label
579
558
580
- -- do it async/later
581
- vim .defer_fn (function ()
582
- local last_label = self .previewer_labels [self .pipeline ]
583
- self .previewer_labels [self .pipeline ] = nil
584
- if type (last_label ) ~= " string" then
559
+ vim .schedule (function ()
560
+ local label = type (previewer_config .previewer_label ) == " function"
561
+ and previewer_config .previewer_label (line , context )
562
+ or previewer_config .previewer_label
563
+ log .debug (
564
+ " |fzfx.general - PreviewerSwitch:preview_label| line:%s, label:%s" ,
565
+ vim .inspect (line ),
566
+ vim .inspect (label )
567
+ )
568
+ if type (label ) ~= " string" then
585
569
return
586
570
end
587
- local fzf_port = utils .readfile (self .fzfportfile ) --[[ @as string]]
588
- fzf_helpers .send_http_post (
589
- fzf_port ,
590
- string.format (" change-preview-label(%s)" , vim .trim (last_label ))
591
- )
592
- end , 100 )
571
+ self .last_previewer_label = label
572
+
573
+ -- do it async/later
574
+ vim .defer_fn (function ()
575
+ local last_label = self .last_previewer_label
576
+ self .last_previewer_label = nil
577
+ if type (last_label ) ~= " string" then
578
+ return
579
+ end
580
+ self .fzfport = utils .string_not_empty (self .fzfport ) and self .fzfport
581
+ or utils .readfile (self .fzfportfile ) --[[ @as string]]
582
+ fzf_helpers .send_http_post (
583
+ self .fzfport ,
584
+ string.format (" change-preview-label(%s)" , vim .trim (last_label ))
585
+ )
586
+ end , 200 )
587
+ end )
593
588
594
- return label
589
+ return self . pipeline
595
590
end
596
591
597
592
-- previewer switch }
@@ -777,12 +772,12 @@ local function general(name, query, bang, pipeline_configs, default_pipeline)
777
772
778
773
--- @param query_params string
779
774
local function provide_rpc (query_params )
780
- provider_switch :provide (name , query_params , context )
775
+ provider_switch :provide (query_params , context )
781
776
end
782
777
783
778
--- @param line_params string
784
779
local function preview_rpc (line_params )
785
- previewer_switch :preview (name , line_params , context )
780
+ previewer_switch :preview (line_params , context )
786
781
end
787
782
788
783
local provide_rpc_id = server .get_rpc_server ():register (provide_rpc )
@@ -829,14 +824,14 @@ local function general(name, query, bang, pipeline_configs, default_pipeline)
829
824
if constants .has_curl then
830
825
--- @param line_params string
831
826
local function preview_label_rpc (line_params )
832
- previewer_switch :preview_label (name , line_params , context )
827
+ previewer_switch :preview_label (line_params , context )
833
828
end
834
829
local preview_label_rpc_id =
835
830
server .get_rpc_server ():register (preview_label_rpc )
836
831
table.insert (rpc_registries , preview_label_rpc_id )
837
832
preview_label_command = string.format (
838
833
" %s %s {}" ,
839
- fzf_helpers .make_lua_command (" rpc" , " notify .lua" ),
834
+ fzf_helpers .make_lua_command (" rpc" , " request .lua" ),
840
835
preview_label_rpc_id
841
836
)
842
837
log .debug (
@@ -1013,11 +1008,11 @@ local function general(name, query, bang, pipeline_configs, default_pipeline)
1013
1008
actions ,
1014
1009
context ,
1015
1010
function ()
1016
- vim .schedule_wrap (function ()
1011
+ vim .defer_fn (function ()
1017
1012
for _ , rpc_id in ipairs (rpc_registries ) do
1018
1013
server :get_rpc_server ():unregister (rpc_id )
1019
1014
end
1020
- end )
1015
+ end , 3000 )
1021
1016
end
1022
1017
)
1023
1018
return p
0 commit comments