@@ -469,34 +469,45 @@ end
469
469
470
470
local hasAsked = {}
471
471
--- @async
472
- local function askFor3rd (uri , cfg )
472
+ local function askFor3rd (uri , cfg , checkThirdParty )
473
473
if hasAsked [cfg .name ] then
474
474
return nil
475
475
end
476
- hasAsked [cfg .name ] = true
477
- local yes1 = lang .script .WINDOW_APPLY_WHIT_SETTING
478
- local yes2 = lang .script .WINDOW_APPLY_WHITOUT_SETTING
479
- local no = lang .script .WINDOW_DONT_SHOW_AGAIN
480
- local result = client .awaitRequestMessage (' Info'
481
- , lang .script (' WINDOW_ASK_APPLY_LIBRARY' , cfg .name )
482
- , {yes1 , yes2 , no }
483
- )
484
- if not result then
485
- return nil
486
- end
487
- if result == yes1 then
476
+
477
+ if checkThirdParty == ' Apply' then
488
478
apply3rd (uri , cfg , false )
489
- elseif result == yes2 then
479
+ elseif checkThirdParty == ' ApplyInMemory ' then
490
480
apply3rd (uri , cfg , true )
491
- else
492
- client .setConfig ({
493
- {
494
- key = ' Lua.workspace.checkThirdParty' ,
495
- action = ' set' ,
496
- value = false ,
497
- uri = uri ,
498
- },
499
- }, false )
481
+ elseif checkThirdParty == ' Disable' then
482
+ return nil
483
+ elseif checkThirdParty == ' Ask' then
484
+ hasAsked [cfg .name ] = true
485
+ local applyAndSetConfig = lang .script .WINDOW_APPLY_WHIT_SETTING
486
+ local applyInMemory = lang .script .WINDOW_APPLY_WHITOUT_SETTING
487
+ local dontShowAgain = lang .script .WINDOW_DONT_SHOW_AGAIN
488
+ local result = client .awaitRequestMessage (' Info'
489
+ , lang .script (' WINDOW_ASK_APPLY_LIBRARY' , cfg .name )
490
+ , {applyAndSetConfig , applyInMemory , dontShowAgain }
491
+ )
492
+ if not result then
493
+ -- "If none got selected"
494
+ -- See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showMessageRequest
495
+ return nil
496
+ end
497
+ if result == applyAndSetConfig then
498
+ apply3rd (uri , cfg , false )
499
+ elseif result == applyInMemory then
500
+ apply3rd (uri , cfg , true )
501
+ else
502
+ client .setConfig ({
503
+ {
504
+ key = ' Lua.workspace.checkThirdParty' ,
505
+ action = ' set' ,
506
+ value = ' Disable' ,
507
+ uri = uri ,
508
+ },
509
+ }, false )
510
+ end
500
511
end
501
512
end
502
513
@@ -517,7 +528,7 @@ local function wholeMatch(a, b)
517
528
return true
518
529
end
519
530
520
- local function check3rdByWords (uri , configs )
531
+ local function check3rdByWords (uri , configs , checkThirdParty )
521
532
if not files .isLua (uri ) then
522
533
return
523
534
end
@@ -546,7 +557,7 @@ local function check3rdByWords(uri, configs)
546
557
log .info (' Found 3rd library by word: ' , word , uri , library , inspect (config .get (uri , ' Lua.workspace.library' )))
547
558
--- @async
548
559
await .call (function ()
549
- askFor3rd (uri , cfg )
560
+ askFor3rd (uri , cfg , checkThirdParty )
550
561
end )
551
562
return
552
563
end
@@ -556,7 +567,7 @@ local function check3rdByWords(uri, configs)
556
567
end , id )
557
568
end
558
569
559
- local function check3rdByFileName (uri , configs )
570
+ local function check3rdByFileName (uri , configs , checkThirdParty )
560
571
local path = ws .getRelativePath (uri )
561
572
if not path then
562
573
return
@@ -582,7 +593,7 @@ local function check3rdByFileName(uri, configs)
582
593
log .info (' Found 3rd library by filename: ' , filename , uri , library , inspect (config .get (uri , ' Lua.workspace.library' )))
583
594
--- @async
584
595
await .call (function ()
585
- askFor3rd (uri , cfg )
596
+ askFor3rd (uri , cfg , checkThirdParty )
586
597
end )
587
598
return
588
599
end
@@ -597,8 +608,12 @@ local function check3rd(uri)
597
608
if ws .isIgnored (uri ) then
598
609
return
599
610
end
600
- if not config .get (uri , ' Lua.workspace.checkThirdParty' ) then
611
+ local checkThirdParty = config .get (uri , ' Lua.workspace.checkThirdParty' )
612
+ -- Backwards compatability: `checkThirdParty` used to be a boolean.
613
+ if not checkThirdParty or checkThirdParty == ' Disable' then
601
614
return
615
+ elseif checkThirdParty == true then
616
+ checkThirdParty = ' Ask'
602
617
end
603
618
local scp = scope .getScope (uri )
604
619
if not scp :get ' canCheckThirdParty' then
@@ -608,8 +623,8 @@ local function check3rd(uri)
608
623
if not thirdConfigs then
609
624
return
610
625
end
611
- check3rdByWords (uri , thirdConfigs )
612
- check3rdByFileName (uri , thirdConfigs )
626
+ check3rdByWords (uri , thirdConfigs , checkThirdParty )
627
+ check3rdByFileName (uri , thirdConfigs , checkThirdParty )
613
628
end
614
629
615
630
local function check3rdOfWorkspace (suri )
0 commit comments