Skip to content

Commit 35a316a

Browse files
authored
Revert "Attach parent PluginResolver to plugin tracked coroutines (#4641)" (#4826)
This reverts commit bc8e338 Since the logic is in `core`, `coroutineContext` is consistently being initialized with "Toolkit" as the resolved plugin. Instead the resolver needs to be evaluated at the top of a coroutine stack, which needs some investigation given that we are moving to a platform-injected parent `CoroutineScope`
1 parent b4433e7 commit 35a316a

File tree

2 files changed

+1
-36
lines changed

2 files changed

+1
-36
lines changed

plugins/core/jetbrains-community/src/migration/software/aws/toolkits/jetbrains/core/coroutines/PluginCoroutineScopeTracker.kt

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ import com.intellij.openapi.util.Disposer
1010
import kotlinx.coroutines.CoroutineName
1111
import kotlinx.coroutines.CoroutineScope
1212
import kotlinx.coroutines.SupervisorJob
13-
import kotlinx.coroutines.ThreadContextElement
1413
import kotlinx.coroutines.cancel
1514
import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext
16-
import software.aws.toolkits.jetbrains.services.telemetry.PluginResolver
1715
import java.util.concurrent.CancellationException
18-
import kotlin.coroutines.CoroutineContext
1916

2017
class PluginCoroutineScopeTracker : Disposable {
2118
@PublishedApi
@@ -30,30 +27,11 @@ class PluginCoroutineScopeTracker : Disposable {
3027
}
3128

3229
private class BackgroundThreadPoolScope(coroutineName: String, disposable: Disposable) : CoroutineScope {
33-
override val coroutineContext = SupervisorJob() +
34-
CoroutineName(coroutineName) +
35-
getCoroutineBgContext() +
36-
PluginResolverThreadContextElement(PluginResolver.fromCurrentThread())
30+
override val coroutineContext = SupervisorJob() + CoroutineName(coroutineName) + getCoroutineBgContext()
3731

3832
init {
3933
Disposer.register(disposable) {
4034
coroutineContext.cancel(CancellationException("Parent disposable was disposed"))
4135
}
4236
}
4337
}
44-
45-
private class PluginResolverThreadContextElement(val pluginResolver: PluginResolver) : ThreadContextElement<PluginResolver> {
46-
companion object Key : CoroutineContext.Key<PluginResolverThreadContextElement>
47-
48-
override val key = Key
49-
50-
override fun updateThreadContext(context: CoroutineContext): PluginResolver {
51-
val oldPluginResolver = PluginResolver.fromCurrentThread()
52-
PluginResolver.setThreadLocal(pluginResolver)
53-
return oldPluginResolver
54-
}
55-
56-
override fun restoreThreadContext(context: CoroutineContext, oldState: PluginResolver) {
57-
PluginResolver.setThreadLocal(oldState)
58-
}
59-
}

plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/coroutines/ScopeTest.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import org.junit.Rule
2828
import org.junit.Test
2929
import org.junit.rules.TemporaryFolder
3030
import org.junit.rules.TestName
31-
import software.aws.toolkits.jetbrains.services.telemetry.PluginResolver
3231
import software.aws.toolkits.jetbrains.utils.isInstanceOf
3332
import java.time.Duration
3433
import java.util.concurrent.CancellationException
@@ -154,18 +153,6 @@ class ScopeTest {
154153
assertThatThrownBy { disposableCoroutineScope(ApplicationManager.getApplication()) }.isInstanceOf<IllegalStateException>()
155154
}
156155

157-
@Test
158-
fun `coroutine inherits PluginResolver from parent`() {
159-
val pluginResolver = PluginResolver.fromCurrentThread()
160-
PluginResolver.setThreadLocal(pluginResolver)
161-
162-
runBlocking {
163-
withContext(applicationCoroutineScope().coroutineContext) {
164-
assertThat(PluginResolver.fromCurrentThread()).isEqualTo(pluginResolver)
165-
}
166-
}
167-
}
168-
169156
private fun createFakePluginScope(componentManager: ComponentManager = ApplicationManager.getApplication()): Disposable {
170157
// We can't unload the real plugin in tests, so make another instance of the service and replace it for the tests
171158
val tracker = PluginCoroutineScopeTracker()

0 commit comments

Comments
 (0)