mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[threading] IJPL-246537: Remove modal progress from calculation of CodeVision
GitOrigin-RevId: 7548fef2e4bebe4fd98de570f0256a13b2ee16f1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5129a1ee32
commit
a1c67da8ef
@@ -324,7 +324,7 @@ Fc:com.intellij.codeInsight.codeVision.CodeVisionHost
|
||||
- sf:defaultVisibleLenses:I
|
||||
- sf:settingsLensProviderId:java.lang.String
|
||||
- <init>(com.intellij.openapi.project.Project,kotlinx.coroutines.CoroutineScope):V
|
||||
- f:calculateCodeVisionSync(com.intellij.openapi.editor.Editor,com.intellij.openapi.Disposable):V
|
||||
- f:calculateCodeVisionSync(com.intellij.openapi.editor.Editor,com.intellij.openapi.Disposable):java.util.concurrent.CompletableFuture
|
||||
- f:collectPlaceholders(com.intellij.openapi.editor.Editor,com.intellij.psi.PsiFile,kotlin.coroutines.Continuation):java.lang.Object
|
||||
- f:getAnchorForEntry(com.intellij.codeInsight.codeVision.CodeVisionEntry):com.intellij.codeInsight.codeVision.CodeVisionAnchorKind
|
||||
- f:getCodeVisionLifetime():com.jetbrains.rd.util.lifetime.Lifetime
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.ide.plugins.DynamicPluginListener
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.EDT
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
@@ -73,6 +72,7 @@ import com.jetbrains.rd.util.reactive.Signal
|
||||
import com.jetbrains.rd.util.reactive.whenTrue
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
@@ -210,27 +210,28 @@ open class CodeVisionHost(val project: Project, protected val coroutineScope: Co
|
||||
return getPriorityForId(entry.providerId)
|
||||
}
|
||||
|
||||
/**
|
||||
* In particular tests, consider using
|
||||
* `CodeVisionTestCase.waitForCodeVisionSync`
|
||||
*/
|
||||
@TestOnly
|
||||
fun calculateCodeVisionSync(editor: Editor, testRootDisposable: Disposable) {
|
||||
fun calculateCodeVisionSync(editor: Editor, testRootDisposable: Disposable): CompletableFuture<Unit> {
|
||||
val future = CompletableFuture<Unit>()
|
||||
calculateFrontendLenses(testRootDisposable.createLifetime(), editor, inTestSyncMode = true) { lenses, _ ->
|
||||
if (EDT.isCurrentThreadEdt()) {
|
||||
runReadActionBlocking {
|
||||
editor.lensContext?.setResults(lenses)
|
||||
future.complete(Unit)
|
||||
}
|
||||
}
|
||||
else {
|
||||
// This code runs under modal progress
|
||||
// We have no guarantees whether the scheduled event will be completed inside or outside the modal progress
|
||||
// So here we forcibly wait for its completion
|
||||
// This is a test method anyway, so it is acceptable to hold the read lock
|
||||
val future = CompletableFuture<Unit>()
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
editor.lensContext?.setResults(lenses)
|
||||
future.complete(Unit)
|
||||
}
|
||||
future.join()
|
||||
}
|
||||
}
|
||||
return future
|
||||
}
|
||||
|
||||
protected open fun subscribeForDocumentChanges(editor: Editor, editorLifetime: Lifetime, onDocumentChanged: () -> Unit) {
|
||||
@@ -617,7 +618,11 @@ open class CodeVisionHost(val project: Project, protected val coroutineScope: Co
|
||||
}
|
||||
}
|
||||
else {
|
||||
ActionUtil.underModalProgress(project, "") { runnable() }
|
||||
coroutineScope.launch {
|
||||
readAction {
|
||||
runnable()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return indicator
|
||||
|
||||
+1
@@ -13,6 +13,7 @@ class CodeVisionVisualVerticalPositionKeeper(vararg editors: Editor) {
|
||||
|
||||
init {
|
||||
for (editor in editors) {
|
||||
if (editor.isDisposed) continue
|
||||
map[editor] = keep(editor)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user