LuaLS / LuaLS/lua-language-server

Logic to sort diagnostics by cost doesn't work because of async processing

Open
#2,677 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.