Skip to content

Commit 581980e

Browse files
authored
fix: resolve SideEffectNotAllowedException in intention previews (#11894)
* fix: use Dispatchers.Default to avoid SideEffectNotAllowedException in JetBrains intention previews DocumentChangeTracker and ActiveHandlerManager used Dispatchers.Main which schedules work via INVOKE_LATER. JetBrains forbids this during intention preview computation (autocomplete, inspections), throwing SideEffectNotAllowedException. Neither class requires EDT for its coroutine work, so switching to Dispatchers.Default resolves the issue. Fixes #9463, #8035 * fix: use limitedParallelism(1) to prevent race conditions Dispatchers.Default allows concurrent execution on a thread pool, which breaks thread-safety for shared mutable state that was previously serialized on the Main/EDT dispatcher. Using limitedParallelism(1) preserves single-threaded execution while still avoiding the SideEffectNotAllowedException from Dispatchers.Main.
1 parent b48183c commit 581980e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/listeners/ActiveHandlerManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ interface CursorMovementHandler {
5656
@Service(Service.Level.PROJECT)
5757
class ActiveHandlerManager(private val project: Project) : SelectionListener, CaretListener, DumbAware {
5858

59-
private val coroutineScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
59+
private val coroutineScope = CoroutineScope(Dispatchers.Default.limitedParallelism(1) + SupervisorJob())
6060
private var activeHandler: CursorMovementHandler? = null
6161
private var isHandlingEvent = false
6262

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/listeners/DocumentChangeTracker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlinx.coroutines.*
1313
@Service(Service.Level.PROJECT)
1414
class DocumentChangeTracker(private val project: Project) : DocumentListener {
1515

16-
private val coroutineScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
16+
private val coroutineScope = CoroutineScope(Dispatchers.Default.limitedParallelism(1) + SupervisorJob())
1717
private var typingHandler: TypingSessionHandler? = null
1818
private var typingSessionTimer: Job? = null
1919

0 commit comments

Comments
 (0)