9494--- @param name string
9595--- @param isScopeDiag boolean
9696--- @param response async fun ( result : any )
97+ --- @return boolean
9798local function check (uri , name , isScopeDiag , response )
9899 local disables = config .get (uri , ' Lua.diagnostics.disable' )
99100 if util .arrayHas (disables , name ) then
100- return
101+ return false
101102 end
102103 local severity = getSeverity (uri , name )
103104 local status = getStatus (uri , name )
104105
105106 if status == ' None' then
106- return
107+ return false
107108 end
108109
109110 if status == ' Opened' and not files .isOpen (uri ) then
110- return
111+ return false
111112 end
112113
113114 local level = define .DiagnosticSeverity [severity ]
@@ -140,10 +141,12 @@ local function check(uri, name, isScopeDiag, response)
140141 if DIAGTIMES then
141142 DIAGTIMES [name ] = (DIAGTIMES [name ] or 0 ) + passed
142143 end
144+ return true
143145end
144146
145147local diagList
146148local diagCosts = {}
149+ local diagCount = {}
147150local function buildDiagList ()
148151 if not diagList then
149152 diagList = {}
@@ -152,7 +155,9 @@ local function buildDiagList()
152155 end
153156 end
154157 table.sort (diagList , function (a , b )
155- return (diagCosts [a ] or 0 ) < (diagCosts [b ] or 0 )
158+ local time1 = (diagCosts [a ] or 0 ) / (diagCount [a ] or 1 )
159+ local time2 = (diagCosts [b ] or 0 ) / (diagCount [b ] or 1 )
160+ return time1 < time2
156161 end )
157162 return diagList
158163end
@@ -171,9 +176,12 @@ return function (uri, isScopeDiag, response, checked)
171176 for _ , name in ipairs (buildDiagList ()) do
172177 await .delay ()
173178 local clock = os.clock ()
174- check (uri , name , isScopeDiag , response )
175- local cost = os.clock () - clock
176- diagCosts [name ] = (diagCosts [name ] or 0 ) + cost
179+ local suc = check (uri , name , isScopeDiag , response )
180+ if suc then
181+ local cost = os.clock () - clock
182+ diagCosts [name ] = (diagCosts [name ] or 0 ) + cost
183+ diagCount [name ] = (diagCount [name ] or 0 ) + 1
184+ end
177185 if checked then
178186 checked (name )
179187 end
0 commit comments