Skip to content

ADFA-4174: prioritize code completion requests over over analyze requests#1439

Draft
itsaky-adfa wants to merge 4 commits into
stagefrom
fix/ADFA-4174
Draft

ADFA-4174: prioritize code completion requests over over analyze requests#1439
itsaky-adfa wants to merge 4 commits into
stagefrom
fix/ADFA-4174

Conversation

@itsaky-adfa

@itsaky-adfa itsaky-adfa commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

See ADFA-4174 for more details.

itsaky and others added 4 commits June 19, 2026 22:28
Signed-off-by: Akash Yadav <itsaky01@gmail.com>
Signed-off-by: Akash Yadav <itsaky01@gmail.com>
… completion cleanup)

Apply the actionable items from Hal's review on PR #1428:

- Diagnostics: extract the unresolved-reference name inside the analyze block
  instead of storing the live KaDiagnosticWithPsi (a KaLifetimeOwner) in
  DiagnosticItem.extra. AddImportAction now reads the pre-extracted string,
  preventing KaInaccessibleLifetimeOwnerAccessException from the quick-fix path.
- CompilationEnvironment.notifyElementModifiedForPath: run
  handleElementModification inside project.write so the session mutation can't
  race a concurrent analyze (mirrors onFileContentChanged).
- KotlinCompletions: collapse manual withAnalysisLock + analyzeCopy into
  analyzeMaybeDangling, removing the only in-prod direct analyzeCopy call.
- KtFileExts: document that code under withAnalysisLock must not call
  project.write (non-upgradeable RW lock footgun).
Replace the FIFO analysis lock with AnalysisScheduler, a process-global,
priority-aware, preemptive, reentrant lock that serializes all Kotlin Analysis
API access while letting interactive work win.

Priority order: Completion > Diagnostics > Indexing.
- A higher-priority request preempts a strictly lower-priority in-progress
  analysis. Preemption is cooperative (the Analysis API can't be interrupted
  mid-analyze): the holder's ScheduledCancelChecker is flagged and the running
  analysis bails at its next abortIfCancelled() checkpoint with
  AnalysisPreemptedException.
- A lower-priority request waits while a higher-priority one holds.
- Preempted diagnostics/indexing work is auto-rescheduled so it still completes:
  diagnostics re-schedules via the fileAnalyzer; indexing re-queues the command.
- Indexing is now actively preemptible (was ICancelChecker.NOOP).

Wiring:
- KotlinCompletions: COMPLETION priority, request-scoped checker from Lookup.
- KotlinDiagnosticProvider: DIAGNOSTICS priority; CompilationEnvironment's
  fileAnalyzer catches AnalysisPreemptedException to re-schedule.
- IndexWorker/SourceFileIndexer: INDEXING priority; re-queue on preemption.

Tests: extend AnalysisSerializationTest with reentrancy, higher-preempts-lower,
and lower-waits-for-higher cases (all 5 tests pass).
@itsaky-adfa itsaky-adfa requested a review from a team June 24, 2026 15:06
@itsaky-adfa itsaky-adfa self-assigned this Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants