@@ -469,34 +469,45 @@ end
469469
470470local hasAsked = {}
471471--- @async
472- local function askFor3rd (uri , cfg )
472+ local function askFor3rd (uri , cfg , checkThirdParty )
473473 if hasAsked [cfg .name ] then
474474 return nil
475475 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
488478 apply3rd (uri , cfg , false )
489- elseif result == yes2 then
479+ elseif checkThirdParty == ' ApplyInMemory ' then
490480 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
500511 end
501512end
502513
@@ -517,7 +528,7 @@ local function wholeMatch(a, b)
517528 return true
518529end
519530
520- local function check3rdByWords (uri , configs )
531+ local function check3rdByWords (uri , configs , checkThirdParty )
521532 if not files .isLua (uri ) then
522533 return
523534 end
@@ -546,7 +557,7 @@ local function check3rdByWords(uri, configs)
546557 log .info (' Found 3rd library by word: ' , word , uri , library , inspect (config .get (uri , ' Lua.workspace.library' )))
547558 --- @async
548559 await .call (function ()
549- askFor3rd (uri , cfg )
560+ askFor3rd (uri , cfg , checkThirdParty )
550561 end )
551562 return
552563 end
@@ -556,7 +567,7 @@ local function check3rdByWords(uri, configs)
556567 end , id )
557568end
558569
559- local function check3rdByFileName (uri , configs )
570+ local function check3rdByFileName (uri , configs , checkThirdParty )
560571 local path = ws .getRelativePath (uri )
561572 if not path then
562573 return
@@ -582,7 +593,7 @@ local function check3rdByFileName(uri, configs)
582593 log .info (' Found 3rd library by filename: ' , filename , uri , library , inspect (config .get (uri , ' Lua.workspace.library' )))
583594 --- @async
584595 await .call (function ()
585- askFor3rd (uri , cfg )
596+ askFor3rd (uri , cfg , checkThirdParty )
586597 end )
587598 return
588599 end
@@ -597,8 +608,12 @@ local function check3rd(uri)
597608 if ws .isIgnored (uri ) then
598609 return
599610 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
601614 return
615+ elseif checkThirdParty == true then
616+ checkThirdParty = ' Ask'
602617 end
603618 local scp = scope .getScope (uri )
604619 if not scp :get ' canCheckThirdParty' then
@@ -608,8 +623,8 @@ local function check3rd(uri)
608623 if not thirdConfigs then
609624 return
610625 end
611- check3rdByWords (uri , thirdConfigs )
612- check3rdByFileName (uri , thirdConfigs )
626+ check3rdByWords (uri , thirdConfigs , checkThirdParty )
627+ check3rdByFileName (uri , thirdConfigs , checkThirdParty )
613628end
614629
615630local function check3rdOfWorkspace (suri )
0 commit comments