Skip to content

ADFA-7115: Analyze the selected variant's source sets - #2269

Merged
itsaky-adfa merged 1 commit into
stagefrom
fix/ADFA-7115-variant-sources
Nov 20, 2026
Merged

itsaky-adfa merged 1 commit into
stagefrom
fix/ADFA-7115-variant-sources

Conversation

@itsaky-adfa

@itsaky-adfa itsaky-adfa commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

ADFA-7115

Stack 4/5.

Both language servers analyze the selected variant's source sets (src/debug, src/testDebug, ...) and switch with the variant. Also fixes Java go-to-definition into another file after a completion.

Tested: unit tests (Java and Kotlin completion, diagnostics, definition per variant), spotlessCheck.

@itsaky-adfa itsaky-adfa self-assigned this Nov 16, 2026
@atlassian

atlassian Bot commented Nov 16, 2026

Copy link
Copy Markdown

To enable Code Reviewer, link your GitHub account to your Atlassian account.

This is a one-time task that takes less than a minute. Once your account is linked, resubmit the pull request to trigger a code review.

@itsaky-adfa
itsaky-adfa added this pull request to stack #2276 November 17, 2026 13:58
@itsaky-adfa
itsaky-adfa marked this pull request as ready for review November 17, 2026 13:59

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: d011d6b5-d108-4622-803f-b3add5970671
Commits

Reviewing files that changed from the base of the PR and between 3df9b17 and 8a4f3ad.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Release notes: Variant source set analysis (ADFA-7115)

Summary

  • Both language servers now analyze the source sets of the selected build variant, such as src/debug and src/testDebug.
  • Source directories follow the selected variant. Switching variants changes the main source directories.
  • Java go-to-definition now works for a class in another file after a completion request.
  • Kotlin module layouts include only source directories that exist.

Java

  • AndroidModule.getSourceDirectories adds Java and Kotlin directories from the selected variant's source providers.
  • RemoteDefinitionProvider.doFindDefinition compiles the current file together with otherFile. It then resolves the element at the request position. It returns an empty list when the element or tree path is unavailable. It logs an error for a missing tree path.

Kotlin

  • CompilationEnvironment replaces symbolVisibilityChecker with unimportedSymbolIndexes (source, generated, then library indexes).
  • CompilationEnvironment adds diagnosticsFor(path, cancelChecker). The debounced analyzer uses this method.
  • KotlinDiagnosticProvider returns a DiagnosticsOutcome (Collected, Superseded, Unavailable).
  • Completion, signature help, and ContextResolver now use AbstractCompilationEnvironment.
  • KotlinModuleLayout ignores source roots that do not exist. Creating a missing test source directory changes the layout.

Tests and fixtures

  • Added Java VariantSourceSetsTest and DefinitionAfterCompletionTest.
  • Added Kotlin VariantSourceSetsTest and a module-layout test.
  • Added variantLayout and related fixture helpers.
  • Added ArtifactScopeSourcesTest cases for variant-based main and unit-test roots.
  • Added test-project resources for debug and release VariantConfig classes and related templates.

Risks and best-practice concerns

  • Public Kotlin API changes. CompilationEnvironment.symbolVisibilityChecker is removed. collectDiagnosticsFor changes its return type and context receiver. Any caller outside this change set breaks at compile time.
  • Changed diagnostic flow. When diagnostics are superseded, doAnalyze no longer reschedules the file. It returns Superseded. Confirm that no diagnostics are lost when a document changes quickly.
  • Definition performance. RemoteDefinitionProvider now compiles the declaring file on each request. This adds latency and memory use for large projects. The commit says the variant definition test depends on this behavior. It does not describe a root-cause fix for the reused javac context.
  • Module layout behavior. Filtering out missing directories changes which modules exist. Watch for regressions when source directories are created or removed after sync.
  • Test fixture visibility. findKotlinStdlibJar changed from private to internal. This widens test-only access.
  • Intentional test errors. VariantUse_template.java contains RELEASE_ONLY_FIELD, which should be flagged. Do not treat its diagnostic as a defect.

Verification status

  • The author reports manual testing of Java and Kotlin completion, diagnostics, and definition per variant. The author also reports running spotlessCheck.
  • CI, build, and test results for the current head are not available.
  • The file-level details in this summary come from the AI-generated change summary. They were not checked against the diff.

The changes add selected-variant Java and Kotlin source roots, adjust Kotlin module and diagnostic handling, and update Java cross-file definition lookup. New tests cover variant-specific language-server behavior and Java definition lookup after completion.

Changes: Selected Variant Source Sets

Layer / File(s) Summary
Selected variant source roots
subprojects/projects/src/main/java/.../AndroidModule.kt, subprojects/projects/src/test/java/.../ArtifactScopeSourcesTest.kt, lsp/kotlin/src/main/java/.../KotlinModuleLayout.kt, lsp/kotlin/src/test/java/.../KotlinModuleLayoutTest.kt
AndroidModule.getSourceDirectories includes Java and Kotlin source directories from the selected variant. KotlinModuleLayout includes only existing source roots, and the tests check variant selection and layouts after a directory is created.
Kotlin analysis and completion
lsp/kotlin/src/main/java/.../compiler/*, lsp/kotlin/src/main/java/.../diagnostic/KotlinDiagnosticProvider.kt, lsp/kotlin/src/main/java/.../KotlinLanguageServer.kt, lsp/kotlin/src/main/java/.../completion/KotlinCompletions.kt, lsp/kotlin/src/main/java/.../signaturehelp/KotlinSignatureHelp.kt, lsp/kotlin/src/main/java/.../utils/ContextResolver.kt
The abstract compilation environment now provides symbol visibility and unimported-symbol indexes. Diagnostic collection reports collected, superseded, or unavailable outcomes. Related Kotlin language-server operations use the abstract environment.
Variant-aware fixtures and tests
lsp/kotlin/src/test/java/.../fixtures/*, lsp/kotlin/src/test/java/.../VariantSourceSetsTest.kt, lsp/java/src/test/java/.../VariantSourceSetsTest.kt, testing/resources/test-project/app/src/{debug,release}/java/.../VariantConfig.java, testing/resources/test-project/app/src/main/resources/variants/*
Kotlin test fixtures can use a module layout and index its source roots. Java and Kotlin tests check that diagnostics, completion, and definition lookup use the selected variant’s sources.

Java Cross-File Definition Lookup

Layer / File(s) Summary
Cross-file definition resolution
lsp/java/src/main/java/.../definition/RemoteDefinitionProvider.kt, lsp/java/src/test/java/.../providers/DefinitionAfterCompletionTest.kt, testing/resources/test-project/app/src/main/resources/definition/*
Remote definition lookup compiles the current file with the other file and returns a location when the element and its tree path are available. The test checks lookup of MainActivity after completion compiles it.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant KotlinLanguageServer
  participant CompilationEnvironment
  participant KotlinDiagnosticProvider
  KotlinLanguageServer->>CompilationEnvironment: diagnosticsFor(path, cancelChecker)
  CompilationEnvironment->>KotlinDiagnosticProvider: collectDiagnosticsFor(path, cancelChecker)
  KotlinDiagnosticProvider-->>CompilationEnvironment: Collected, Superseded, or Unavailable
  CompilationEnvironment-->>KotlinLanguageServer: DiagnosticResult or NO_UPDATE
Loading

Suggested reviewers: itsaky, daniel-adfa, hal-eisen-adfa

Merge Risk: Minimal · previous review 847fb

This change makes both language servers analyze the selected variant's source sets, and it fixes Java go-to-definition after a completion. No concrete defects were found in the reviewed code, and new tests cover completion, diagnostics and definition per variant. Merge risk looks low.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the ADFA-7115 change: both language servers analyze the selected variant's source sets. The changeset adds variant-aware source directories in AndroidModule, Kotlin module layout, and …
Description check Passed The description links ADFA-7115 and states that both language servers analyze the selected variant's source sets and switch with the variant. It also mentions the Java go-to-definition fix after compl…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the ADFA-7115 change: both language servers analyze the selected variant's source sets. The changeset adds variant-aware source directories in AndroidModule, Kotlin module layout, and LSP tests for debug/release variant lookups, so the title matches the main change. It omits the Java go-to-definition fix, which is acceptable.

Full details: Description check

Explanation

The description links ADFA-7115 and states that both language servers analyze the selected variant's source sets and switch with the variant. It also mentions the Java go-to-definition fix after completion, which matches RemoteDefinitionProvider and the definition test. It lists the testing performed. The description relates directly to the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the source roots at dawn
Debug leaves appear where the paths lead on
Release stays outside the selected set
A definition hops to its target yet
The tests mark each branch with care
Then whiskers twitch at clean results there

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 113f7aac-b332-4a1e-9045-478e2ed65361
Commits

Reviewing files that changed from the base of the PR and between f197210 and 847fbd8.

Files selected for processing: 26

  • lsp/java/src/main/java/com/itsaky/androidide/lsp/java/providers/definition/RemoteDefinitionProvider.kt
  • lsp/java/src/test/java/com/itsaky/androidide/lsp/java/VariantSourceSetsTest.kt
  • lsp/java/src/test/java/com/itsaky/androidide/lsp/java/providers/DefinitionAfterCompletionTest.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/KotlinLanguageServer.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/AbstractCompilationEnvironment.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/CompilationEnvironment.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/KotlinModuleLayout.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/completion/KotlinCompletions.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/diagnostic/KotlinDiagnosticProvider.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/signaturehelp/KotlinSignatureHelp.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/utils/ContextResolver.kt
  • lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/VariantSourceSetsTest.kt
  • lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/compiler/KotlinModuleLayoutTest.kt
  • lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/fixtures/KtLspTest.kt
  • lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/fixtures/KtLspTestEnvironment.kt
  • lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/fixtures/KtLspTestRule.kt
  • lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/fixtures/VariantProjectFixtures.kt
  • subprojects/projects/src/main/java/com/itsaky/androidide/projects/api/AndroidModule.kt
  • subprojects/projects/src/test/java/com/itsaky/androidide/projects/api/ArtifactScopeSourcesTest.kt
  • testing/resources/test-project/app/src/debug/java/com/itsaky/test/app/variant/VariantConfig.java
  • testing/resources/test-project/app/src/main/resources/definition/CompletesMainActivity_template.java
  • testing/resources/test-project/app/src/main/resources/definition/ReferencesMainActivity_template.java
  • testing/resources/test-project/app/src/main/resources/variants/VariantDefinition_template.java
  • testing/resources/test-project/app/src/main/resources/variants/VariantMembers_template.java
  • testing/resources/test-project/app/src/main/resources/variants/VariantUse_template.java
  • testing/resources/test-project/app/src/release/java/com/itsaky/test/app/variant/VariantConfig.java

Included review availability: This review used your included allowance. 1 included review remains after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

@itsaky-adfa
itsaky-adfa force-pushed the fix/ADFA-7115-variant-sources branch 2 times, most recently from 3b89da9 to 3df9b17 Compare November 20, 2026 13:47
Base automatically changed from fix/ADFA-7115-kotlin-scopes to stage November 20, 2026 14:10
Also fixes Java go-to-definition into another file after a completion: the
reused javac context keeps a class an earlier request compiled without its
tree, so RemoteDefinitionProvider now compiles the declaring file with the
current one. The variant definition test depends on it.
@itsaky-adfa
itsaky-adfa force-pushed the fix/ADFA-7115-variant-sources branch from 3df9b17 to 8a4f3ad Compare November 20, 2026 14:10
@itsaky-adfa
itsaky-adfa merged commit a42b3d3 into stage Nov 20, 2026
5 checks passed
@itsaky-adfa
itsaky-adfa deleted the fix/ADFA-7115-variant-sources branch November 20, 2026 14:32
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