@@ -17,6 +17,70 @@ require 'vm'
17
17
18
18
local export = {}
19
19
20
+ local function clear_line ()
21
+ -- Write out empty space to ensure that the previous lien is cleared.
22
+ io.write (' \x0D ' , (' ' ):rep (80 ), ' \x0D ' )
23
+ end
24
+
25
+ --- @param i integer
26
+ --- @param max integer
27
+ --- @param results table<string , table[]>
28
+ local function report_progress (i , max , results )
29
+ local filesWithErrors = 0
30
+ local errors = 0
31
+ for _ , diags in pairs (results ) do
32
+ filesWithErrors = filesWithErrors + 1
33
+ errors = errors + # diags
34
+ end
35
+
36
+ clear_line ()
37
+ io.write (
38
+ (' >' ):rep (math.ceil (i / max * 20 )),
39
+ (' =' ):rep (20 - math.ceil (i / max * 20 )),
40
+ ' ' ,
41
+ (' 0' ):rep (# tostring (max ) - # tostring (i )),
42
+ tostring (i ),
43
+ ' /' ,
44
+ tostring (max )
45
+ )
46
+ if errors > 0 then
47
+ io.write (' [' , lang .script (' CLI_CHECK_PROGRESS' , errors , filesWithErrors ), ' ]' )
48
+ end
49
+ io.flush ()
50
+ end
51
+
52
+ --- @param uri string
53
+ --- @param checkLevel integer
54
+ local function apply_check_level (uri , checkLevel )
55
+ local config_disables = util .arrayToHash (config .get (uri , ' Lua.diagnostics.disable' ))
56
+ local config_severities = config .get (uri , ' Lua.diagnostics.severity' )
57
+ for name , serverity in pairs (define .DiagnosticDefaultSeverity ) do
58
+ serverity = config_severities [name ] or serverity
59
+ if serverity :sub (- 1 ) == ' !' then
60
+ serverity = serverity :sub (1 , - 2 )
61
+ end
62
+ if define .DiagnosticSeverity [serverity ] > checkLevel then
63
+ config_disables [name ] = true
64
+ end
65
+ end
66
+ config .set (uri , ' Lua.diagnostics.disable' , util .getTableKeys (config_disables , true ))
67
+ end
68
+
69
+ local function downgrade_checks_to_opened (uri )
70
+ local diagStatus = config .get (uri , ' Lua.diagnostics.neededFileStatus' )
71
+ for d , status in pairs (diagStatus ) do
72
+ if status == ' Any' or status == ' Any!' then
73
+ diagStatus [d ] = ' Opened!'
74
+ end
75
+ end
76
+ for d , status in pairs (protoDiag .getDefaultStatus ()) do
77
+ if status == ' Any' or status == ' Any!' then
78
+ diagStatus [d ] = ' Opened!'
79
+ end
80
+ end
81
+ config .set (uri , ' Lua.diagnostics.neededFileStatus' , diagStatus )
82
+ end
83
+
20
84
function export .runCLI ()
21
85
lang (LOCALE )
22
86
@@ -36,18 +100,16 @@ function export.runCLI()
36
100
end
37
101
rootUri = rootUri :gsub (" /$" , " " )
38
102
39
- if CHECKLEVEL then
40
- if not define .DiagnosticSeverity [CHECKLEVEL ] then
41
- print (lang .script (' CLI_CHECK_ERROR_LEVEL' , ' Error, Warning, Information, Hint' ))
42
- return
43
- end
103
+ if CHECKLEVEL and not define .DiagnosticSeverity [CHECKLEVEL ] then
104
+ print (lang .script (' CLI_CHECK_ERROR_LEVEL' , ' Error, Warning, Information, Hint' ))
105
+ return
44
106
end
45
107
local checkLevel = define .DiagnosticSeverity [CHECKLEVEL ] or define .DiagnosticSeverity .Warning
46
108
47
109
util .enableCloseFunction ()
48
110
49
111
local lastClock = os.clock ()
50
- local results = {}
112
+ local results = {} --- @type table<string , table[]>
51
113
52
114
local function errorhandler (err )
53
115
print (err )
@@ -75,31 +137,12 @@ function export.runCLI()
75
137
76
138
ws .awaitReady (rootUri )
77
139
78
- local disables = util .arrayToHash (config .get (rootUri , ' Lua.diagnostics.disable' ))
79
- for name , serverity in pairs (define .DiagnosticDefaultSeverity ) do
80
- serverity = config .get (rootUri , ' Lua.diagnostics.severity' )[name ] or serverity
81
- if serverity :sub (- 1 ) == ' !' then
82
- serverity = serverity :sub (1 , - 2 )
83
- end
84
- if define .DiagnosticSeverity [serverity ] > checkLevel then
85
- disables [name ] = true
86
- end
87
- end
88
- config .set (rootUri , ' Lua.diagnostics.disable' , util .getTableKeys (disables , true ))
140
+ -- Disable any diagnostics that are above the check level
141
+ apply_check_level (rootUri , checkLevel )
89
142
90
- -- Downgrade file opened status to Opened for everything to avoid reporting during compilation on files that do not belong to this thread
91
- local diagStatus = config .get (rootUri , ' Lua.diagnostics.neededFileStatus' )
92
- for diag , status in pairs (diagStatus ) do
93
- if status == ' Any' or status == ' Any!' then
94
- diagStatus [diag ] = ' Opened!'
95
- end
96
- end
97
- for diag , status in pairs (protoDiag .getDefaultStatus ()) do
98
- if status == ' Any' or status == ' Any!' then
99
- diagStatus [diag ] = ' Opened!'
100
- end
101
- end
102
- config .set (rootUri , ' Lua.diagnostics.neededFileStatus' , diagStatus )
143
+ -- Downgrade file opened status to Opened for everything to avoid
144
+ -- reporting during compilation on files that do not belong to this thread
145
+ downgrade_checks_to_opened (rootUri )
103
146
104
147
local uris = files .getChildFiles (rootUri )
105
148
local max = # uris
@@ -108,28 +151,12 @@ function export.runCLI()
108
151
if (i % numThreads + 1 ) == threadId then
109
152
files .open (uri )
110
153
diag .doDiagnostic (uri , true )
111
- -- Print regularly but always print the last entry to ensure that logs written to files don't look incomplete.
112
- if (os.clock () - lastClock > 0.2 or i == # uris ) and not QUIET then
154
+ -- Print regularly but always print the last entry to ensure
155
+ -- that logs written to files don't look incomplete.
156
+ if not QUIET and (os.clock () - lastClock > 0.2 or i == # uris ) then
113
157
lastClock = os.clock ()
114
158
client :update ()
115
- local output = ' \x0D '
116
- .. (' >' ):rep (math.ceil (i / max * 20 ))
117
- .. (' =' ):rep (20 - math.ceil (i / max * 20 ))
118
- .. ' '
119
- .. (' 0' ):rep (# tostring (max ) - # tostring (i ))
120
- .. tostring (i ) .. ' /' .. tostring (max )
121
- io.write (output )
122
- local filesWithErrors = 0
123
- local errors = 0
124
- for _ , diags in pairs (results ) do
125
- filesWithErrors = filesWithErrors + 1
126
- errors = errors + # diags
127
- end
128
- if errors > 0 then
129
- local errorDetails = ' [' .. lang .script (' CLI_CHECK_PROGRESS' , errors , filesWithErrors ) .. ' ]'
130
- io.write (errorDetails )
131
- end
132
- io.flush ()
159
+ report_progress (i , max , results )
133
160
end
134
161
end
135
162
end
@@ -146,10 +173,8 @@ function export.runCLI()
146
173
end
147
174
end
148
175
149
- local outpath = CHECK_OUT_PATH
150
- if outpath == nil then
151
- outpath = LOGPATH .. ' /check.json'
152
- end
176
+ local outpath = CHECK_OUT_PATH or LOGPATH .. ' /check.json'
177
+
153
178
-- Always write result, even if it's empty to make sure no one accidentally looks at an old output after a successful run.
154
179
util .saveFile (outpath , jsonb .beautify (results ))
155
180
0 commit comments