diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-09-19 20:45:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-09-19 20:45:02 +0800 |
commit | 1f93575f7fc938cd675214ebd04bbe4210f6f8ac (patch) | |
tree | efa7d074168129349e04e604a3ea2c13767641d8 | |
parent | fba6856a9cfc54904b8417bc5731dc6f25a297ff (diff) | |
download | lua-language-server-1f93575f7fc938cd675214ebd04bbe4210f6f8ac.zip |
resolve #1558 detect multi libraries
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/library.lua | 75 |
2 files changed, 38 insertions, 40 deletions
diff --git a/changelog.md b/changelog.md index 802f7d35..bff1c503 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # changelog +## 3.6.0 +* `CHG` detect multi libraries [#1558](https://github.com/sumneko/lua-language-server/issues/1558) + ## 3.5.6 `2022-9-16` * `FIX` [#1439](https://github.com/sumneko/lua-language-server/issues/1439) diff --git a/script/library.lua b/script/library.lua index b4333dca..017b3e20 100644 --- a/script/library.lua +++ b/script/library.lua @@ -383,13 +383,13 @@ local function apply3rd(uri, cfg, onlyMemory) client.setConfig(changes, onlyMemory) end -local hasAsked +local hasAsked = {} ---@async local function askFor3rd(uri, cfg) - if hasAsked then + if hasAsked[cfg.name] then return nil end - hasAsked = true + 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 @@ -402,24 +402,8 @@ local function askFor3rd(uri, cfg) end if result == yes1 then apply3rd(uri, cfg, false) - client.setConfig({ - { - key = 'Lua.workspace.checkThirdParty', - action = 'set', - value = false, - uri = uri, - }, - }, false) elseif result == yes2 then apply3rd(uri, cfg, true) - client.setConfig({ - { - key = 'Lua.workspace.checkThirdParty', - action = 'set', - value = false, - uri = uri, - }, - }, true) else client.setConfig({ { @@ -450,9 +434,6 @@ local function wholeMatch(a, b) end local function check3rdByWords(uri, configs) - if hasAsked then - return - end if not files.isLua(uri) then return end @@ -465,23 +446,32 @@ local function check3rdByWords(uri, configs) return end for _, cfg in ipairs(configs) do - if cfg.words then - for _, word in ipairs(cfg.words) do - await.delay() - if wholeMatch(text, word) then + if not cfg.words then + goto CONTINUE + end + if hasAsked[cfg.name] then + goto CONTINUE + end + local library = ('%s/library'):format(cfg.dirname) + if util.arrayHas(config.get(uri, 'Lua.workspace.library'), library) then + goto CONTINUE + end + for _, word in ipairs(cfg.words) do + await.delay() + if wholeMatch(text, word) then + ---@async + await.call(function () askFor3rd(uri, cfg) - return - end + end) + return end end + ::CONTINUE:: end end, id) end local function check3rdByFileName(uri, configs) - if hasAsked then - return - end local path = ws.getRelativePath(uri) if not path then return @@ -491,24 +481,29 @@ local function check3rdByFileName(uri, configs) await.call(function () ---@async await.sleep(0.1) for _, cfg in ipairs(configs) do - if cfg.files then - for _, filename in ipairs(cfg.files) do - await.delay() - if wholeMatch(path, filename) then + if not cfg.files then + goto CONTINUE + end + if hasAsked[cfg.name] then + goto CONTINUE + end + for _, filename in ipairs(cfg.files) do + await.delay() + if wholeMatch(path, filename) then + ---@async + await.call(function () askFor3rd(uri, cfg) - return - end + end) + return end end + ::CONTINUE:: end end, id) end ---@async local function check3rd(uri) - if hasAsked then - return - end if ws.isIgnored(uri) then return end |