diff options
-rw-r--r-- | doc/en-us/config.md | 12 | ||||
-rw-r--r-- | doc/pt-br/config.md | 11 | ||||
-rw-r--r-- | doc/zh-cn/config.md | 12 | ||||
-rw-r--r-- | doc/zh-tw/config.md | 11 | ||||
-rw-r--r-- | script/config/template.lua | 7 | ||||
-rw-r--r-- | 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 52066a54..7a283955 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 af0be93c..63a28c41 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 26b54ad5..1866fb82 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 9a564683..7b59dda2 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 436f5e1a..6919efa8 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 3a9bbbc6..4446797a 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) |