diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-03-01 19:51:49 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-03-01 19:51:49 +0800 |
commit | 268aee4c5e0851b9cd5a391569bec5371aa124eb (patch) | |
tree | 5eea638e16fb2ad637a346e1cbaf1c590c9e91a5 /script/cli | |
parent | 73c405b176ef9aa8468c6279fab883943def7ade (diff) | |
download | lua-language-server-268aee4c5e0851b9cd5a391569bec5371aa124eb.zip |
offline diagnostic
Diffstat (limited to 'script/cli')
-rw-r--r-- | script/cli/check.lua | 76 | ||||
-rw-r--r-- | script/cli/init.lua | 9 | ||||
-rw-r--r-- | script/cli/version.lua | 2 |
3 files changed, 87 insertions, 0 deletions
diff --git a/script/cli/check.lua b/script/cli/check.lua new file mode 100644 index 00000000..e5385c4e --- /dev/null +++ b/script/cli/check.lua @@ -0,0 +1,76 @@ +local lclient = require 'lclient' +local furi = require 'file-uri' +local ws = require 'workspace' +local files = require 'files' +local diag = require 'provider.diagnostic' +local util = require 'utility' +local json = require 'json-beautify' +local lang = require 'language' +local define = require 'proto.define' +local config = require 'config.config' + +if type(CHECK) ~= 'string' then + print(('The argument of CHECK must be a string, but got %s'):format(type(CHECK))) +end + +local rootUri = furi.encode(CHECK) +if not rootUri then + print(('The argument of CHECK must be a valid uri, but got %s'):format(CHECK)) +end + +util.enableCloseFunction() + +local lastClock = os.clock() +local results = {} +---@async +lclient():start(function (client) + client:registerFakers() + + client:initialize { + rootUri = rootUri, + } + + client:register('textDocument/publishDiagnostics', function (params) + results[params.uri] = params.diagnostics + end) + + ws.awaitReady(rootUri) + + local checkLevel = define.DiagnosticSeverity[CHECKLEVEL] or define.DiagnosticSeverity.Warning + local disables = config.get(rootUri, 'Lua.diagnostics.disable') + for name, serverity in pairs(define.DiagnosticDefaultSeverity) do + serverity = config.get(rootUri, 'Lua.diagnostics.severity')[name] or 'Warning' + if define.DiagnosticSeverity[serverity] > checkLevel then + disables[name] = true + end + end + config.set(nil, 'Lua.diagnostics.disable', disables) + + local uris = files.getAllUris(rootUri) + local max = #uris + for i, uri in ipairs(uris) do + files.open(uri) + diag.doDiagnostic(uri, true) + if os.clock() - lastClock > 0.2 then + lastClock = os.clock() + print(('%d/%d'):format(i, max)) + end + end +end) + +local count = 0 +for uri, result in pairs(results) do + count = count + #result + if #result == 0 then + results[uri] = nil + end +end + +if count == 0 then + print(lang.script('CLI_CHECK_SUCCESS')) +else + local outpath = LOGPATH .. '/check.json' + util.saveFile(outpath, json.beautify(results)) + + print(lang.script('CLI_CHECK_RESULTS', count, outpath)) +end diff --git a/script/cli/init.lua b/script/cli/init.lua new file mode 100644 index 00000000..c2fc7aa8 --- /dev/null +++ b/script/cli/init.lua @@ -0,0 +1,9 @@ +if _G['VERSION'] then + require 'cli.version' + os.exit(0, true) +end + +if _G['CHECK'] then + require 'cli.check' + os.exit(0, true) +end diff --git a/script/cli/version.lua b/script/cli/version.lua new file mode 100644 index 00000000..03926c28 --- /dev/null +++ b/script/cli/version.lua @@ -0,0 +1,2 @@ +local version = require 'version' +print(version.getVersion()) |