From 5f7b0a3dd4ae5ff346ea5cfd1436ae9d54f00474 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Sat, 30 Sep 2023 15:09:00 -0700 Subject: [PATCH 1/2] Make `workspace.checkThirdParty` a string enum This lets you skip the "apply third party library to workspace configuration" prompt. --- doc/en-us/config.md | 12 +++++- doc/pt-br/config.md | 11 +++++- doc/zh-cn/config.md | 12 +++++- doc/zh-tw/config.md | 11 +++++- script/config/template.lua | 7 +++- script/library.lua | 75 +++++++++++++++++++++++--------------- 6 files changed, 89 insertions(+), 39 deletions(-) diff --git a/doc/en-us/config.md b/doc/en-us/config.md index 52066a54d..7a283955b 100644 --- a/doc/en-us/config.md +++ b/doc/en-us/config.md @@ -2173,17 +2173,25 @@ Automatic detection and adaptation of third-party libraries, currently supported * skynet * Jass +Value can be one of: +* `Ask` (ask every time) +* `Apply` (always apply third-party libraries and set the workspace + configuration) +* `ApplyInMemory` (always apply third-party libraries but don't set the + workspace configuration) +* `Disable` (don't ask and don't apply) + ## type ```ts -boolean +string ``` ## default ```jsonc -true +"Ask" ``` # workspace.ignoreDir diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md index af0be93c2..63a28c419 100644 --- a/doc/pt-br/config.md +++ b/doc/pt-br/config.md @@ -2173,17 +2173,24 @@ Automatic detection and adaptation of third-party libraries, currently supported * skynet * Jass +Value can be one of: +* `Ask` (ask every time) +* `Apply` (always apply third-party libraries and set the workspace + configuration) +* `ApplyInMemory` (always apply third-party libraries but don't set the + workspace configuration) +* `Disable` (don't ask and don't apply) ## type ```ts -boolean +string ``` ## default ```jsonc -true +"Ask" ``` # workspace.ignoreDir diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md index 26b54ad56..1866fb828 100644 --- a/doc/zh-cn/config.md +++ b/doc/zh-cn/config.md @@ -2172,17 +2172,25 @@ true * skynet * Jass +Value can be one of: +* `Ask` (ask every time) +* `Apply` (always apply third-party libraries and set the workspace + configuration) +* `ApplyInMemory` (always apply third-party libraries but don't set the + workspace configuration) +* `Disable` (don't ask and don't apply) + ## type ```ts -boolean +string ``` ## default ```jsonc -true +"Ask" ``` # workspace.ignoreDir diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md index 9a5646835..7b59dda22 100644 --- a/doc/zh-tw/config.md +++ b/doc/zh-tw/config.md @@ -2172,17 +2172,24 @@ true * skynet * Jass +Value can be one of: +* `Ask` (ask every time) +* `Apply` (always apply third-party libraries and set the workspace + configuration) +* `ApplyInMemory` (always apply third-party libraries but don't set the + workspace configuration) +* `Disable` (don't ask and don't apply) ## type ```ts -boolean +string ``` ## default ```jsonc -true +"Ask" ``` # workspace.ignoreDir diff --git a/script/config/template.lua b/script/config/template.lua index 436f5e1a4..6919efa8f 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -317,7 +317,12 @@ local template = { ['Lua.workspace.maxPreload'] = Type.Integer >> 5000, ['Lua.workspace.preloadFileSize'] = Type.Integer >> 500, ['Lua.workspace.library'] = Type.Array(Type.String), - ['Lua.workspace.checkThirdParty'] = Type.Boolean >> true, + ['Lua.workspace.checkThirdParty'] = Type.String >> 'Ask' << { + 'Ask', + 'Apply', + 'ApplyInMemory', + 'Disable', + }, ['Lua.workspace.userThirdParty'] = Type.Array(Type.String), ['Lua.completion.enable'] = Type.Boolean >> true, ['Lua.completion.callSnippet'] = Type.String >> 'Disable' << { diff --git a/script/library.lua b/script/library.lua index 3a9bbbc6c..4446797a7 100644 --- a/script/library.lua +++ b/script/library.lua @@ -469,34 +469,45 @@ end local hasAsked = {} ---@async -local function askFor3rd(uri, cfg) +local function askFor3rd(uri, cfg, checkThirdParty) if hasAsked[cfg.name] then return nil end - hasAsked[cfg.name] = true - local yes1 = lang.script.WINDOW_APPLY_WHIT_SETTING - local yes2 = lang.script.WINDOW_APPLY_WHITOUT_SETTING - local no = lang.script.WINDOW_DONT_SHOW_AGAIN - local result = client.awaitRequestMessage('Info' - , lang.script('WINDOW_ASK_APPLY_LIBRARY', cfg.name) - , {yes1, yes2, no} - ) - if not result then - return nil - end - if result == yes1 then + + if checkThirdParty == 'Apply' then apply3rd(uri, cfg, false) - elseif result == yes2 then + elseif checkThirdParty == 'ApplyInMemory' then apply3rd(uri, cfg, true) - else - client.setConfig({ - { - key = 'Lua.workspace.checkThirdParty', - action = 'set', - value = false, - uri = uri, - }, - }, false) + elseif checkThirdParty == 'Disable' then + return nil + elseif checkThirdParty == 'Ask' then + hasAsked[cfg.name] = true + local applyAndSetConfig = lang.script.WINDOW_APPLY_WHIT_SETTING + local applyInMemory = lang.script.WINDOW_APPLY_WHITOUT_SETTING + local dontShowAgain = lang.script.WINDOW_DONT_SHOW_AGAIN + local result = client.awaitRequestMessage('Info' + , lang.script('WINDOW_ASK_APPLY_LIBRARY', cfg.name) + , {applyAndSetConfig, applyInMemory, dontShowAgain} + ) + if not result then + -- "If none got selected" + -- See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showMessageRequest + return nil + end + if result == applyAndSetConfig then + apply3rd(uri, cfg, false) + elseif result == applyInMemory then + apply3rd(uri, cfg, true) + else + client.setConfig({ + { + key = 'Lua.workspace.checkThirdParty', + action = 'set', + value = 'Disable', + uri = uri, + }, + }, false) + end end end @@ -517,7 +528,7 @@ local function wholeMatch(a, b) return true end -local function check3rdByWords(uri, configs) +local function check3rdByWords(uri, configs, checkThirdParty) if not files.isLua(uri) then return end @@ -546,7 +557,7 @@ local function check3rdByWords(uri, configs) log.info('Found 3rd library by word: ', word, uri, library, inspect(config.get(uri, 'Lua.workspace.library'))) ---@async await.call(function () - askFor3rd(uri, cfg) + askFor3rd(uri, cfg, checkThirdParty) end) return end @@ -556,7 +567,7 @@ local function check3rdByWords(uri, configs) end, id) end -local function check3rdByFileName(uri, configs) +local function check3rdByFileName(uri, configs, checkThirdParty) local path = ws.getRelativePath(uri) if not path then return @@ -582,7 +593,7 @@ local function check3rdByFileName(uri, configs) log.info('Found 3rd library by filename: ', filename, uri, library, inspect(config.get(uri, 'Lua.workspace.library'))) ---@async await.call(function () - askFor3rd(uri, cfg) + askFor3rd(uri, cfg, checkThirdParty) end) return end @@ -597,8 +608,12 @@ local function check3rd(uri) if ws.isIgnored(uri) then return end - if not config.get(uri, 'Lua.workspace.checkThirdParty') then + local checkThirdParty = config.get(uri, 'Lua.workspace.checkThirdParty') + -- Backwards compatability: `checkThirdParty` used to be a boolean. + if not checkThirdParty or checkThirdParty == 'Disable' then return + elseif checkThirdParty == true then + checkThirdParty = 'Ask' end local scp = scope.getScope(uri) if not scp:get 'canCheckThirdParty' then @@ -608,8 +623,8 @@ local function check3rd(uri) if not thirdConfigs then return end - check3rdByWords(uri, thirdConfigs) - check3rdByFileName(uri, thirdConfigs) + check3rdByWords(uri, thirdConfigs, checkThirdParty) + check3rdByFileName(uri, thirdConfigs, checkThirdParty) end local function check3rdOfWorkspace(suri) From 3bbc8dd579dadd67171c758c1065f271c5816133 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Wed, 11 Oct 2023 13:39:32 -0700 Subject: [PATCH 2/2] Update `doc` and `locale` --- doc/en-us/config.md | 15 +++++++-------- doc/pt-br/config.md | 14 +++++++------- doc/zh-cn/config.md | 15 +++++++-------- doc/zh-tw/config.md | 14 +++++++------- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/doc/en-us/config.md b/doc/en-us/config.md index 7a283955b..f57d4d64e 100644 --- a/doc/en-us/config.md +++ b/doc/en-us/config.md @@ -2173,14 +2173,6 @@ Automatic detection and adaptation of third-party libraries, currently supported * skynet * Jass -Value can be one of: -* `Ask` (ask every time) -* `Apply` (always apply third-party libraries and set the workspace - configuration) -* `ApplyInMemory` (always apply third-party libraries but don't set the - workspace configuration) -* `Disable` (don't ask and don't apply) - ## type @@ -2188,6 +2180,13 @@ Value can be one of: string ``` +## enum + +* ``"Ask"`` +* ``"Apply"`` +* ``"ApplyInMemory"`` +* ``"Disable"`` + ## default ```jsonc diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md index 63a28c419..7add2c982 100644 --- a/doc/pt-br/config.md +++ b/doc/pt-br/config.md @@ -2173,13 +2173,6 @@ Automatic detection and adaptation of third-party libraries, currently supported * skynet * Jass -Value can be one of: -* `Ask` (ask every time) -* `Apply` (always apply third-party libraries and set the workspace - configuration) -* `ApplyInMemory` (always apply third-party libraries but don't set the - workspace configuration) -* `Disable` (don't ask and don't apply) ## type @@ -2187,6 +2180,13 @@ Value can be one of: string ``` +## enum + +* ``"Ask"`` +* ``"Apply"`` +* ``"ApplyInMemory"`` +* ``"Disable"`` + ## default ```jsonc diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md index 1866fb828..ebb8325f4 100644 --- a/doc/zh-cn/config.md +++ b/doc/zh-cn/config.md @@ -2172,14 +2172,6 @@ true * skynet * Jass -Value can be one of: -* `Ask` (ask every time) -* `Apply` (always apply third-party libraries and set the workspace - configuration) -* `ApplyInMemory` (always apply third-party libraries but don't set the - workspace configuration) -* `Disable` (don't ask and don't apply) - ## type @@ -2187,6 +2179,13 @@ Value can be one of: string ``` +## enum + +* ``"Ask"`` +* ``"Apply"`` +* ``"ApplyInMemory"`` +* ``"Disable"`` + ## default ```jsonc diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md index 7b59dda22..8b01d78cc 100644 --- a/doc/zh-tw/config.md +++ b/doc/zh-tw/config.md @@ -2172,13 +2172,6 @@ true * skynet * Jass -Value can be one of: -* `Ask` (ask every time) -* `Apply` (always apply third-party libraries and set the workspace - configuration) -* `ApplyInMemory` (always apply third-party libraries but don't set the - workspace configuration) -* `Disable` (don't ask and don't apply) ## type @@ -2186,6 +2179,13 @@ Value can be one of: string ``` +## enum + +* ``"Ask"`` +* ``"Apply"`` +* ``"ApplyInMemory"`` +* ``"Disable"`` + ## default ```jsonc