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.
This commit is contained in:
Dallin Romney 2026-03-26 14:37:07 -07:00 • committed by GitHub
parent b48183c023
commit 581980e31e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -56,7 +56,7 @@ interface CursorMovementHandler {
@Service(Service.Level.PROJECT)
class ActiveHandlerManager(private val project: Project) : SelectionListener, CaretListener, DumbAware {
private val coroutineScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
private val coroutineScope = CoroutineScope(Dispatchers.Default.limitedParallelism(1) + SupervisorJob())
private var activeHandler: CursorMovementHandler? = null
private var isHandlingEvent = false

View file

@ -13,7 +13,7 @@ import kotlinx.coroutines.*
@Service(Service.Level.PROJECT)
class DocumentChangeTracker(private val project: Project) : DocumentListener {
private val coroutineScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
private val coroutineScope = CoroutineScope(Dispatchers.Default.limitedParallelism(1) + SupervisorJob())
private var typingHandler: TypingSessionHandler? = null
private var typingSessionTimer: Job? = null