Skip to content

Commit 75cd0a7

Browse files
committed
fixup! report pretty as soon as results are available
1 parent 74425be commit 75cd0a7

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

script/cli/check_worker.lua

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,48 +55,51 @@ local severity_str = {
5555
[4] = 'hint'
5656
}
5757

58-
local function report_pretty(results)
59-
for f, diags in pairs(results) do
60-
local path = furi.relpath(furi.decode(f))
61-
62-
local lines = {} --- @type string[]
63-
pcall(function()
64-
for line in io.lines(path) do
65-
table.insert(lines, line)
66-
end
67-
end)
58+
local function report_pretty(uri, diags)
59+
local path = furi.relpath(furi.decode(uri))
60+
61+
local lines = {} --- @type string[]
62+
pcall(function()
63+
for line in io.lines(path) do
64+
table.insert(lines, line)
65+
end
66+
end)
6867

69-
for _, d in ipairs(diags) do
70-
local rstart = d.range.start
71-
local rend = d.range['end']
72-
print(
73-
('%s%s:%s:%s%s [%s%s%s] %s %s(%s)%s'):format(
74-
colors.blue,
75-
path,
76-
rstart.line,
77-
rstart.character,
78-
colors.reset,
79-
severity_colors[d.severity],
80-
severity_str[d.severity],
81-
colors.reset,
82-
d.message,
83-
colors.magenta,
84-
d.code,
85-
colors.reset
86-
)
68+
for _, d in ipairs(diags) do
69+
local rstart = d.range.start
70+
local rend = d.range['end']
71+
print(
72+
('%s%s:%s:%s%s [%s%s%s] %s %s(%s)%s'):format(
73+
colors.blue,
74+
path,
75+
rstart.line,
76+
rstart.character,
77+
colors.reset,
78+
severity_colors[d.severity],
79+
severity_str[d.severity],
80+
colors.reset,
81+
d.message,
82+
colors.magenta,
83+
d.code,
84+
colors.reset
8785
)
88-
if #lines > 0 then
89-
io.write(' ', lines[rstart.line + 1], '\n')
90-
io.write(' ', colors.grey, (' '):rep(rstart.character), '^')
91-
if rstart.line == rend.line then
92-
io.write(('^'):rep(rend.character - rstart.character - 1))
93-
end
94-
io.write(colors.reset, '\n')
86+
)
87+
if #lines > 0 then
88+
io.write(' ', lines[rstart.line + 1], '\n')
89+
io.write(' ', colors.grey, (' '):rep(rstart.character), '^')
90+
if rstart.line == rend.line then
91+
io.write(('^'):rep(rend.character - rstart.character - 1))
9592
end
93+
io.write(colors.reset, '\n')
9694
end
9795
end
9896
end
9997

98+
local function clear_line()
99+
-- Write out empty space to ensure that the previous lien is cleared.
100+
io.write('\x0D', (' '):rep(80), '\x0D')
101+
end
102+
100103
function export.runCLI()
101104
lang(LOCALE)
102105

@@ -145,6 +148,10 @@ function export.runCLI()
145148

146149
client:register('textDocument/publishDiagnostics', function (params)
147150
results[params.uri] = params.diagnostics
151+
if not QUIET and (CHECK_FORMAT == nil or CHECK_FORMAT == 'pretty') then
152+
clear_line()
153+
report_pretty(params.uri, params.diagnostics)
154+
end
148155
end)
149156

150157
if not QUIET then
@@ -214,8 +221,7 @@ function export.runCLI()
214221
end
215222
end
216223
if not QUIET then
217-
-- Write out empty space to ensure that the progress bar is cleared.
218-
io.write('\x0D', (' '):rep(80), '\x0D')
224+
clear_line()
219225
end
220226
end)
221227

@@ -229,10 +235,6 @@ function export.runCLI()
229235

230236
local outpath = nil
231237

232-
if CHECK_FORMAT == nil or CHECK_FORMAT == 'pretty' then
233-
report_pretty(results)
234-
end
235-
236238
if CHECK_FORMAT == 'json' or CHECK_OUT_PATH then
237239
outpath = CHECK_OUT_PATH or LOGPATH .. '/check.json'
238240
-- Always write result, even if it's empty to make sure no one accidentally looks at an old output after a successful run.

0 commit comments

Comments
 (0)