Manages the lifecycle and multi-threaded access to the presentation compiler.
A thread pool executor to execute jobs on a single thread in a last-in-first-out order.
A thread pool executor to execute jobs on a single thread in a last-in-first-out order.
The last-in-first-out order is important because it's common for Metals users to send multiple completion/hover/signatureHelp requests in rapid succession. In these situations, we care most about responding to the latest request even if it comes at the expense of ignoring older requests.
To restrict unsafe multi-threaded access to the presentation compiler we
schedule jobs to run on a single thread. We use this executor instead of the
presentation compiler thread (see MetalsGlobalThread) for the following reasons:
- we limit the usage of sleep/notify/wait/synchronized primitives.
- some blocking compiler APIs like ask[T](op: () => T)
don't seem to work as advertised.
- it's preferable to work on top of CompletableFuture[T] instead of the custom Response[T] from the compiler,
which is required to execute tasks on the presentation compiler thread:
A custom version of fuzzy search designed for code completions.
A comparator for identifier like "Predef" or "Function10".
A comparator for identifier like "Predef" or "Function10".
Differences from the default string comparator:
- works with CharSequences like compiler Name
- orders numbers by their numerical value instead of lexicographical
Function1
, Function2
, Function10
Function1
, Function10
, Function2
Extractor for exceptions that are caused by Thread.interrupt()
.
Manages the lifecycle and multi-threaded access to the presentation compiler.
- automatically restarts the compiler on miscellaneous crashes. - handles cancellation via
Thread.interrupt()
to stop the compiler during typechecking, for functions that support cancellation.