Skip to content

Commit

Permalink
Prepare for 2023.3: Move some tasks to background thread. (#5446)
Browse files Browse the repository at this point in the history
Since the commit below, FSRecords update operations are forbidden in EDT thread.
JetBrains/intellij-community@78f7474

For this reason, we delegate a few method calls to Background Thread in order to make
sure it will not crash. We do it via a synchrounous BGT call, so
EDT still stops and waits until the aciton is completed, like it was before this change.
  • Loading branch information
tpasternak authored Oct 10, 2023
1 parent 936e132 commit 228a6fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.google.common.collect.ImmutableList;
import com.google.common.io.CharStreams;
import com.google.idea.blaze.base.io.InputStreamProvider;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.vfs.LocalFileSystem;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -43,6 +45,12 @@ public void writeProjectView(String projectViewText, File projectViewFile) throw
try (Writer fileWriter = Files.newBufferedWriter(projectViewFile.toPath(), UTF_8)) {
fileWriter.write(projectViewText);
}
LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(projectViewFile));

ProgressManager.getInstance().runProcessWithProgressSynchronously(
() -> LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(projectViewFile)),
"Updating VFS",
false,
null
);
}
}
18 changes: 13 additions & 5 deletions base/src/com/google/idea/blaze/base/toolwindow/ConsoleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
Expand Down Expand Up @@ -298,11 +300,17 @@ Result combine(Result first, Result second) {

/** Add the global filters, wrapped to separate them from blaze problems. */
private void addWrappedPredefinedFilters() {
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
for (ConsoleFilterProvider provider : ConsoleFilterProvider.FILTER_PROVIDERS.getExtensions()) {
Arrays.stream(getFilters(scope, provider))
.forEach(f -> consoleView.addMessageFilter(NonProblemFilterWrapper.wrap(f)));
}
ProgressManager.getInstance().runProcessWithProgressSynchronously(() ->
ApplicationManager.getApplication().runReadAction(() -> {
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
for (ConsoleFilterProvider provider : ConsoleFilterProvider.FILTER_PROVIDERS.getExtensions()) {
Arrays.stream(getFilters(scope, provider))
.forEach(f -> consoleView.addMessageFilter(NonProblemFilterWrapper.wrap(f)));
}
}),
"Setting Console Filters",
false,
null);
}

private Filter[] getFilters(GlobalSearchScope scope, ConsoleFilterProvider provider) {
Expand Down

0 comments on commit 228a6fd

Please sign in to comment.