Skip to content

Commit a1ca7ee

Browse files
Merge branch 'stage' into ADFA-4959-gh-desktop-push-error
2 parents d984f8d + 85c52cf commit a1ca7ee

23 files changed

Lines changed: 1716 additions & 139 deletions

File tree

‎app/proguard-rules.pro‎

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
-dontnote **
55
-dontobfuscate
66

7+
# ADFA-3604: R8's optimize pass (inlining/method merging) can silently
8+
# retarget a call to the wrong method when it fails to parse Kotlin 2.3.0
9+
# metadata (see "R8: An error occurred when parsing kotlin metadata" in the
10+
# build log) -- observed corrupting calls to utils.TestModeUtilsKt.isTestMode
11+
# into calls to the unrelated, device-missing dalvik.system.VMRuntime.isTestMode,
12+
# crashing every release build on launch. Shrinking (dead-code removal) is
13+
# what actually cuts dex size; the optimize passes are the risky part given
14+
# this R8/Kotlin version mismatch, so disable only optimization.
15+
-dontoptimize
16+
717
-keep class javax.** { *; }
818
-keep class jdkx.** { *; }
919

@@ -19,6 +29,42 @@
1929
# Builder model implementations
2030
-keep class com.itsaky.androidide.builder.model.** { *; }
2131

32+
# lsp/kotlin registers its own IntelliJ project/application services -- some
33+
# by class name in lsp/kotlin/src/main/resources/META-INF/kt-lsp/kt-lsp.xml,
34+
# the rest via ::class literals in
35+
# lsp/kotlin/.../registrar/AnalysisApiServiceProviders.kt, which PicoContainer
36+
# then instantiates reflectively via each class's no-arg constructor. A
37+
# ::class literal doesn't count as an actual `new` call to R8, so it kept
38+
# stripping "unused" no-arg constructors one class at a time as each was
39+
# discovered on-device (ClassNotFoundException on DirectInheritorsProvider,
40+
# then a PicoInitializationException on ModuleDependentsProvider's missing
41+
# constructor). Keep the whole package rather than list every implementation
42+
# class in AnalysisApiServiceProviders.kt individually.
43+
-keep class com.itsaky.androidide.lsp.kotlin.compiler.services.** { *; }
44+
45+
# Kotlin Analysis API (bundled in subprojects/kotlin-analysis-api, used by the
46+
# Kotlin LSP). subprojects/kotlin-analysis-api/consumer-rules.pro keeps every
47+
# class this jar's own IntelliJ plugin XML descriptors and ServiceLoader
48+
# entries reference by name, but on-device testing kept surfacing distinct
49+
# reflection paths that narrow list didn't cover -- not just inside this jar,
50+
# but in other lsp/kotlin runtime dependencies too (Caffeine picks a cache
51+
# implementation from dozens of codegenned variant classes at runtime; a
52+
# protobuf-lite message field is resolved by name string; lsp/kotlin's own
53+
# kt-lsp.xml above; and a NullPointerException deep in IntelliJ's own
54+
# JavaCoreApplicationEnvironment bootstrap, verified absent on an unshrunk
55+
# debug build). Each fix was quick but the next gap kept appearing elsewhere
56+
# in the same dependency graph, so rather than keep discovering them one
57+
# on-device crash at a time, keep every runtime dependency lsp/kotlin pulls in
58+
# whole. This gives up the dex-size reduction for this whole dependency graph;
59+
# see ADFA-3604 for the size trade-off.
60+
-keep class org.jetbrains.kotlin.** { *; }
61+
-keep class com.github.benmanes.caffeine.** { *; }
62+
-keep class kotlin.reflect.** { *; }
63+
-keep class kotlin.script.** { *; }
64+
-keep class kotlinx.coroutines.internal.** { *; }
65+
-keep class one.util.streamex.** { *; }
66+
-keep class gnu.trove.** { *; }
67+
2268
# Eclipse
2369
-keep class org.eclipse.** { *; }
2470

@@ -66,10 +112,12 @@
66112
}
67113
-keep class com.itsaky.androidide.utils.DialogUtils { public <methods>; }
68114

69-
# APK Metadata
70-
-keep class com.itsaky.androidide.models.ApkMetadata { *; }
71-
-keep class com.itsaky.androidide.models.ArtifactType { *; }
72-
-keep class com.itsaky.androidide.models.MetadataElement { *; }
115+
# Gson model classes deserialized only via reflection (gson.fromJson(...,
116+
# X::class.java)), same "R8 strips the unreachable constructor" issue as
117+
# templates.impl.zip below. Covers OpenedFilesCache/OpenedFile (no prior
118+
# rule) as well as the APK metadata classes already listed individually.
119+
-keep class com.itsaky.androidide.models.** { *; }
120+
-keep class com.itsaky.androidide.lsp.debug.model.** { *; }
73121

74122
# Parcelable
75123
-keepclassmembers class * implements android.os.Parcelable {
@@ -88,6 +136,14 @@
88136

89137
-keep class com.itsaky.androidide.treesitter.** { *; }
90138

139+
# Protobuf lite: the generated runtime resolves message fields by name via
140+
# reflection (the info string baked into newMessageInfo()), so shrinking a
141+
# "field with no direct bytecode reference" breaks it at runtime with a
142+
# NoSuchFieldException (observed on SyncMetaModels$SyncMeta.projectModelInfo_).
143+
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
144+
<fields>;
145+
}
146+
91147
# Retrofit 2
92148
-dontwarn retrofit2.**
93149
-keep class retrofit2.** { *; }
@@ -101,15 +157,19 @@
101157
-keep interface okhttp3.** { *; }
102158
-dontwarn okhttp3.**
103159

104-
# Stat uploader
105-
-keep class com.itsaky.androidide.stats.** { *; }
106-
107160
# Gson
108161
-keep class * extends com.google.gson.TypeAdapter
109162
-keep class * implements com.google.gson.TypeAdapterFactory
110163
-keep class * implements com.google.gson.JsonSerializer
111164
-keep class * implements com.google.gson.JsonDeserializer
112165

166+
# Gson model classes: nothing calls `new TemplatesIndex(...)` directly --
167+
# only gson.fromJson(..., TemplatesIndex::class.java) does, via reflection.
168+
# With no traceable constructor call, R8 strips the constructor and Gson's
169+
# runtime then reports the class as abstract ("Failed to load template
170+
# archive ... Abstract classes can't be instantiated!").
171+
-keep class com.itsaky.androidide.templates.impl.zip.** { *; }
172+
113173
-keepclassmembers,allowobfuscation class * {
114174
@com.google.gson.annotations.SerializedName <fields>;
115175
}
@@ -143,9 +203,18 @@
143203
-keep class com.itsaky.androidide.plugins.** { *; }
144204
-keep interface com.itsaky.androidide.plugins.** { *; }
145205

146-
## Initial rules to enable when R8 is shrinking to address exceptions
147-
#-keep class com.sun.tools.jdi.** { *; }
148-
#-keep class com.sun.jdi.** { *; }
206+
## ADFA-3604: JDI's SocketAttachingConnector/SocketListeningConnector are
207+
## loaded via ServiceLoader (META-INF/services), which R8 can't trace, so it
208+
## stripped their no-arg constructors. This surfaced as
209+
## "ServiceConfigurationError: Provider ... could not be instantiated" ->
210+
## "java.lang.Error: no Connectors loaded" from VirtualMachineManagerImpl,
211+
## which the app then reports to the user as a generic "Network access
212+
## error" (the debug-connect failure handler always appends a network
213+
## suggestion regardless of cause) even though this has nothing to do with
214+
## network permissions. This is exactly the exceptions these rules were
215+
## anticipating -- enabling them now that shrinking is genuinely on.
216+
-keep class com.sun.tools.jdi.** { *; }
217+
-keep class com.sun.jdi.** { *; }
149218

150219
## R8 Kotlin metadata workaround for Kotlin 2.3.0 compatibility
151220
## Suppresses D8 errors when parsing kotlin metadata for StopWatch inline functions

‎build.gradle.kts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ buildscript {
6767
}
6868
}
6969

70+
// `jacocoAggregateReport` dependsOn every subproject's `testV8DebugUnitTest` and `sonarqube`
71+
// dependsOn that, so a hard test failure skips both - even under `--continue` - and the analysis
72+
// run uploads an empty coverage artifact with no Sonar analysis at all. That, not any individual
73+
// module's broken suite, is the only reason `ignoreFailures` exists here: keep test failures
74+
// non-fatal when the analysis chain is what was asked for, and let every ordinary build gate on them.
75+
val analysisRun =
76+
gradle.startParameter.taskNames.any {
77+
it.substringAfterLast(':') in setOf("sonar", "sonarqube", "jacocoAggregateReport")
78+
}
79+
7080
subprojects {
7181
plugins.apply("jacoco")
7282

@@ -78,14 +88,28 @@ subprojects {
7888
FDroidConfig.load(project)
7989

8090
tasks.withType<Test> {
81-
// Continue even if tests fail, so coverage data is written
82-
ignoreFailures = true
91+
ignoreFailures = analysisRun
92+
93+
// Gradle's default test-worker heap is 512m, too small for the Robolectric +
94+
// Kotlin Analysis API suites (:lsp:kotlin peaks near 240m and keeps growing).
95+
// Keep it explicit so the suites fail on a real regression, not on the default.
96+
maxHeapSize = "1g"
8397

8498
// Backstop: kill any individual Test task that runs longer than 10 minutes.
8599
// Prevents a single hung test JVM (e.g. the Tooling API child) from burning
86100
// the entire CI job budget.
87101
timeout.set(Duration.ofMinutes(10))
88102

103+
// A test worker's default working dir is the module directory, so an unpathed
104+
// -XX:+HeapDumpOnOutOfMemoryError drops a heap dump of up to maxHeapSize into the source
105+
// tree, untracked and not gitignored. Keep dumps under build/ instead, one per task.
106+
val heapDumpFile =
107+
layout.buildDirectory
108+
.file("test-heapdumps/$name.hprof")
109+
.get()
110+
.asFile
111+
doFirst { heapDumpFile.parentFile.mkdirs() }
112+
89113
// JPMS opens required by the unit-test stack on JDK 17+:
90114
// - jdk.unsupported/sun.misc: HiddenApiBypass.<clinit> reflectively
91115
// resolves sun.misc.Unsafe; without this the IDEApplication
@@ -105,6 +129,14 @@ subprojects {
105129
"--add-opens=java.base/java.util=ALL-UNNAMED",
106130
"--add-opens=java.base/java.util.concurrent=ALL-UNNAMED",
107131
"--add-opens=jdk.unsupported/sun.misc=ALL-UNNAMED",
132+
// An OutOfMemoryError inside a test deadlocks Gradle's TestWorker: the
133+
// OOM unwinds the runQueue.take() loop, whose finally needs the TestWorker
134+
// monitor that the in-flight stop() already holds while blocked on
135+
// runQueue.put() (capacity 1). The worker then never exits and the build
136+
// hangs. Exiting on the first OOM turns that hang into a task failure.
137+
"-XX:+ExitOnOutOfMemoryError",
138+
"-XX:+HeapDumpOnOutOfMemoryError",
139+
"-XX:HeapDumpPath=${heapDumpFile.absolutePath}",
108140
)
109141

110142
// Attach jacoco agent
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# 0010. Kotlin navigation resolves via the Analysis API, not the symbol index
2+
3+
- **Status:** Proposed
4+
- **Date:** 2026-07-27
5+
- **Deciders:** Code On The Go team
6+
7+
## Context
8+
9+
The K2 Kotlin LSP carries a substantial symbol-indexing stack: `JvmSymbolIndex` over library jars, `KtFileMetadataIndex` over source files, and `KtSymbolIndex` tying them together, all SQLite-backed and refreshed by background workers. Completion and add-import lean on it heavily, and it is the cheap way to answer "what symbols named X exist in this workspace".
10+
11+
Navigation features - go-to-definition (ADFA-4823) and find usages (ADFA-4824) - look superficially similar: given a name, find where it lives. A reader who has just read the completion code will reasonably expect navigation to query the same index.
12+
13+
It cannot. The index stores names, kinds, visibility, and containing-class metadata, but **no source offsets** - `JvmSymbol`/`JvmSymbolInfo` have nowhere to put a declaration's position, and `KtFileMetadata` records only a file path plus its symbol keys. An index hit narrows the answer to a file at best; something still has to parse that file to find where in it the declaration sits. Worse, the index answers by *name*, while navigation must answer by *resolution* - which of the seven overloads of `foo`, through this module's dependency graph and content scopes, does this call site actually bind to.
14+
15+
## Decision
16+
17+
**Kotlin navigation resolves through the Analysis API and PSI only. The symbol indexes are not consulted.**
18+
19+
- Given a caret offset, find the reference, then `analyze(ktFile) { reference.mainReference.resolveToSymbols() }`, falling back to `resolveToCall()` for convention references (`a + b`, `a[i]`, `by lazy`, destructuring, `for` loops) that have no name reference to resolve.
20+
- Convert each resolved symbol to its PSI declaration, and the declaration to a file plus a name-identifier range.
21+
- Correctness of scoping - module dependencies, content scopes, visibility - is delegated to the analysis session rather than reimplemented over index rows.
22+
23+
## Consequences
24+
25+
**Positive**
26+
27+
- Results are *resolved*, not name-matched: the right overload, the right receiver, the right module.
28+
- Module dependency graphs and content scopes are respected by construction. No second, divergent notion of "which module can see what" to keep in sync with `ProjectStructureProvider`.
29+
- One code path for all three resolution scopes (same-file, inter-file, inter-module), so the test matrix covers behaviour rather than plumbing.
30+
31+
**Negative / costs**
32+
33+
- **Navigation requires a live analysis session.** Before one exists, go-to-definition returns nothing; it cannot degrade to an index-only answer. The user-facing gap - no way to say "still indexing" rather than "not found" - is cross-cutting across every LSP feature and remains unsolved.
34+
- Resolving a cross-module target means building PSI for the target file, which is more work than an index row lookup. Acceptable for a user-initiated, cancellable, one-at-a-time request; it would not be acceptable for a per-keystroke feature.
35+
- Symbols with no source PSI - stdlib, framework, any library jar - are simply unreachable. Library navigation would need decompilation or source-jar extraction, neither of which exists in the tree.
36+
37+
## Alternatives considered
38+
39+
- **Index-first, analysis fallback** - rejected: the index has no declaration offsets, so it can only narrow to a file and a second pass must parse it anyway. Extra machinery, no saved work, and a name-matched shortlist that can disagree with what the call site actually binds to.
40+
- **Index-only for cross-module targets** - rejected: two divergent code paths for the same user action, and cross-module results would be position-less, so they could not be selected in the editor.
41+
- **Extend the index to store declaration offsets** - rejected for now: offsets go stale on every edit, so the index would need write-through invalidation on document change to stay trustworthy for navigation, and it still would not answer overload resolution. Revisit only if navigation latency becomes a measured problem.
42+
43+
## Related
44+
45+
- [docs/features/kotlin-goto-definition.md](../features/kotlin-goto-definition.md) - the first feature built on this decision
46+
- [ADR 0001](0001-prefer-room-for-persistence.md) - persistence choices for the indexes this ADR declines to use

‎docs/adr/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ Format is lightweight **MADR / Nygard**: Context → Decision → Consequences
2323
| [0007](0007-strictmode-whitelist-engine.md) | Enforce StrictMode via a custom whitelist engine | Proposed |
2424
| [0008](0008-retain-androidide-namespace.md) | Retain the `com.itsaky.androidide` namespace after rebrand | Proposed |
2525
| [0009](0009-jetpack-compose-for-new-ui.md) | Build new UI in Jetpack Compose, not XML Views | Proposed |
26+
| [0010](0010-navigation-resolves-via-analysis-api.md) | Kotlin navigation resolves via the Analysis API, not the symbol index | Proposed |

0 commit comments

Comments
 (0)