Skip to content

Support suggested fixes for error and warning reporting (#2551)#2955

Closed
HMH-3080 wants to merge 1 commit into
google:mainfrom
HMH-3080:feature/suggested-fixes-2551
Closed

Support suggested fixes for error and warning reporting (#2551)#2955
HMH-3080 wants to merge 1 commit into
google:mainfrom
HMH-3080:feature/suggested-fixes-2551

Conversation

@HMH-3080

Copy link
Copy Markdown

Closes #2551 — Support suggested fixes

Summary

Adds KSPSuggestedFix to KSP so processors can suggest replacement code alongside error/warning messages. This enables IDE tools (IntelliJ/Android Studio) to offer Quick Fixes directly from KSP diagnostics, similar to how Android Lint works.

Changes

New API (:api)

  • KSPSuggestedFix — new data class carrying replacementText and optional description
  • KSPLogger — added default warn(message, symbol, fix) and error(message, symbol, fix) overloads (backward compatible)

Logger implementations

  • KspGradleLogger — overrides warn/error with fix, prints as:
    w: [ksp] <message> -> Suggested Fix (<desc>): [<replacement>]
  • CommandLineKSPLogger — same, writes to System.err with Warning: / Error: prefix

Bug fix (:kotlin-analysis-api)

  • KotlinSymbolProcessing — logger wrapper was missing overrides for the new fix overloads, so hasError was never set when calling logger.error(..., fix). Fixed by adding the missing error/warn overrides with proper hasError tracking.

API signature (:api)

  • Updated api.base with component1(), component2(), copy() for KSPSuggestedFix

Tests

  • Unit tests: KspGradleLoggerTest (4 tests) + CommandLineKSPLoggerTest (4 tests)
  • End-to-end test: SuggestedFixProcessor + suggestedFix.kt test data — validates the full pipeline (processor → logger → exit code)
  • All tests pass for both AA and Psi configurations

Usage example

env.logger.error(
    "This annotation is deprecated",
    declaration,
    KSPSuggestedFix("@NewAnnotation", "Replace with @NewAnnotation")
)

@google-cla

google-cla Bot commented May 20, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@jaschdoc

jaschdoc commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Hi thank you for the PR! Your contribution is much appreciated, however, supporting suggested fixes is not a top priority at the moment and I'm not sure this design is quite what we need even though there are some good ideas here. I'm going to close this PR, but feel free to propose a design in the linked issue that we can iterate on.

@jaschdoc jaschdoc closed this Jun 3, 2026
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.

Support suggested fixes

2 participants