nextflow-io / language-server

The Nextflow language server
Apache License 2.0
0 stars 0 forks source link

Some LSP requests should wait for debounced update #23

Open bentsherman opened 1 month ago

bentsherman commented 1 month ago

I got nerd-sniped over the weekend while playing around with the language server. Saving my findings here for later.

Some LSP requests like document link, document symbol, and code lens are made automatically by the editor as a document is edited. They do appear to be debounced (at least in vscode), but the delay is shorter than ours, so these requests are often processed before the AST has been re-compiled. I have seen the document links fall out of sync for this reason.

I would like to make these LSP requests wait for the delayed update if it exists, since the change event always seems to arrive first. Something like this:

  1. on didChange, trigger a delayed update and set an "awaiting update" flag to true
  2. on document link/symbol request, if "awaiting update" is true, wait on an "updated" condition variable
  3. on update, signal the "updated" condition variable, unblocking all relevant LSP requests

The problem I'm seeing is the lock associated with the condition. If the requests need to acquire the lock in order to wait on the condition variable, then the update thread can't acquire that lock to signal the condition variable. Maybe I need to use a read-write lock to handle this.