LuaLS / LuaLS/lua-language-server
Logic to sort diagnostics by cost doesn't work because of async processing
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in script/core/diagnostics/init.lua at the sorting logic around line 158 and runtime measurement around line 180. Compare diagnostic cost arrays with await.delay() enabled and disabled to reproduce the issue. Done means diagnostics are ordered by meaningful measured cost even when diagnostic execution yields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100