@@ -11,6 +11,7 @@ import com.intellij.icons.AllIcons
11
11
import com.intellij.lang.Language
12
12
import com.intellij.lang.annotation.HighlightSeverity
13
13
import com.intellij.openapi.application.ApplicationManager
14
+ import com.intellij.openapi.application.WriteAction
14
15
import com.intellij.openapi.application.runReadAction
15
16
import com.intellij.openapi.application.runWriteAction
16
17
import com.intellij.openapi.command.CommandProcessor
@@ -20,6 +21,10 @@ import com.intellij.openapi.diff.impl.patch.*
20
21
import com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier
21
22
import com.intellij.openapi.fileEditor.FileDocumentManager
22
23
import com.intellij.openapi.fileEditor.FileEditorManager
24
+ import com.intellij.openapi.progress.ProgressIndicator
25
+ import com.intellij.openapi.progress.ProgressManager
26
+ import com.intellij.openapi.progress.Task
27
+ import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
23
28
import com.intellij.openapi.project.Project
24
29
import com.intellij.openapi.vfs.VfsUtilCore
25
30
import com.intellij.openapi.vfs.VirtualFile
@@ -33,7 +38,6 @@ import com.intellij.ui.components.panels.VerticalLayout
33
38
import com.intellij.util.LocalTimeCounter
34
39
import com.intellij.util.concurrency.annotations.RequiresWriteLock
35
40
import java.awt.BorderLayout
36
- import java.awt.EventQueue.invokeLater
37
41
import java.awt.event.MouseAdapter
38
42
import java.awt.event.MouseEvent
39
43
import java.io.IOException
@@ -141,17 +145,18 @@ class SingleFileDiffSketch(
141
145
mainPanel.add(contentPanel)
142
146
143
147
ApplicationManager .getApplication().invokeLater {
144
- lintCheckForNewCode(currentFile)
145
- }
148
+ val task = object : Task .Backgroundable (myProject, " Analysis code style" , false ) {
149
+ override fun run (indicator : ProgressIndicator ) {
150
+ lintCheckForNewCode(currentFile)
146
151
147
- if (isAutoRepair && appliedPatch?.status != ApplyPatchStatus .SUCCESS ) {
148
- ApplicationManager .getApplication().invokeLater {
149
- try {
150
- executeAutoRepair()
151
- } catch (e: Exception ) {
152
- logger<SingleFileDiffSketch >().error(" Failed to execute auto repair" , e)
152
+ if (isAutoRepair && appliedPatch?.status != ApplyPatchStatus .SUCCESS ) {
153
+ executeAutoRepair()
154
+ }
153
155
}
154
156
}
157
+
158
+ ProgressManager .getInstance()
159
+ .runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator (task))
155
160
}
156
161
}
157
162
@@ -166,8 +171,11 @@ class SingleFileDiffSketch(
166
171
null
167
172
}
168
173
169
- val file = LightVirtualFile (currentFile, fixedCode, LocalTimeCounter .currentTime())
170
- createActionButtons(file, appliedPatch, patch).let { actions ->
174
+ WriteAction .compute<Unit , Throwable > {
175
+ currentFile.writeText(fixedCode)
176
+ }
177
+
178
+ createActionButtons(currentFile, appliedPatch, patch).let { actions ->
171
179
actionPanel.removeAll()
172
180
actions.forEach { button ->
173
181
actionPanel.add(button)
@@ -256,6 +264,7 @@ class SingleFileDiffSketch(
256
264
override fun updateLanguage (language : Language ? , originLanguage : String? ) {}
257
265
258
266
fun lintCheckForNewCode (currentFile : VirtualFile ) {
267
+
259
268
if (newCode.isEmpty()) return
260
269
val newFile = LightVirtualFile (currentFile, newCode, LocalTimeCounter .currentTime())
261
270
val psiFile = runReadAction { PsiManager .getInstance(myProject).findFile(newFile) } ? : return
0 commit comments