@@ -5,13 +5,9 @@ import com.intellij.openapi.application.ReadAction
5
5
import com.intellij.psi.PsiFile
6
6
import com.intellij.util.io.await
7
7
import ee.carlrobert.codegpt.psistructure.models.ClassStructure
8
- import kotlinx.coroutines.Dispatchers
9
- import kotlinx.coroutines.asExecutor
10
- import kotlinx.coroutines.currentCoroutineContext
11
- import kotlinx.coroutines.delay
12
- import kotlinx.coroutines.ensureActive
8
+ import ee.carlrobert.codegpt.util.coroutines.runCatchingCancellable
9
+ import kotlinx.coroutines.*
13
10
import org.jetbrains.kotlin.psi.KtFile
14
- import kotlin.coroutines.cancellation.CancellationException
15
11
16
12
class PsiStructureProvider {
17
13
@@ -26,7 +22,7 @@ class PsiStructureProvider {
26
22
27
23
while (result == null && attempts < maxAttempts) {
28
24
attempts++
29
- try {
25
+ runCatchingCancellable {
30
26
val project = psiFiles
31
27
.map { it.project }
32
28
.firstOrNull { ! it.isDisposed } ? : error(" Project not available" )
@@ -60,9 +56,7 @@ class PsiStructureProvider {
60
56
.submit(Dispatchers .Default .asExecutor())
61
57
62
58
result = future.await()
63
- } catch (e: CancellationException ) {
64
- throw e
65
- } catch (_: Exception ) {
59
+ }.onFailure {
66
60
delay(DELAY_RESTART_READ_ACTION )
67
61
}
68
62
}
0 commit comments