Skip to content

Commit 15a57e7

Browse files
authored
Merge pull request #3051 from lewis6991/feat/clipretty
feat: add --check_format=json|pretty
2 parents 06943cf + c1f10c2 commit 15a57e7

File tree

9 files changed

+266
-112
lines changed

9 files changed

+266
-112
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
cfgs[2] = {} -- only warns missing `b`
3232
```
3333
This enables the previous missing field check behavior before [#2970](https://github.com/LuaLS/lua-language-server/issues/2970)
34+
* `NEW` Added `--check_format=json|pretty` for use with `--check` to output diagnostics in a human readable format.
3435

3536
## 3.13.5
3637
`2024-12-20`

locale/en-us/script.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,10 @@ CLI_CHECK_SUCCESS =
648648
'Diagnosis completed, no problems found'
649649
CLI_CHECK_PROGRESS =
650650
'Found {} problems in {} files'
651-
CLI_CHECK_RESULTS =
651+
CLI_CHECK_RESULTS_OUTPATH =
652652
'Diagnosis complete, {} problems found, see {}'
653+
CLI_CHECK_RESULTS_PRETTY =
654+
'Diagnosis complete, {} problems found'
653655
CLI_CHECK_MULTIPLE_WORKERS =
654656
'Starting {} worker tasks, progress output will be disabled. This may take a few minutes.'
655657
CLI_DOC_INITING =

locale/ja-jp/script.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,10 @@ CLI_CHECK_SUCCESS =
649649
'診断が完了しました。問題は見つかりませんでした'
650650
CLI_CHECK_PROGRESS =
651651
'{} ファイルに渡り、{} 個の問題が発見されました'
652-
CLI_CHECK_RESULTS =
652+
CLI_CHECK_RESULTS_OUTPATH =
653653
'診断が完了しました。{} 個の問題が発見されました。詳しくは {} をご確認ください'
654+
CLI_CHECK_RESULTS_PRETTY =
655+
'診断が完了しました。{} 個の問題が発見されました'
654656
CLI_CHECK_MULTIPLE_WORKERS =
655657
'{} 個のワーカータスクを開始しているため、進行状況の出力が無効になります。完了まで数分かかることがあります。'
656658
CLI_DOC_INITING =

locale/pt-br/script.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,10 @@ CLI_CHECK_SUCCESS =
648648
'Diagnóstico completo, nenhum problema encontrado'
649649
CLI_CHECK_PROGRESS = -- TODO: need translate!
650650
'Found {} problems in {} files'
651-
CLI_CHECK_RESULTS =
651+
CLI_CHECK_RESULTS_OUTPATH =
652652
'Diagnóstico completo, {} problemas encontrados, veja {}'
653+
CLI_CHECK_RESULTS_PRETTY =
654+
'Diagnóstico completo, {} problemas encontrados'
653655
CLI_CHECK_MULTIPLE_WORKERS = -- TODO: need translate!
654656
'Starting {} worker tasks, progress output will be disabled. This may take a few minutes.'
655657
CLI_DOC_INITING = -- TODO: need translate!

locale/zh-cn/script.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,10 @@ CLI_CHECK_SUCCESS =
648648
'诊断完成,没有发现问题'
649649
CLI_CHECK_PROGRESS =
650650
'检测到问题 {} 在文件 {} 中'
651-
CLI_CHECK_RESULTS =
651+
CLI_CHECK_RESULTS_OUTPATH =
652652
'诊断完成,共有 {} 个问题,请查看 {}'
653+
CLI_CHECK_RESULTS_PRETTY =
654+
'诊断完成,共有 {} 个问题'
653655
CLI_CHECK_MULTIPLE_WORKERS =
654656
'开启 {} 个工作任务,进度输出将会被禁用。这可能会花费几分钟。'
655657
CLI_DOC_INITING =

locale/zh-tw/script.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,10 @@ CLI_CHECK_SUCCESS =
648648
'診斷完成,沒有發現問題'
649649
CLI_CHECK_PROGRESS = -- TODO: need translate!
650650
'Found {} problems in {} files'
651-
CLI_CHECK_RESULTS =
651+
CLI_CHECK_RESULTS_OUTPATH =
652652
'診斷完成,共有 {} 個問題,請查看 {}'
653+
CLI_CHECK_RESULTS_PRETTY =
654+
'診斷完成,共有 {} 個問題'
653655
CLI_CHECK_MULTIPLE_WORKERS = -- TODO: need translate!
654656
'Starting {} worker tasks, progress output will be disabled. This may take a few minutes.'
655657
CLI_DOC_INITING = -- TODO: need translate!

script/cli/check.lua

+58-47
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,46 @@ local util = require 'utility'
77

88
local export = {}
99

10+
local function logFileForThread(threadId)
11+
return LOGPATH .. '/check-partial-' .. threadId .. '.json'
12+
end
13+
14+
local function buildArgs(exe, numThreads, threadId, format, quiet)
15+
local args = {exe}
16+
local skipNext = false
17+
for i = 1, #arg do
18+
local arg = arg[i]
19+
-- --check needs to be transformed into --check_worker
20+
if arg:lower():match('^%-%-check$') or arg:lower():match('^%-%-check=') then
21+
args[#args + 1] = arg:gsub('%-%-%w*', '--check_worker')
22+
-- --check_out_path needs to be removed if we have more than one thread
23+
elseif arg:lower():match('%-%-check_out_path') and numThreads > 1 then
24+
if not arg:match('%-%-%w*=') then
25+
skipNext = true
26+
end
27+
else
28+
if skipNext then
29+
skipNext = false
30+
else
31+
args[#args + 1] = arg
32+
end
33+
end
34+
end
35+
args[#args + 1] = '--thread_id'
36+
args[#args + 1] = tostring(threadId)
37+
if numThreads > 1 then
38+
if quiet then
39+
args[#args + 1] = '--quiet'
40+
end
41+
if format then
42+
args[#args + 1] = '--check_format=' .. format
43+
end
44+
args[#args + 1] = '--check_out_path'
45+
args[#args + 1] = logFileForThread(threadId)
46+
end
47+
return args
48+
end
49+
1050
function export.runCLI()
1151
local numThreads = tonumber(NUM_THREADS or 1)
1252

@@ -21,48 +61,13 @@ function export.runCLI()
2161
exe = exe..'.exe'
2262
end
2363

24-
local function logFileForThread(threadId)
25-
return LOGPATH .. '/check-partial-' .. threadId .. '.json'
26-
end
27-
28-
local function buildArgs(threadId)
29-
local args = {exe}
30-
local skipNext = false
31-
for i = 1, #arg do
32-
local arg = arg[i]
33-
-- --check needs to be transformed into --check_worker
34-
if arg:lower():match('^%-%-check$') or arg:lower():match('^%-%-check=') then
35-
args[#args + 1] = arg:gsub('%-%-%w*', '--check_worker')
36-
-- --check_out_path needs to be removed if we have more than one thread
37-
elseif arg:lower():match('%-%-check_out_path') and numThreads > 1 then
38-
if not arg:match('%-%-%w*=') then
39-
skipNext = true
40-
end
41-
else
42-
if skipNext then
43-
skipNext = false
44-
else
45-
args[#args + 1] = arg
46-
end
47-
end
48-
end
49-
args[#args + 1] = '--thread_id'
50-
args[#args + 1] = tostring(threadId)
51-
if numThreads > 1 then
52-
args[#args + 1] = '--quiet'
53-
args[#args + 1] = '--check_out_path'
54-
args[#args + 1] = logFileForThread(threadId)
55-
end
56-
return args
57-
end
58-
59-
if numThreads > 1 then
64+
if not QUIET and numThreads > 1 then
6065
print(lang.script('CLI_CHECK_MULTIPLE_WORKERS', numThreads))
6166
end
6267

6368
local procs = {}
6469
for i = 1, numThreads do
65-
local process, err = subprocess.spawn({buildArgs(i)})
70+
local process, err = subprocess.spawn({buildArgs(exe, numThreads, i, CHECK_FORMAT, QUIET)})
6671
if err then
6772
print(err)
6873
end
@@ -76,11 +81,6 @@ function export.runCLI()
7681
checkPassed = process:wait() == 0 and checkPassed
7782
end
7883

79-
local outpath = CHECK_OUT_PATH
80-
if outpath == nil then
81-
outpath = LOGPATH .. '/check.json'
82-
end
83-
8484
if numThreads > 1 then
8585
local mergedResults = {}
8686
local count = 0
@@ -95,11 +95,22 @@ function export.runCLI()
9595
end
9696
end
9797
end
98-
util.saveFile(outpath, jsonb.beautify(mergedResults))
99-
if count == 0 then
100-
print(lang.script('CLI_CHECK_SUCCESS'))
101-
else
102-
print(lang.script('CLI_CHECK_RESULTS', count, outpath))
98+
99+
local outpath = nil
100+
101+
if CHECK_FORMAT == 'json' or CHECK_OUT_PATH then
102+
outpath = CHECK_OUT_PATH or LOGPATH .. '/check.json'
103+
util.saveFile(outpath, jsonb.beautify(mergedResults))
104+
end
105+
106+
if not QUIET then
107+
if count == 0 then
108+
print(lang.script('CLI_CHECK_SUCCESS'))
109+
elseif outpath then
110+
print(lang.script('CLI_CHECK_RESULTS_OUTPATH', count, outpath))
111+
else
112+
print(lang.script('CLI_CHECK_RESULTS_PRETTY', count))
113+
end
103114
end
104115
end
105116
return checkPassed and 0 or 1

0 commit comments

Comments
 (0)