diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-19 18:30:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-19 18:30:25 +0800 |
commit | eaa3c93756ab549f0184ebdb2d50c350d904bd70 (patch) | |
tree | b7da4269ec4c56e8d42679a5958984f7d8973b7a | |
parent | e0eef52ac0a819a1c211231f908072562c78caf0 (diff) | |
download | lua-language-server-eaa3c93756ab549f0184ebdb2d50c350d904bd70.zip |
诊断进行一下过滤,以免影响前端的性能
-rw-r--r-- | server-beta/src/files.lua | 22 | ||||
-rw-r--r-- | server-beta/src/provider/diagnostic.lua | 12 |
2 files changed, 33 insertions, 1 deletions
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua index 076c491b..34c8c2de 100644 --- a/server-beta/src/files.lua +++ b/server-beta/src/files.lua @@ -195,6 +195,28 @@ 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/provider/diagnostic.lua b/server-beta/src/provider/diagnostic.lua index 6583c8d8..df5fd419 100644 --- a/server-beta/src/provider/diagnostic.lua +++ b/server-beta/src/provider/diagnostic.lua @@ -144,10 +144,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) + end proto.notify('textDocument/publishDiagnostics', { uri = uri, - diagnostics = merge(syntax, diagnostics), + diagnostics = newDiag, }) end |