Skip to content

ADFA-4747: Fix Add-import code action not appearing on unresolved references#1547

Open
itsaky-adfa wants to merge 4 commits into
stagefrom
feat/ADFA-4747
Open

ADFA-4747: Fix Add-import code action not appearing on unresolved references#1547
itsaky-adfa wants to merge 4 commits into
stagefrom
feat/ADFA-4747

Conversation

@itsaky-adfa

@itsaky-adfa itsaky-adfa commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Jira: ADFA-4747

What & why

The "Add import" code action (shipped in ADFA-3754) never appeared on an unresolved-reference diagnostic - dead since it shipped. KtSymbolIndex.findSymbolBySimpleName ended with Sequence.take(limit) and its only caller passed limit = 0, so take(0) returned empty and prepare() always went invisible.

  1. Fix the dead action - treat limit <= 0 as unbounded, honouring the ReadableIndex.query contract. Extract computeImportCandidates (non-suspend, runCatching, KtFile before project.read); drop the no-op CMD_FORMAT_CODE.
  2. No main-thread I/O in prepare() - decide from the in-memory unresolvedReference marker; index resolution moves entirely to the background execAction.
  3. Surface the empty case - "No imports found" (flashError) when a shown action resolves nothing.

Tests

:lsp:kotlin:testV7DebugUnitTest --tests AddImportActionTest 5/5 (incl. the take(0)-unbounded regression guard); EditExtsTest covers sorted-insert/dedup; :lsp:kotlin:assembleV8Debug builds.

Merge gate (manual QA)

On-device: "No imports found" on a typo; single-candidate auto-apply vs multi-candidate picker; no main-thread jank.

Follow-ups (out of scope)

  • insertImport does not dedup a concrete import already covered by a wildcard (no impact today).
  • Uniform long-press/tooltip help across the Kotlin code actions.

Supersedes the PR originally opened under ADFA-4610 (that subtask tracks the original feature, delivered via ADFA-3754); the same commits are re-attached here under the correctly-scoped bug ADFA-4747.

…nces

AddImportAction.prepare() gated visibility on findSymbolBySimpleName(name, 0),
but the helper ended with Sequence.take(limit) and take(0) returns empty, so
the action was invisible for every unresolved-reference diagnostic - dead since
ADFA-3754. Treat limit <= 0 as unbounded, honoring the documented
ReadableIndex.query contract the helper was violating.

Also extract hasImportableClassifier and a non-suspend computeImportCandidates
(runCatching, KtFile fetched before project.read) for testability and
crash-safety, and drop the no-op CMD_FORMAT_CODE. Adds AddImportActionTest
(visibility-gate regression) and EditExtsTest.
Replace the SQLite-backed visibility gate with an in-memory check on the
unresolved-reference marker. prepare() runs synchronously on the UI thread
during menu build, so resolving against the symbol index there was
main-thread disk I/O; that resolution now happens only in the background
execAction.
@itsaky-adfa itsaky-adfa self-assigned this Jul 17, 2026
@itsaky-adfa
itsaky-adfa requested a review from a team July 17, 2026 14:47

@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 Jul 17, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@itsaky-adfa, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 20 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 752e061e-453f-4206-bece-860093250b13

📥 Commits

Reviewing files that changed from the base of the PR and between 8077407 and bcbc6ea.

📒 Files selected for processing (5)
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/actions/AddImportAction.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/KtSymbolIndex.kt
  • lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/actions/AddImportActionTest.kt
  • lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/utils/EditExtsTest.kt
  • resources/src/main/res/values/strings.xml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ADFA-4747

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
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.

1 participant