diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java index 67f271dfc..720023465 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java @@ -17,6 +17,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; @@ -45,12 +46,21 @@ public LSPDiagnosticHandler(LanguageServerWrapper languageServerWrapper) { @Override public void accept(PublishDiagnosticsParams params) { + Project project = languageServerWrapper.getProject(); + if(project.isDisposed()) { + return; + } if (ApplicationManager.getApplication().isReadAccessAllowed()) { updateDiagnostics(params); } else { - ReadAction.nonBlocking(() -> updateDiagnostics(params)) - .submit(AppExecutorUtil.getAppExecutorService()); - + var executeInSmartMode = DumbService.getInstance(languageServerWrapper.getProject()).isDumb(); + var action = ReadAction.nonBlocking(() -> updateDiagnostics(params)) + .expireWith(languageServerWrapper) + .coalesceBy(params); + if (executeInSmartMode) { + action.inSmartMode(project); + } + action.submit(AppExecutorUtil.getAppExecutorService()); } }