diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 17:01:55 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 17:01:55 +0800 |
commit | 32301f8de3d832d428bf75fe44269ed121f4ab4f (patch) | |
tree | dacab9a50a96a1332d10dc2b355173a8770bc9ae /script | |
parent | e6c9cf88693235171cf38581d8e1cf3334744a9c (diff) | |
download | lua-language-server-32301f8de3d832d428bf75fe44269ed121f4ab4f.zip |
workspaceRate
Diffstat (limited to 'script')
-rw-r--r-- | script/await.lua | 19 | ||||
-rw-r--r-- | script/core/diagnostics/init.lua | 6 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 54 |
3 files changed, 34 insertions, 45 deletions
diff --git a/script/await.lua b/script/await.lua index ff840956..4fdab0a2 100644 --- a/script/await.lua +++ b/script/await.lua @@ -10,7 +10,6 @@ m.coMap = setmetatable({}, wkmt) m.idMap = {} m.delayQueue = {} m.delayQueueIndex = 1 -m.watchList = {} m.needClose = {} m._enable = true @@ -162,9 +161,6 @@ function m.delay() end local co = coroutine.running() local current = m.coMap[co] - if m.onWatch('delay', co) == false then - return - end -- TODO if current.priority then return @@ -244,19 +240,4 @@ function m.disable() m._enable = false end ---- 注册事件 ----@param callback async fun(ev: string, ...) -function m.watch(callback) - m.watchList[#m.watchList+1] = callback -end - -function m.onWatch(ev, ...) - for _, callback in ipairs(m.watchList) do - local res = callback(ev, ...) - if res ~= nil then - return res - end - end -end - return m diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 50233559..4f5510c7 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -19,6 +19,9 @@ table.sort(diagList, function (a, b) return (diagSort[a] or 0) < (diagSort[b] or 0) end) +---@param uri uri +---@param name string +---@param response async fun(result: any) local function check(uri, name, response) if config.get(uri, 'Lua.diagnostics.disable')[name] then return @@ -40,6 +43,7 @@ local function check(uri, name, response) local severity = define.DiagnosticSeverity[level] local clock = os.clock() local mark = {} + ---@async require('core.diagnostics.' .. name)(uri, function (result) if vm.isDiagDisabledAt(uri, result.start, name) then return @@ -65,6 +69,8 @@ local function check(uri, name, response) end ---@async +---@param uri uri +---@param response async fun(result: any) return function (uri, response) local ast = files.getState(uri) if not ast then diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 031295db..09e1ea85 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -168,6 +168,28 @@ 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 @@ -236,12 +258,18 @@ function m.doDiagnostic(uri, isScopeDiag) pushResult() local lastPushClock = os.clock() + ---@async xpcall(core, log.error, uri, function (result) diags[#diags+1] = buildDiagnostic(uri, result) + if not isScopeDiag and os.clock() - lastPushClock >= 0.2 then lastPushClock = os.clock() pushResult() end + + if isScopeDiag then + checkSleep(uri) + end end) pushResult() @@ -354,32 +382,6 @@ function m.diagnosticsScope(uri, force) end, 'files.version', ('diagnosticsScope:' .. uri)) end ----@async -function m.checkWorkspaceDiag(uri) - if not await.hasID('diagnosticsScope:' .. uri) then - return - end - 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() - return false -end - ws.watch(function (ev, uri) if ev == 'reload' then m.diagnosticsScope(uri) |