summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-08 16:47:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-08 16:47:30 +0800
commit7106bc546af5a6d88941b645412eb4c063c5a912 (patch)
treeae8cec0acd828937167384449d1f7f90b5b6fae6
parentf4e4cc0114adba8d199f9f81298a7c15c9576d5c (diff)
downloadlua-language-server-7106bc546af5a6d88941b645412eb4c063c5a912.zip
#409 apply without local setting
-rw-r--r--script/client.lua6
-rw-r--r--script/library.lua34
2 files changed, 28 insertions, 12 deletions
diff --git a/script/client.lua b/script/client.lua
index 47fd48e5..00db9fce 100644
--- a/script/client.lua
+++ b/script/client.lua
@@ -105,7 +105,8 @@ end
---@field uri? uri
---@param changes config.change[]
-function m.setConfig(changes)
+---@param updateLocal boolean
+function m.setConfig(changes, updateLocal)
local finalChanges = {}
for _, change in ipairs(changes) do
if change.action == 'add' then
@@ -120,6 +121,9 @@ function m.setConfig(changes)
end
end
end
+ if not updateLocal then
+ return
+ end
if #finalChanges == 0 then
return
end
diff --git a/script/library.lua b/script/library.lua
index 516a4dd3..4a40fead 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -9,6 +9,7 @@ local fsu = require 'fs-utility'
local define = require "proto.define"
local files = require 'files'
local await = require 'await'
+local timer = require 'timer'
local m = {}
@@ -293,7 +294,7 @@ local function load3rdConfig()
return configs
end
-local function apply3rd(cfg)
+local function apply3rd(cfg, localConfig)
local changes = {}
for _, change in ipairs(cfg.configs) do
changes[#changes+1] = change
@@ -313,18 +314,19 @@ local function apply3rd(cfg)
value = ('${3rd}/%s/library'):format(cfg.name),
}
- client.setConfig(changes)
+ client.setConfig(changes, localConfig)
end
local hasAsked
local function askFor3rd(cfg)
hasAsked = true
-- TODO: translate
- local yes = lang.script['启用']
- local no = lang.script.WINDOW_DONT_SHOW_AGAIN
+ local yes1 = lang.script['应用并修改设置']
+ local yes2 = lang.script['应用但不修改设置']
+ local no = lang.script.WINDOW_DONT_SHOW_AGAIN
local result = client.awaitRequestMessage('Info'
- , lang.script('是否需要将你的工作环境配置为 `{}` ?(这会修改你的工作区设置)', cfg.name)
- , {yes, no}
+ , lang.script('是否需要将你的工作环境配置为 `{}` ?', cfg.name)
+ , {yes1, yes2, no}
)
if not result then
return nil
@@ -336,8 +338,10 @@ local function askFor3rd(cfg)
value = false,
},
}
- if result == yes then
- apply3rd(cfg)
+ if result == yes1 then
+ apply3rd(cfg, true)
+ elseif result == yes2 then
+ apply3rd(cfg, false)
end
end
@@ -404,8 +408,17 @@ local function check3rdByFileName(uri, configs)
end)
end
+local lastCheckedUri = {}
+local function checkedUri(uri)
+ if lastCheckedUri[uri]
+ and timer.clock() - lastCheckedUri[uri] < 5 then
+ return false
+ end
+ lastCheckedUri[uri] = timer.clock()
+ return true
+end
+
local thirdConfigs
-local hasCheckedUri = {}
local function check3rd(uri)
if hasAsked then
return
@@ -419,8 +432,7 @@ local function check3rd(uri)
if not thirdConfigs then
return
end
- if not hasCheckedUri[uri] then
- hasCheckedUri[uri] = true
+ if checkedUri(uri) then
if files.isLua(uri) then
local text = files.getText(uri)
check3rdByWords(text, thirdConfigs)