diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 16:46:08 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 16:46:08 +0800 |
commit | c9b94234048a9608a732e85251757d02fcf19c8a (patch) | |
tree | dc95e70c233ab72e46e8bcb1fe7b9d8f6731886e | |
parent | 2877f084943ba30a9970cbe9a5cb0be844a2ec64 (diff) | |
download | lua-language-server-c9b94234048a9608a732e85251757d02fcf19c8a.zip |
cleanup
-rw-r--r-- | script/core/diagnostics/init.lua | 8 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 53 | ||||
-rw-r--r-- | test/crossfile/diagnostic.lua | 18 | ||||
-rw-r--r-- | test/diagnostics/init.lua | 12 | ||||
-rw-r--r-- | test/full/projects.lua | 2 | ||||
-rw-r--r-- | test/full/self.lua | 2 |
6 files changed, 18 insertions, 77 deletions
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 4e2a4976..50233559 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -19,7 +19,7 @@ table.sort(diagList, function (a, b) return (diagSort[a] or 0) < (diagSort[b] or 0) end) -local function check(uri, name, results) +local function check(uri, name, response) if config.get(uri, 'Lua.diagnostics.disable')[name] then return end @@ -53,7 +53,7 @@ local function check(uri, name, results) mark[result.start] = true result.level = severity or result.level result.code = name - results[#results+1] = result + response(result) end, name) local passed = os.clock() - clock if passed >= 0.5 then @@ -77,8 +77,6 @@ return function (uri, response) for _, name in ipairs(diagList) do await.delay() - local results = {} - check(uri, name, results) - response(results) + check(uri, name, response) end end diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 3b99b6b0..30b9cd2f 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -15,7 +15,6 @@ local converter = require 'proto.converter' local m = {} m.cache = {} m.sleepRest = 0.0 -m.coroutineUri = setmetatable({}, { __mode = 'k' }) local function concat(t, sep) if type(t) ~= 'table' then @@ -173,18 +172,13 @@ function m.diagnostics(uri, diags) return end - xpcall(core, log.error, uri, function (results) - if #results == 0 then - return - end - for i = 1, #results do - diags[#diags+1] = buildDiagnostic(uri, results[i]) - end + xpcall(core, log.error, uri, function (result) + diags[#diags+1] = buildDiagnostic(uri, result) end) end ---@async -function m.doDiagnostic(uri) +function m.doDiagnostic(uri, isScopeDiag) if not config.get(uri, 'Lua.diagnostics.enable') then return end @@ -249,25 +243,8 @@ function m.doDiagnostic(uri) end end - m.coroutineUri[coroutine.running()] = uri - - if await.hasID('diagnosticsScope:' .. scp.uri) then - scp:set('diagStepPush', nil) - else - local clock = os.clock() - scp:set('diagStepPush', function () - if os.clock() - clock >= 0.2 then - pushResult() - clock = os.clock() - end - end) - end - m.diagnostics(uri, diags) - await.sleep(1.0) - await.sleep(1.0) pushResult() - scp:set('diagStepPush', nil) end function m.refresh(uri) @@ -365,7 +342,7 @@ function m.diagnosticsScope(uri, force) for i, uri in ipairs(uris) do bar:setMessage(('%d/%d'):format(i, #uris)) bar:setPercentage(i / #uris * 100) - xpcall(m.doDiagnostic, log.error, uri) + xpcall(m.doDiagnostic, log.error, uri, true) await.delay() if cancelled then log.debug('Break workspace diagnostics') @@ -377,17 +354,6 @@ function m.diagnosticsScope(uri, force) end, 'files.version', ('diagnosticsScope:' .. uri)) end -function m.checkStepResult(uri) - local scp = ws.getScope(uri) - if await.hasID('diagnosticsScope:' .. scp.uri) then - return - end - local stepPush = scp:get 'diagStepPush' - if stepPush then - stepPush() - end -end - ---@async function m.checkWorkspaceDiag(uri) if not await.hasID('diagnosticsScope:' .. uri) then @@ -440,17 +406,6 @@ files.watch(function (ev, uri) ---@async end end) -await.watch(function (ev, co) ---@async - if ev == 'delay' then - local uri = m.coroutineUri[co] - if not uri then - return - end - m.checkStepResult(uri) - return m.checkWorkspaceDiag(uri) - end -end) - config.watch(function (uri, key, value, oldValue) if key:find 'Lua.diagnostics' then if value ~= oldValue then diff --git a/test/crossfile/diagnostic.lua b/test/crossfile/diagnostic.lua index ab2c3e41..0a32ddb0 100644 --- a/test/crossfile/diagnostic.lua +++ b/test/crossfile/diagnostic.lua @@ -53,24 +53,18 @@ function TEST(datas) end - local result = {} + local results = {} for _, data in ipairs(datas) do local uri = furi.encode(data.path) - local results = {} core(uri, function (result) - for _, res in ipairs(result) do - results[#results+1] = res - end - end) - for i, position in ipairs(results) do - result[i] = { - position.start, - position.finish, + results[#results+1] = { + result.start, + result.finish, uri, } - end + end) end - assert(founded(targetList, result)) + assert(founded(targetList, results)) end TEST { diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 2821dc1b..e20c129c 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -31,16 +31,10 @@ function TEST(script, ...) local newScript, catched = catch(script, '!') files.setText('', newScript) files.open('') - local datas = {} - core('', function (results) - for _, res in ipairs(results) do - datas[#datas+1] = res - end - end) local results = {} - for i, data in ipairs(datas) do - results[i] = { data.start, data.finish } - end + core('', function (result) + results[#results+1] = { result.start, result.finish } + end) if results[1] then if not founded(catched['!'] or {}, results) then diff --git a/test/full/projects.lua b/test/full/projects.lua index 9531d01b..dedb42e5 100644 --- a/test/full/projects.lua +++ b/test/full/projects.lua @@ -48,7 +48,7 @@ local function doProjects(pathname) for uri in files.eachFile() do local fileClock = os.clock() - diag.doDiagnostic(uri) + diag.doDiagnostic(uri, true) print('诊断文件耗时:', os.clock() - fileClock, uri) end diff --git a/test/full/self.lua b/test/full/self.lua index d0e74a80..5fb1fc7a 100644 --- a/test/full/self.lua +++ b/test/full/self.lua @@ -36,7 +36,7 @@ local clock = os.clock() ---@diagnostic disable: await-in-sync for uri in files.eachFile() do local fileClock = os.clock() - diag.doDiagnostic(uri) + diag.doDiagnostic(uri, true) print('诊断文件耗时:', os.clock() - fileClock, uri) end |