lsp4intellij icon indicating copy to clipboard operation
lsp4intellij copied to clipboard

validations/diagnostics/annotations keep disappearing and reappering

Open Trias opened this issue 5 years ago • 3 comments

Description: perhaps best explained in a screencast: lsp-annotations

Suggested Labels: validation, annotation, bug,

Affected Product Version: master

OS, DB, other environment details and versions:
windows

Steps to reproduce: Have an LSP-server which produces diagnostics for the current file. Provoke an invalid edit. after the validation appears, click away. the diagnostics diasappear. Enter some new text and the diagnostics reappear

I've looked into the code and I'm not sure how to fix it. I believe this condition here is faulty: https://github.com/ballerina-platform/lsp4intellij/blob/3acf176e65493825239e1d3ebb3fcb64689e3af0/src/main/java/org/wso2/lsp4intellij/contributors/annotator/LSPAnnotator.java#L59

If i remove the !(eventManager.isDiagnosticSyncRequired() || eventManager.isCodeActionSyncRequired())-part, the annotations stay alive as expected. However i guess there is a reason for this check, but it is not clear to me what it achieves or what the downsides of removing it are.

does not appear to solve the problem reliably

Trias avatar Nov 19 '20 15:11 Trias

confirm same behavior with bsl language server.

nixel2007 avatar Nov 20 '20 07:11 nixel2007

Maybe it has sth todo with the way IntelliJ renders/collects information for the editor panel. With LineMarkers IntelliJ loads information about the visible area at first and i a second pass IntelliJ asks for the rest of the information. As the getAnnotation() has a sideffect the first call will set isDiagnosticSyncRequired() to false so a a followup call will return false and there are no annotations returned so the rendering removes the already rendered annotations? Just a guess that this could happen here, too.

swissiety avatar Dec 29 '20 11:12 swissiety

i found the issue. It has nothing to do with intellij. the logic with ...SyncRequired() is off. if i disable it completely (no checking in collectInformation and always createAnnotations in apply) it works for me. (only annotations, no code actions of course)

the indeterminism apparently comes from the server pushing new diagostics and multiple threads running in parallel. This leads to the ...SyncRequired()- functions being ... out of sync (pardon the pun ;) ) between the different threads or even within a thread. So it happens that neither diagnosticSyncRequired nor codeActionSyncRequired is true and annotations are effectively cleared. Retuning null from collectInformation also clears annotations and is also something we shouldn't do in common cases.

Trias avatar Dec 30 '20 19:12 Trias