diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-10-19 15:12:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-19 15:12:07 +0800 |
commit | 13aebe5389219f3791b3c6b8d91129a6074ec105 (patch) | |
tree | 15cd6ca3ddca027923bc5b7698fb5efab5c3d051 | |
parent | 4819a7ad29ab38f6cec0c04e767494d6130f46b2 (diff) | |
parent | 3bbc8dd579dadd67171c758c1065f271c5816133 (diff) | |
download | lua-language-server-13aebe5389219f3791b3c6b8d91129a6074ec105.zip |
Merge pull request #2354 from 9999years/dont-ask-third-party
Make `workspace.checkThirdParty` a string enum
-rw-r--r-- | doc/en-us/config.md | 11 | ||||
-rw-r--r-- | doc/pt-br/config.md | 11 | ||||
-rw-r--r-- | doc/zh-cn/config.md | 11 | ||||
-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, 87 insertions, 39 deletions
diff --git a/doc/en-us/config.md b/doc/en-us/config.md index 52066a54..f57d4d64 100644 --- a/doc/en-us/config.md +++ b/doc/en-us/config.md @@ -2177,13 +2177,20 @@ Automatic detection and adaptation of third-party libraries, currently supported ## type ```ts -boolean +string ``` +## enum + +* ``"Ask"`` +* ``"Apply"`` +* ``"ApplyInMemory"`` +* ``"Disable"`` + ## default ```jsonc -true +"Ask" ``` # workspace.ignoreDir diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md index af0be93c..7add2c98 100644 --- a/doc/pt-br/config.md +++ b/doc/pt-br/config.md @@ -2177,13 +2177,20 @@ Automatic detection and adaptation of third-party libraries, currently supported ## type ```ts -boolean +string ``` +## enum + +* ``"Ask"`` +* ``"Apply"`` +* ``"ApplyInMemory"`` +* ``"Disable"`` + ## default ```jsonc -true +"Ask" ``` # workspace.ignoreDir diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md index 26b54ad5..ebb8325f 100644 --- a/doc/zh-cn/config.md +++ b/doc/zh-cn/config.md @@ -2176,13 +2176,20 @@ true ## type ```ts -boolean +string ``` +## enum + +* ``"Ask"`` +* ``"Apply"`` +* ``"ApplyInMemory"`` +* ``"Disable"`` + ## default ```jsonc -true +"Ask" ``` # workspace.ignoreDir diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md index 9a564683..8b01d78c 100644 --- a/doc/zh-tw/config.md +++ b/doc/zh-tw/config.md @@ -2176,13 +2176,20 @@ true ## type ```ts -boolean +string ``` +## enum + +* ``"Ask"`` +* ``"Apply"`` +* ``"ApplyInMemory"`` +* ``"Disable"`` + ## 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) |