diff options
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/core/diagnostics/init.lua | 4 | ||||
-rw-r--r-- | server-beta/src/files.lua | 23 | ||||
-rw-r--r-- | server-beta/src/proto/proto.lua | 4 | ||||
-rw-r--r-- | server-beta/src/provider/diagnostic.lua | 40 | ||||
-rw-r--r-- | server-beta/test/diagnostics/init.lua | 2 |
5 files changed, 36 insertions, 37 deletions
diff --git a/server-beta/src/core/diagnostics/init.lua b/server-beta/src/core/diagnostics/init.lua index c5abff25..0d523f26 100644 --- a/server-beta/src/core/diagnostics/init.lua +++ b/server-beta/src/core/diagnostics/init.lua @@ -33,5 +33,9 @@ return function (uri) check(uri, name, level, results) end + if #results == 0 then + return nil + end + return results end diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua index 34cba439..ac27117c 100644 --- a/server-beta/src/files.lua +++ b/server-beta/src/files.lua @@ -127,6 +127,7 @@ function m.remove(uri) local diagnostic = require 'service.diagnostic' diagnostic.refresh(file.uri) + diagnostic.clear(file.uri) end --- 移除所有文件 @@ -195,28 +196,6 @@ function m.getOriginUri(uri) return file.uri end -function m.setDiagnostic(uri, diag) - if platform.OS == 'Windows' then - uri = uri:lower() - end - local file = m.fileMap[uri] - if not file then - return - end - file._diag = diag -end - -function m.getDiagnostic(uri) - if platform.OS == 'Windows' then - uri = uri:lower() - end - local file = m.fileMap[uri] - if not file then - return nil - end - return file._diag -end - --- 寻找全局变量 function m.findGlobals(name) local uris = {} diff --git a/server-beta/src/proto/proto.lua b/server-beta/src/proto/proto.lua index 1d8160c1..e12631aa 100644 --- a/server-beta/src/proto/proto.lua +++ b/server-beta/src/proto/proto.lua @@ -30,6 +30,7 @@ function m.response(id, res) data.id = id data.result = res local buf = jsonrpc.encode(data) + log.debug('Response', id, #buf) io.stdout:write(buf) end @@ -41,6 +42,7 @@ function m.responseErr(id, code, message) message = message, } } + log.debug('ResponseErr', id, #buf) io.stdout:write(buf) end @@ -49,6 +51,7 @@ function m.notify(name, params) method = name, params = params, } + log.debug('Notify', name, #buf) io.stdout:write(buf) end @@ -59,6 +62,7 @@ function m.awaitRequest(name, params) method = name, params = params, } + log.debug('Request', name, #buf) io.stdout:write(buf) return await.wait(function (waker) m.waiting[id] = waker diff --git a/server-beta/src/provider/diagnostic.lua b/server-beta/src/provider/diagnostic.lua index df5fd419..ba95f2bf 100644 --- a/server-beta/src/provider/diagnostic.lua +++ b/server-beta/src/provider/diagnostic.lua @@ -5,6 +5,7 @@ local lang = require 'language' local files = require 'files' local config = require 'config' local core = require 'core.diagnostics' +local util = require 'utility' local m = {} m._start = false @@ -86,6 +87,9 @@ local function buildDiagnostic(uri, diag) end local function merge(a, b) + if not a and not b then + return nil + end local t = {} if a then for i = 1, #a do @@ -101,6 +105,9 @@ local function merge(a, b) end function m.clear(uri) + if not m.cache[uri] then + return + end m.cache[uri] = nil proto.notify('textDocument/publishDiagnostics', { uri = uri, @@ -109,6 +116,10 @@ function m.clear(uri) end function m.syntaxErrors(uri, ast) + if #ast.errs == 0 then + return nil + end + local results = {} for _, err in ipairs(ast.errs) do @@ -123,15 +134,16 @@ function m.diagnostics(uri, syntaxOnly) return m.cache[uri] end - local results = {} - local diags = core(uri) + if not diags then + return nil + end + + local results = {} for _, diag in ipairs(diags) do results[#results+1] = buildDiagnostic(uri, diag) end - m.cache[uri] = results - return results end @@ -144,20 +156,20 @@ function m.doDiagnostic(uri, syntaxOnly) local syntax = m.syntaxErrors(uri, ast) local diagnostics = m.diagnostics(uri, syntaxOnly) - local newDiag = merge(syntax, diagnostics) - local lastDiag = files.getDiagnostic(uri) - if #newDiag == 0 then - if not lastDiag then - return - end - files.setDiagnostic(uri, nil) - else - files.setDiagnostic(uri, newDiag) + local full = merge(syntax, diagnostics) + if not full then + m.clear(uri) + return + end + + if util.equal(m.cache[uri], full) then + return end + m.cache[uri] = full proto.notify('textDocument/publishDiagnostics', { uri = uri, - diagnostics = newDiag, + diagnostics = full, }) end diff --git a/server-beta/test/diagnostics/init.lua b/server-beta/test/diagnostics/init.lua index 35b46c77..0a38bce9 100644 --- a/server-beta/test/diagnostics/init.lua +++ b/server-beta/test/diagnostics/init.lua @@ -50,7 +50,7 @@ function TEST(script, ...) files.removeAll() local new_script, target = catch_target(script, ...) files.setText('', new_script) - local datas = core('') + local datas = core('') or {} local results = {} for i, data in ipairs(datas) do results[i] = { data.start, data.finish } |