Skip to content

Commit 5f7b0a3

Browse files
committed
Make workspace.checkThirdParty a string enum
This lets you skip the "apply third party library to workspace configuration" prompt.
1 parent 4819a7a commit 5f7b0a3

File tree

6 files changed

+89
-39
lines changed

6 files changed

+89
-39
lines changed

doc/en-us/config.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -2173,17 +2173,25 @@ Automatic detection and adaptation of third-party libraries, currently supported
21732173
* skynet
21742174
* Jass
21752175

2176+
Value can be one of:
2177+
* `Ask` (ask every time)
2178+
* `Apply` (always apply third-party libraries and set the workspace
2179+
configuration)
2180+
* `ApplyInMemory` (always apply third-party libraries but don't set the
2181+
workspace configuration)
2182+
* `Disable` (don't ask and don't apply)
2183+
21762184

21772185
## type
21782186

21792187
```ts
2180-
boolean
2188+
string
21812189
```
21822190

21832191
## default
21842192

21852193
```jsonc
2186-
true
2194+
"Ask"
21872195
```
21882196

21892197
# workspace.ignoreDir

doc/pt-br/config.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -2173,17 +2173,24 @@ Automatic detection and adaptation of third-party libraries, currently supported
21732173
* skynet
21742174
* Jass
21752175

2176+
Value can be one of:
2177+
* `Ask` (ask every time)
2178+
* `Apply` (always apply third-party libraries and set the workspace
2179+
configuration)
2180+
* `ApplyInMemory` (always apply third-party libraries but don't set the
2181+
workspace configuration)
2182+
* `Disable` (don't ask and don't apply)
21762183

21772184
## type
21782185

21792186
```ts
2180-
boolean
2187+
string
21812188
```
21822189

21832190
## default
21842191

21852192
```jsonc
2186-
true
2193+
"Ask"
21872194
```
21882195

21892196
# workspace.ignoreDir

doc/zh-cn/config.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -2172,17 +2172,25 @@ true
21722172
* skynet
21732173
* Jass
21742174

2175+
Value can be one of:
2176+
* `Ask` (ask every time)
2177+
* `Apply` (always apply third-party libraries and set the workspace
2178+
configuration)
2179+
* `ApplyInMemory` (always apply third-party libraries but don't set the
2180+
workspace configuration)
2181+
* `Disable` (don't ask and don't apply)
2182+
21752183

21762184
## type
21772185

21782186
```ts
2179-
boolean
2187+
string
21802188
```
21812189

21822190
## default
21832191

21842192
```jsonc
2185-
true
2193+
"Ask"
21862194
```
21872195

21882196
# workspace.ignoreDir

doc/zh-tw/config.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -2172,17 +2172,24 @@ true
21722172
* skynet
21732173
* Jass
21742174

2175+
Value can be one of:
2176+
* `Ask` (ask every time)
2177+
* `Apply` (always apply third-party libraries and set the workspace
2178+
configuration)
2179+
* `ApplyInMemory` (always apply third-party libraries but don't set the
2180+
workspace configuration)
2181+
* `Disable` (don't ask and don't apply)
21752182

21762183
## type
21772184

21782185
```ts
2179-
boolean
2186+
string
21802187
```
21812188

21822189
## default
21832190

21842191
```jsonc
2185-
true
2192+
"Ask"
21862193
```
21872194

21882195
# workspace.ignoreDir

script/config/template.lua

+6-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,12 @@ local template = {
317317
['Lua.workspace.maxPreload'] = Type.Integer >> 5000,
318318
['Lua.workspace.preloadFileSize'] = Type.Integer >> 500,
319319
['Lua.workspace.library'] = Type.Array(Type.String),
320-
['Lua.workspace.checkThirdParty'] = Type.Boolean >> true,
320+
['Lua.workspace.checkThirdParty'] = Type.String >> 'Ask' << {
321+
'Ask',
322+
'Apply',
323+
'ApplyInMemory',
324+
'Disable',
325+
},
321326
['Lua.workspace.userThirdParty'] = Type.Array(Type.String),
322327
['Lua.completion.enable'] = Type.Boolean >> true,
323328
['Lua.completion.callSnippet'] = Type.String >> 'Disable' << {

script/library.lua

+45-30
Original file line numberDiff line numberDiff line change
@@ -469,34 +469,45 @@ end
469469

470470
local 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
501512
end
502513

@@ -517,7 +528,7 @@ local function wholeMatch(a, b)
517528
return true
518529
end
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)
557568
end
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)
613628
end
614629

615630
local function check3rdOfWorkspace(suri)

0 commit comments

Comments
 (0)