diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 17:42:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 17:42:05 +0800 |
commit | 0a11d6f52abe6f0c913c5286b2da7598caf324e0 (patch) | |
tree | 03d8f3d12304320ff0ed784f2d8abc6ce75a4d90 /script | |
parent | 96fbddee50795421f3476140c0cfc0dac48c71a3 (diff) | |
download | lua-language-server-0a11d6f52abe6f0c913c5286b2da7598caf324e0.zip |
`diagnostics.workspaceRate`
Diffstat (limited to 'script')
-rw-r--r-- | script/config/config.lua | 13 | ||||
-rw-r--r-- | script/core/diagnostics/init.lua | 27 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 27 | ||||
-rw-r--r-- | script/provider/provider.lua | 3 |
4 files changed, 38 insertions, 32 deletions
diff --git a/script/config/config.lua b/script/config/config.lua index 81ab4b81..b4a350f7 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -358,15 +358,18 @@ function m.getRaw(uri, key) return value end +---@param scp scope +function m.clean(scp) + scp:set('config.now', {}) + scp:set('config.raw', {}) +end + ---@param scp scope ---@param new table ---@param null any function m.update(scp, new, null) - local oldConfig = scp:get 'config.now' - local newConfig = {} - - scp:set('config.now', newConfig) - scp:set('config.raw', {}) + local newConfig = scp:get 'config.now' + local oldConfig = util.deepCopy(newConfig) local function expand(t, left) for key, value in pairs(t) do diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 4f5510c7..72672f14 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -19,6 +19,32 @@ table.sort(diagList, function (a, b) return (diagSort[a] or 0) < (diagSort[b] or 0) end) +local sleepRest = 0.0 + +---@async +local function checkSleep(uri, passed) + local speedRate = config.get(uri, 'Lua.diagnostics.workspaceRate') + if speedRate <= 0 or speedRate >= 100 then + return + end + local sleepTime = passed * (100 - speedRate) / speedRate + if sleepTime + sleepRest < 0.001 then + sleepRest = sleepRest + sleepTime + return + end + sleepRest = sleepTime + sleepRest + sleepTime = sleepRest + if sleepTime > 0.1 then + sleepTime = 0.1 + end + local clock = os.clock() + await.sleep(sleepTime) + local sleeped = os.clock() - clock + + sleepRest = sleepRest - sleeped +end + +---@async ---@param uri uri ---@param name string ---@param response async fun(result: any) @@ -63,6 +89,7 @@ local function check(uri, name, response) if passed >= 0.5 then log.warn(('Diagnostics [%s] @ [%s] takes [%.3f] sec!'):format(name, uri, passed)) end + checkSleep(uri, passed) if DIAGTIMES then DIAGTIMES[name] = (DIAGTIMES[name] or 0) + passed end diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 09e1ea85..9f64cb88 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -168,28 +168,6 @@ function m.syntaxErrors(uri, ast) end ---@async -local function checkSleep(uri) - local speedRate = config.get(uri, 'Lua.diagnostics.workspaceRate') - if speedRate <= 0 or speedRate >= 100 then - return - end - local currentClock = os.clock() - local passed = currentClock - m.diagnosticsAllClock - local sleepTime = passed * (100 - speedRate) / speedRate + m.sleepRest - m.sleepRest = 0.0 - if sleepTime < 0.001 then - m.sleepRest = m.sleepRest + sleepTime - return - end - if sleepTime > 0.1 then - m.sleepRest = sleepTime - 0.1 - sleepTime = 0.1 - end - await.sleep(sleepTime) - m.diagnosticsAllClock = os.clock() -end - ----@async function m.doDiagnostic(uri, isScopeDiag) if not config.get(uri, 'Lua.diagnostics.enable') then return @@ -266,10 +244,6 @@ function m.doDiagnostic(uri, isScopeDiag) lastPushClock = os.clock() pushResult() end - - if isScopeDiag then - checkSleep(uri) - end end) pushResult() @@ -354,7 +328,6 @@ function m.diagnosticsScope(uri, force) await.close ('diagnosticsScope:' .. uri) await.call(function () ---@async await.sleep(delay) - m.diagnosticsAllClock = os.clock() local clock = os.clock() local bar <close> = progress.create(ws.getScope(uri), lang.script.WORKSPACE_DIAGNOSTIC, 1) local cancelled diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 10376239..e83738d5 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -21,6 +21,7 @@ local scope = require 'workspace.scope' ---@async local function updateConfig(uri) local specified = cfgLoader.loadLocalConfig(uri, CONFIGPATH) + config.clean(scope.override) if specified then log.debug('Load config from specified', CONFIGPATH) log.debug(util.dump(specified)) @@ -32,6 +33,7 @@ local function updateConfig(uri) for _, folder in ipairs(scope.folders) do local uri = folder.uri + config.clean(folder) local clientConfig = cfgLoader.loadClientConfig(uri) if clientConfig then log.debug('Load config from client', uri) @@ -50,6 +52,7 @@ local function updateConfig(uri) local global = cfgLoader.loadClientConfig() log.debug('Load config from client', 'fallback') log.debug(util.dump(global)) + config.clean(scope.fallback) config.update(scope.fallback, global, json.null) end |