Skip to content

Commit

Permalink
fix: Too many non-blocking read actions submitted at once in
Browse files Browse the repository at this point in the history
LSPDiagnosticHandler

Fixes redhat-developer#1089

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Aug 10, 2023
1 parent bd549b4 commit 4f4df61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Source file change notifier with a debounce mode.
*/
public class ClasspathResourceChangedNotifier implements Disposable {
public class ClasspathResourceChangedNotifier implements Disposable {

private static final long DEBOUNCE_DELAY = 1000;

Expand All @@ -46,7 +46,8 @@ public class ClasspathResourceChangedNotifier implements Disposable {

private final Set<Pair<VirtualFile, Module>> sourceFiles;
private boolean librariesChanged;
private final List<RunnableProgress> processBeforeLibrariesChanged;
private final List<RunnableProgress> processBeforeLibrariesChanged;
private boolean disposed;

public ClasspathResourceChangedNotifier(Project project, List<RunnableProgress> preprocessors) {
this.project = project;
Expand Down Expand Up @@ -74,6 +75,9 @@ public synchronized void addSourceFile(Pair<VirtualFile, Module> pair) {
}

private void asyncNotifyChanges() {
if (isDisposed()) {
return;
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
notifyChanges();
} else {
Expand All @@ -93,6 +97,9 @@ public void run() {
}

private void notifyChanges() {
if (isDisposed()) {
return;
}
synchronized (sourceFiles) {
// Java, config sources files has changed
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).sourceFilesChanged(sourceFiles);
Expand Down Expand Up @@ -121,8 +128,7 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
for (var runnable : processBeforeLibrariesChanged) {
runnable.run(progressIndicator);
}
}
finally {
} finally {
// Send the libraries changed event
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).librariesChanged();
librariesChanged = false;
Expand All @@ -134,12 +140,17 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
}
}

public boolean isDisposed() {
return disposed;
}

@Override
public void dispose() {
this.disposed = true;
if (debounceTask != null) {
debounceTask.cancel();
}
if(debounceTimer != null) {
if (debounceTimer != null) {
debounceTimer.cancel();
}
}
Expand Down

0 comments on commit 4f4df61

Please sign in to comment.