lua-language-server
lua-language-server copied to clipboard
Logic to sort diagnostics by cost doesn't work because of async processing
I found some logic in diagnostics/init.lua that doesn't work as expected: https://github.com/LuaLS/lua-language-server/blob/87abc4245f2a24e1cc35851b6464af9588934286/script/core/diagnostics/init.lua#L158 tries to sort diagnostics by cost to run cheap diags first.
However, the code to measure to runtime at https://github.com/LuaLS/lua-language-server/blob/87abc4245f2a24e1cc35851b6464af9588934286/script/core/diagnostics/init.lua#L180 does to by calling os.clock() before and after invoking a given diagnostic.
This doesn't work if the diagnostic yields during execution, and most diagnostics do exactly that via await.delay(). The end result is that the order is pretty much random (which I confirmed by looking at the diagCost arrays with and without await.delay() enabled)