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
38
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
38 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 dee0285
test(common): release the JobCancelChecker test gate when an assertio…
itsaky-adfa 2d5b92c
fix(common): keep JobCancelChecker cancellation terminal across job a…
itsaky-adfa 898b808
fix(lsp-kotlin): propagate cancellation from the extract-variable pla…
itsaky-adfa ff29ed9
fix(lsp-kotlin): refuse an inline-variable plan on a stale pin
itsaky-adfa 753056d
fix(lsp-kotlin): wait out an edit's barrier before retrying a preempt…
itsaky-adfa 9cfeba0
test(lsp-kotlin): assert the injected failure in the barrier-lowering…
itsaky-adfa 54ea700
test(lsp-kotlin): observe the owed refresh after release without pinn…
itsaky-adfa 1751e28
test(lsp-kotlin): assert pinned text is unchanged until release
itsaky-adfa 947aae3
test(lsp-kotlin): check each in-body edit's reindex before the next edit
itsaky-adfa 4954269
test(lsp-kotlin): assert the tree text after the monitored in-place e…
itsaky-adfa b52fd29
fix(lsp-kotlin): reindex an in-block edit that can change an inferred…
itsaky-adfa 85d0a46
fix(lsp-kotlin): apply an edit deferred by a pin even when the releas…
itsaky-adfa 3f8d1f7
fix(lsp-kotlin): publish a full parse only into the open it was launc…
itsaky-adfa 1f2cdeb
style: spotless reformat, no functional change
itsaky-adfa 3a16acf
Merge branch 'stage' into perf/ADFA-6855-incremental-reparse
itsaky-adfa a03d280
docs(adr): describe the barrier wait before a retry and the release-t…
itsaky-adfa 02fc0cf
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
136 changes: 136 additions & 0 deletions
136
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,136 @@ | ||
| 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) | ||
| try { | ||
| var fired = false | ||
| checker.invokeOnCancel { fired = true } | ||
|
|
||
| parent.cancel() | ||
|
|
||
| assertThat(parent.isCompleted).isFalse() | ||
| assertThat(checker.isCancelled()).isTrue() | ||
| assertThat(fired).isTrue() | ||
| } finally { | ||
| gate.complete(Unit) | ||
| parent.join() | ||
| } | ||
| } | ||
|
|
||
| @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() | ||
| try { | ||
| var fired = false | ||
| checker.invokeOnCancel { fired = true } | ||
| checker.job = parent | ||
|
|
||
| parent.cancel() | ||
|
|
||
| assertThat(parent.isCompleted).isFalse() | ||
| assertThat(checker.isCancelled()).isTrue() | ||
| assertThat(fired).isTrue() | ||
| } finally { | ||
| gate.complete(Unit) | ||
| parent.join() | ||
| } | ||
| } | ||
|
|
||
| @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() } | ||
| } | ||
|
|
||
| @Test | ||
| fun `abortIfCancelled throws when a job is assigned after the checker was cancelled`() { | ||
| val checker = JobCancelChecker() | ||
| checker.cancel() | ||
|
|
||
| checker.job = Job() | ||
|
|
||
| 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.
Uh oh!
There was an error while loading. Please reload this page.