Skip to content

Commit 3cb5af0

Browse files
committed
Process imports in background thread
1 parent 5680c65 commit 3cb5af0

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/com/goide/codeInsight/imports/GoOptimizeImportsPass.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.intellij.codeInsight.daemon.impl.DefaultHighlightInfoProcessor;
2020
import com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass;
21+
import com.intellij.openapi.command.undo.UndoManager;
2122
import com.intellij.openapi.editor.Editor;
2223
import com.intellij.openapi.progress.ProgressIndicator;
2324
import com.intellij.openapi.project.Project;
@@ -27,6 +28,7 @@
2728

2829
public class GoOptimizeImportsPass extends ProgressableTextEditorHighlightingPass {
2930
@NotNull private final PsiFile myFile;
31+
private Runnable myRunnableFix;
3032

3133
public GoOptimizeImportsPass(@NotNull Project project, @NotNull PsiFile file, @NotNull Editor editor) {
3234
super(project, editor.getDocument(), "Go Optimize Imports Pass", file, editor, file.getTextRange(), false,
@@ -36,12 +38,15 @@ public GoOptimizeImportsPass(@NotNull Project project, @NotNull PsiFile file, @N
3638

3739
@Override
3840
protected void collectInformationWithProgress(@NotNull ProgressIndicator progress) {
41+
myRunnableFix = new GoImportOptimizer().processFile(myFile);
3942
progress.checkCanceled();
4043
}
4144

4245
@Override
4346
protected void applyInformationWithProgress() {
44-
final Runnable runnable = new GoImportOptimizer().processFile(myFile);
45-
DocumentUtil.writeInRunUndoTransparentAction(runnable);
47+
final Project project = myFile.getProject();
48+
UndoManager undoManager = UndoManager.getInstance(project);
49+
if (undoManager.isUndoInProgress() || undoManager.isRedoInProgress()) return;
50+
DocumentUtil.writeInRunUndoTransparentAction(myRunnableFix);
4651
}
4752
}

tests/com/goide/inspections/GoTestSignaturesInspectionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
import com.intellij.testFramework.LightProjectDescriptor;
2222

2323
public class GoTestSignaturesInspectionTest extends GoQuickFixTestBase {
24-
@Override
25-
protected void tearDown() throws Exception {
26-
GoCodeInsightSettings.getInstance().setOptimizeImportsOnTheFly(true);
27-
super.tearDown();
28-
}
29-
3024
@Override
3125
protected void setUp() throws Exception {
3226
super.setUp();
@@ -35,6 +29,12 @@ protected void setUp() throws Exception {
3529
GoCodeInsightSettings.getInstance().setOptimizeImportsOnTheFly(false);
3630
}
3731

32+
@Override
33+
protected void tearDown() throws Exception {
34+
GoCodeInsightSettings.getInstance().setOptimizeImportsOnTheFly(true);
35+
super.tearDown();
36+
}
37+
3838
@Override
3939
protected LightProjectDescriptor getProjectDescriptor() {
4040
return createMockProjectDescriptor();

0 commit comments

Comments
 (0)