Repository navigation
ADFA-6855: Reparse and invalidate Kotlin documents incrementally #2280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
itsaky-adfa
wants to merge
21
commits into
stage
Choose a base branch
from
perf/ADFA-6855-incremental-reparse
base: stage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
dd9ea28
feat(lsp-kotlin): register services for in-place PSI edits
itsaky-adfa 20229f2
fix(common): propagate job cancellation to JobCancelChecker listeners
itsaky-adfa e515f52
fix(common): cancel JobCancelChecker when its job starts cancelling
itsaky-adfa 9914d18
fix(common): keep JobCancelChecker.abortIfCancelled throwing after ca…
itsaky-adfa db6fa2c
fix(lsp-kotlin): preempt running analysis before applying an edit
itsaky-adfa 1be3d9e
fix(lsp-kotlin): keep environment disposal and the barrier count safe…
itsaky-adfa 773a0bc
perf(lsp-kotlin): reparse open Kotlin documents in place
itsaky-adfa b4bf694
perf(lsp-kotlin): invalidate only the edited declaration on in-body e…
itsaky-adfa b70a654
fix(lsp-kotlin): reindex when an in-block edit removes a local class
itsaky-adfa 72d2da3
fix(lsp-kotlin): read the live KtFile under project.read when applyin…
itsaky-adfa 277bc98
test(lsp-kotlin): cover the edit barrier on in-place refreshes
itsaky-adfa c0e8643
perf(lsp-kotlin): skip the edit barrier when a version bump leaves th…
itsaky-adfa 601bce7
fix(lsp-kotlin): relaunch a failed refresh and keep a closed path's d…
itsaky-adfa a4efe2b
fix(lsp-kotlin): retry refactoring plans once when an edit preempts them
itsaky-adfa ad1efaa
docs(lsp-kotlin): correct the pin KDocs for in-place edits and name a…
itsaky-adfa 05aefc4
style: spotless reformat, no functional change
itsaky-adfa 322f2c0
docs(lsp-kotlin): record the edit barrier and in-place reparse in ADR…
itsaky-adfa 9c094f9
style: spotless reformat, no functional change
itsaky-adfa 45c5d78
fix(lsp-kotlin): log the sizes of IntelliJ error attachments instead …
itsaky-adfa d748fff
fix(lsp-kotlin): update the file contents before an in-place PSI chan…
itsaky-adfa be58ac9
Merge branch 'stage' into perf/ADFA-6855-incremental-reparse
itsaky-adfa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
common/src/test/java/com/itsaky/androidide/tasks/JobCancelCheckerTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package com.itsaky.androidide.tasks | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import kotlinx.coroutines.CancellationException | ||
| import kotlinx.coroutines.CompletableDeferred | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.Job | ||
| import kotlinx.coroutines.NonCancellable | ||
| import kotlinx.coroutines.launch | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlinx.coroutines.withContext | ||
| import org.junit.Assert.assertThrows | ||
| import org.junit.Test | ||
|
|
||
| class JobCancelCheckerTest { | ||
| @Test | ||
| fun `cancelling the constructor job cancels the checker and fires listeners`() { | ||
| val job = Job() | ||
| val checker = JobCancelChecker(job) | ||
| var fired = false | ||
| checker.invokeOnCancel { fired = true } | ||
|
|
||
| job.cancel() | ||
|
|
||
| assertThat(checker.isCancelled()).isTrue() | ||
| assertThat(fired).isTrue() | ||
| } | ||
|
|
||
| @Test | ||
| fun `cancelling a job assigned after construction cancels the checker`() { | ||
| val checker = JobCancelChecker() | ||
| val job = Job() | ||
| checker.job = job | ||
|
|
||
| job.cancel() | ||
|
|
||
| assertThat(checker.isCancelled()).isTrue() | ||
| } | ||
|
|
||
| @Test | ||
| fun `a job that completes normally does not cancel the checker`() { | ||
| val job = Job() | ||
| val checker = JobCancelChecker(job) | ||
|
|
||
| job.complete() | ||
|
|
||
| assertThat(checker.isCancelled()).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `a cancelled job that is still running reports cancelled before it completes`() = | ||
| runBlocking<Unit> { | ||
| val parent = Job() | ||
| val gate = runUncancellableChild(parent) | ||
| val checker = JobCancelChecker(parent) | ||
| var fired = false | ||
| checker.invokeOnCancel { fired = true } | ||
|
|
||
| parent.cancel() | ||
|
|
||
| assertThat(parent.isCompleted).isFalse() | ||
| assertThat(checker.isCancelled()).isTrue() | ||
| assertThat(fired).isTrue() | ||
| gate.complete(Unit) | ||
| } | ||
|
|
||
| @Test | ||
| fun `a job assigned later that is cancelled while still running reports cancelled before it completes`() = | ||
| runBlocking<Unit> { | ||
| val parent = Job() | ||
| val gate = runUncancellableChild(parent) | ||
| val checker = JobCancelChecker() | ||
| var fired = false | ||
| checker.invokeOnCancel { fired = true } | ||
| checker.job = parent | ||
|
|
||
| parent.cancel() | ||
|
|
||
| assertThat(parent.isCompleted).isFalse() | ||
| assertThat(checker.isCancelled()).isTrue() | ||
| assertThat(fired).isTrue() | ||
| gate.complete(Unit) | ||
| } | ||
|
|
||
| @Test | ||
| fun `abortIfCancelled throws after the job is cancelled`() { | ||
| val job = Job() | ||
| val checker = JobCancelChecker(job) | ||
|
|
||
| job.cancel() | ||
|
|
||
| assertThrows(CancellationException::class.java) { checker.abortIfCancelled() } | ||
| } | ||
|
|
||
| @Test | ||
| fun `abortIfCancelled throws after the checker is cancelled`() { | ||
| val checker = JobCancelChecker(Job()) | ||
|
|
||
| checker.cancel() | ||
|
|
||
| assertThrows(CancellationException::class.java) { checker.abortIfCancelled() } | ||
| } | ||
|
|
||
| /** A plain child Job completes as soon as its parent is cancelled, so use a body that ignores cancellation. */ | ||
| private suspend fun runUncancellableChild(parent: Job): CompletableDeferred<Unit> { | ||
| val gate = CompletableDeferred<Unit>() | ||
| val started = CompletableDeferred<Unit>() | ||
| CoroutineScope(parent + Dispatchers.Default).launch { | ||
| withContext(NonCancellable) { | ||
| started.complete(Unit) | ||
| gate.await() | ||
| } | ||
| } | ||
| started.await() | ||
| return gate | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
common/src/test/java/com/itsaky/androidide/utils/KeyedDebouncingActionTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.itsaky.androidide.utils | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import kotlinx.coroutines.CompletableDeferred | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.SupervisorJob | ||
| import kotlinx.coroutines.awaitCancellation | ||
| import kotlinx.coroutines.cancel | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlinx.coroutines.withTimeout | ||
| import org.junit.Test | ||
| import kotlin.time.Duration.Companion.milliseconds | ||
|
|
||
| class KeyedDebouncingActionTest { | ||
| @Test | ||
| fun `rescheduling the same key cancels the running action's checker`() = | ||
| runBlocking { | ||
| val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) | ||
| val started = CompletableDeferred<Unit>() | ||
| val cancelled = CompletableDeferred<Unit>() | ||
| val debouncer = | ||
| KeyedDebouncingAction<String>( | ||
| scope = scope, | ||
| debounceDuration = 10.milliseconds, | ||
| action = { _, checker -> | ||
| checker.invokeOnCancel { cancelled.complete(Unit) } | ||
| started.complete(Unit) | ||
| awaitCancellation() | ||
| }, | ||
| ) | ||
|
|
||
| try { | ||
| debouncer.schedule("a") | ||
| withTimeout(2_000) { started.await() } | ||
| debouncer.schedule("a") | ||
|
|
||
| withTimeout(2_000) { cancelled.await() } | ||
| assertThat(cancelled.isCompleted).isTrue() | ||
| } finally { | ||
| scope.cancel() | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prevent a replaced job from cancelling the current job.
If the checker switches from job A to job B, cancelling A still calls
cancel()on the checker. That call cancels B and clears its binding. The callback remains registered because the setter discards itsDisposableHandle. (raw.githubusercontent.com)Dispose the old registration on replacement. Also make the callback's ownership check atomic with the cancellation transition so an in-flight callback cannot cancel B. Keep immediate notification when the current job is cancelled.