Skip to content

Commit 268aee4

Browse files
committed
offline diagnostic
1 parent 73c405b commit 268aee4

File tree

15 files changed

+174
-49
lines changed

15 files changed

+174
-49
lines changed

.vscode/launch.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
},
2323
{
24-
"name": "attach",
24+
"name": "🪡attach",
2525
"type": "lua",
2626
"request": "attach",
2727
"stopOnEntry": false,
@@ -36,7 +36,7 @@
3636
]
3737
},
3838
{
39-
"name": "build-3rd-meta",
39+
"name": "🍉build-3rd-meta",
4040
"type": "lua",
4141
"request": "launch",
4242
"stopOnEntry": false,
@@ -53,5 +53,25 @@
5353
"stderr",
5454
],
5555
},
56+
{
57+
"name": "🍖cli-check",
58+
"type": "lua",
59+
"request": "launch",
60+
"stopOnEntry": false,
61+
"program": "${workspaceRoot}/main.lua",
62+
"luaexe": "${workspaceFolder}/bin/lua-language-server.exe",
63+
"cpath": null,
64+
"arg": [
65+
"--check",
66+
"${workspaceRoot}",
67+
],
68+
"luaVersion": "5.4",
69+
"consoleCoding": "utf8",
70+
"sourceCoding": "utf8",
71+
"outputCapture": [
72+
"print",
73+
"stderr",
74+
],
75+
},
5676
]
5777
}

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# changelog
22

33
## 2.6.7
4+
* `NEW` offline diagnostic, [read more](https://github.com/sumneko/lua-language-server/wiki/Offline-Diagnostic)
45
* `FIX` [#965](https://github.com/sumneko/lua-language-server/issues/965)
56

67
## 2.6.6

locale/en-us/script.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,8 @@ PLUGIN_TRUST_NO =
511511
[[
512512
Don't load this plugin
513513
]]
514+
515+
CLI_CHECK_SUCCESS =
516+
'Diagnosis completed, no problems found'
517+
CLI_CHECK_RESULTS =
518+
'Diagnosis complete, {} problems found, see {}'

locale/zh-cn/script.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,8 @@ PLUGIN_TRUST_NO =
510510
[[
511511
不要加载此插件
512512
]]
513+
514+
CLI_CHECK_SUCCESS =
515+
'诊断完成,没有发现问题'
516+
CLI_CHECK_RESULTS =
517+
'诊断完成,共有 {} 个问题,请查看 {}'

main.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ log.debug('LOGPATH:', LOGPATH)
6464
log.debug('METAPATH:', METAPATH)
6565
log.debug('VERSION:', version.getVersion())
6666

67-
require 'ci'
68-
6967
require 'tracy'
68+
require 'cli'
7069

7170
xpcall(dofile, log.debug, (ROOT / 'debugger.lua'):string())
7271

script/ci/check.lua

Lines changed: 0 additions & 1 deletion
This file was deleted.

script/cli/check.lua

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
local lclient = require 'lclient'
2+
local furi = require 'file-uri'
3+
local ws = require 'workspace'
4+
local files = require 'files'
5+
local diag = require 'provider.diagnostic'
6+
local util = require 'utility'
7+
local json = require 'json-beautify'
8+
local lang = require 'language'
9+
local define = require 'proto.define'
10+
local config = require 'config.config'
11+
12+
if type(CHECK) ~= 'string' then
13+
print(('The argument of CHECK must be a string, but got %s'):format(type(CHECK)))
14+
end
15+
16+
local rootUri = furi.encode(CHECK)
17+
if not rootUri then
18+
print(('The argument of CHECK must be a valid uri, but got %s'):format(CHECK))
19+
end
20+
21+
util.enableCloseFunction()
22+
23+
local lastClock = os.clock()
24+
local results = {}
25+
---@async
26+
lclient():start(function (client)
27+
client:registerFakers()
28+
29+
client:initialize {
30+
rootUri = rootUri,
31+
}
32+
33+
client:register('textDocument/publishDiagnostics', function (params)
34+
results[params.uri] = params.diagnostics
35+
end)
36+
37+
ws.awaitReady(rootUri)
38+
39+
local checkLevel = define.DiagnosticSeverity[CHECKLEVEL] or define.DiagnosticSeverity.Warning
40+
local disables = config.get(rootUri, 'Lua.diagnostics.disable')
41+
for name, serverity in pairs(define.DiagnosticDefaultSeverity) do
42+
serverity = config.get(rootUri, 'Lua.diagnostics.severity')[name] or 'Warning'
43+
if define.DiagnosticSeverity[serverity] > checkLevel then
44+
disables[name] = true
45+
end
46+
end
47+
config.set(nil, 'Lua.diagnostics.disable', disables)
48+
49+
local uris = files.getAllUris(rootUri)
50+
local max = #uris
51+
for i, uri in ipairs(uris) do
52+
files.open(uri)
53+
diag.doDiagnostic(uri, true)
54+
if os.clock() - lastClock > 0.2 then
55+
lastClock = os.clock()
56+
print(('%d/%d'):format(i, max))
57+
end
58+
end
59+
end)
60+
61+
local count = 0
62+
for uri, result in pairs(results) do
63+
count = count + #result
64+
if #result == 0 then
65+
results[uri] = nil
66+
end
67+
end
68+
69+
if count == 0 then
70+
print(lang.script('CLI_CHECK_SUCCESS'))
71+
else
72+
local outpath = LOGPATH .. '/check.json'
73+
util.saveFile(outpath, json.beautify(results))
74+
75+
print(lang.script('CLI_CHECK_RESULTS', count, outpath))
76+
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
if _G['VERSION'] then
2-
require 'ci.version'
2+
require 'cli.version'
33
os.exit(0, true)
44
end
55

66
if _G['CHECK'] then
7-
require 'ci.check'
7+
require 'cli.check'
88
os.exit(0, true)
99
end

script/client.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ function m.isReady()
389389
end
390390

391391
local function hookPrint()
392-
if TEST then
392+
if TEST or CLI then
393393
return
394394
end
395395
print = function (...)

0 commit comments

Comments
 (0)