netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

Run long-spanning tasks cancellably on background in the (Java) LSP server.

Open lahodaj opened this issue 1 year ago • 1 comments

@jtulach reported the code completion inside VS Code is sometimes slow for him. I was thinking of that, and experimenting, and I think at least part of the problem is that tasks that should be background tasks are not properly cancellable in the VS Code (Java) server.

I was doing experiments on: https://github.com/openjdk/jdk/blob/master/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

and it seemed there were two (current) particular pain points:

  • diagnostics (especially hints) computation, which can take a fairly long time to compute
  • semantic coloring computation, which can also take some time to compute

Neither of these can be cancelled when the request to compute code completion. This draft is attempting to improve that, and run diagnostics and semantic coloring in a cancellable way.

It only properly cancels for Java sources at this time, for other sources runs only the CompletableFuture cancel will work. Some work on Schedulers will be needed to fully enable this for non-Java sources, but I suspect this can wait

I also have a separate PR that adds additional logging for code completion: https://github.com/apache/netbeans/pull/7815

lahodaj avatar Aug 29 '24 11:08 lahodaj

I think we need to make progress on this.

lahodaj avatar Oct 09 '24 13:10 lahodaj

FWIW: I've changed the implementation to an explicit priority "queue", as the original patch with injecting tasks in the editor background infrastructure proved to be too complex, at least for now.

lahodaj avatar Nov 29 '24 14:11 lahodaj

I limitation of this way to cancel things is that it cannot stop computations inside javac/parser. Unlike the previous round which used the "editor" tasks, which can stop even javac/parser.

But, this patch:

  • should provide an improvement compared to the current state
  • should allow various features use the abstraction - and then we might be able to improve the abstraction, without (significantly) re-writing the features.

lahodaj avatar Dec 03 '24 10:12 lahodaj