… editor scrolls (#1883)
* fix: don't throw a failed code lens request on the UI thread when the editor scrolls
LSPCodeLensEditorFactoryListener's visible area listener, which runs on the
UI thread on every scroll or resize of an editor, read the code lens future
with getNow() once it was done. A request whose language server cannot
start, as when its command is wrong, is done exceptionally: getNow() then
rethrew its CompletionException(CannotStartProcessException), which IntelliJ
reports as an IDE error with no LSP4IJ frame on the UI thread, as in #1600.
LSP4IJ already reports a server that cannot start with a "Cannot start
server" notification. The listener now reads the future only if it is done
normally (CompletableFutures.isDoneNormally), and a failed or cancelled
request has no code lenses to resolve.
#1832 (#1830) changed the wait of the highlighting passes, not this read,
so it didn't fix #1600.
Validation:
- ServerStartFailureTest.testAScrollOfAnEditorWhoseCodeLensesFailedDoesNotThrow
calls the listener that editorCreated attaches with a failed code lens
request. On main it fails with "CompletionException:
CannotStartProcessException: Cannot run program "missing"", thrown at
LanguageServerWrapper.java:659, as in the issue; with this change it
passes.
- The full suite: 1,292 tests, 3 skipped; the 7 failures are the known
macOS ones ("File accessed outside allowed roots") in
LSPIJUtils_applyWorkspaceEdit_*Test and CommandExecutorTest, which fail
on main too.
Fixes #1600.
* fix: keep a code lens viewport up to date while its editor has no code lenses
LSPCodeLensProvider resolves the code lenses of a new result in the
viewport kept by the editor's UnresolvedCodeLensViewportContext. The scroll
listener updated that viewport only when the code lens request had ended
normally, so a scroll while the request ran, or after it failed as when the
language server cannot start, left it where it was. A later result then
resolved the code lenses of the old viewport, and those shown stayed
unresolved until the next scroll.
The listener now updates the viewport on every scroll, and only the refresh
of the code visions waits for a result.
Validation: ServerStartFailureTest's new
testAScrollOfAnEditorWhoseCodeLensesFailedUpdatesItsViewport scrolls an
editor whose request failed from line 0 to line 50; without the change the
viewport stays at line 0 ("expected:<50> but was:<0>"). ServerStartFailureTest
and EditorRefreshBatchTest: 9 tests, 0 failures, 0 skipped (JUnit XML).
* fix: read a code lens result once its editor's viewport is updated
The scroll listener read the code lens result when the editor scrolled, and
updated the viewport later when it had no read access, in a read action on
the UI thread. A request that ended in between resolved the code lenses of
the previous viewport, and the deferred update, which still held no result,
didn't refresh the code visions: the code lenses of the new viewport stayed
unresolved until another scroll.
updateViewportLinesAndRefreshCodeVision now reads the result itself, once
it has updated the viewport, on both paths.
Validation: ServerStartFailureTest and EditorRefreshBatchTest, 9 tests, 0
failures, 0 skipped (JUnit XML). The deferred path runs only without read
access on the UI thread, which a 2024.2 test doesn't have, so no test
drives it.
When a language server cannot start, for instance because its command is wrong ("Cannot run program"), LSP4IJ shows its "Cannot start server" notification, and IntelliJ also reports "IDE error occurred" for a feature that was waiting for the server, such as the colors of the file:
About 40 features wait for their request with
CompletableFutures.awaitWithCheckCanceled, catch only cancellations, and then skip a request which isn't done normally (isDoneNormally). But the wait calls IntelliJ'sProgressIndicatorUtils.awaitWithCheckCanceled, which rethrows a failed future, in aRuntimeExceptionaround itsExecutionException, so the failure escapes before that check.15aa49ae("perf: Use ProgressIndicatorUtils.awaitWithCheckCanceled", in 0.20.2) made it the wait. Before,CompletableFutures.waitUntilDoneturned a failed server start, aLanguageServerException, into aProcessCanceledException, and threw any other failure as anExecutionException, which the callers caught. #784 is the same regression forcompletionItem/resolve, which #1814 fixed for that request.Fixes #1830.
Related to #1600: its trace is also a
CannotStartProcessExceptionreported by IntelliJ, but through another path: it was reported against 0.20.0, before15aa49ae, and it is aCompletionException, made by a stage of the failed initialization (thethenApplyofgetInitializedServer()), which reaches the EDT, so some code there joins that stage. This wait throws aRuntimeExceptioninstead, so #1600 is not addressed here.Changes
CompletableFutures.awaitWithCheckCanceledreturns when the future fails, instead of throwing the failure, so the callers skip it as a request which isn't done normally. A cancellation is thrown as before: aCancellationExceptionfor a cancelled future, and aProcessCanceledExceptionfor a canceled progress or a future cancelled in a previous stage.LanguageServerException, a server which could not start or which stopped, is logged at debug level: LSP4IJ has already reported it, in its notification and the LSP console, and each highlighting pass which waits for the server would repeat it. Any other failure is logged as a warning, since it is unexpected: an LSP error response doesn't reach the wait, asCancellationSupportreports it, as the server's Error reporting setting says, and completes the request with null. What's left is a bug in a client's feature code or in LSP4IJ, or a request which doesn't go throughCancellationSupport, such as a DAP request. A warning keeps it in the log without an IDE error.CancellationSupport.awaitWithCheckCanceled, LSP4IJ's own copy of IntelliJ's wait, which Go to Symbol and Go to Class use, returns null for a failed future in the same way. It threw the failure before 0.20.2 too.isDoneNormally, sincegetNow()andjoin()rethrow a failure:LSPUsageSearcherchecked onlyisDone(), so the failure reached itsLOGGER.error. It now checksisDoneNormally.DAPSmartStepIntoHandlernow checksisDoneNormallybeforegetNow().DAPDebugProcessneeds the failure thrown: it prints it in the debug console and stops the session. It now waits withProgressIndicatorUtils.awaitWithCheckCanceled, which still throws it, so it works as before.LSPFormattingSupportletsjoin()andgetNow()throw the failure into itscatch (Exception), which reports a formatting error, as before. The message of that error is now the failure's own, rather than theExecutionException's.LSPInlineCompletionProvidercalledProgressIndicatorUtils.awaitWithCheckCanceleditself, and caught anExecutionException, which that wait never throws. It now waits withCompletableFutures.awaitWithCheckCanceled, and checksisDoneNormallyas before, so a failed request gives no suggestion.The other callers check
isDoneNormallybefore they read the future, or hand it to code which does (AbstractLSPGoToAction, andfillChildrenof the call and type hierarchies).LSPCodeLensProvidergoes on with the code lenses whosecodeLens/resolvedidn't fail.AbstractLSPFileListenerandCompletableFutures.waitUntilDoneAsynccall IntelliJ's wait themselves and catch any exception, so they don't change.LSPCompletionProposalisn't changed here.Tests
AwaitWithCheckCanceledTesthas 7 tests:CompletableFutures.awaitWithCheckCanceledwithout their failure;CancellationException, and a future cancelled in a previous stage, or a canceled progress, throws aProcessCanceledException, as before;CancellationSupport.awaitWithCheckCanceledreturns null for a failed future, and the result of a completed one, and throws aProcessCanceledExceptionfor a cancelled future, as before.ServerStartFailureTesthas 2 tests, with a server whose start fails with "Cannot run program": the color provider, collecting throughgetCollectorFor(...).collect(...)as in the trace above, adds nothing, andLSPFoldingRangeBuilder.getFoldingRangesreturns no folding range. Both check that the server failed to start.Without the change in
src/main, 5 of the 9 tests fail with theRuntimeExceptionabove: the 2 tests ofServerStartFailureTest, the 2 failed futures ofCompletableFutures.awaitWithCheckCanceled, and the failed future ofCancellationSupport.awaitWithCheckCanceled. The 4 tests of the cancellations pass with and without it.com.redhat.devtools.lsp4ij.features.*,usages.*,dap.*,internal.*,server.*and the language server lifecycle tests (LanguageServer*,ConnectDuringStopTest,DocumentLifecycleTest,RequestAfterChangeTest,LSPIJEditorUtilsTest) pass: 784 tests, with the 3 existing skips.Locally, the full suite passes (1,019 tests, 3 skipped) except the 7 known macOS failures ("File accessed outside allowed roots"), which fail on
maintoo. The IDE error was seen in a running IDE, with a LemMinX server whose command was wrong; the fix was not checked there.