Skip to content

Add suppress warnings & remove redudant cast quick-fix code action - #8646

Draft
zielinsky wants to merge 4 commits into
scalameta:main-v2from
zielinsky:metalsv2/supress-warnings
Draft

Add suppress warnings & remove redudant cast quick-fix code action#8646
zielinsky wants to merge 4 commits into
scalameta:main-v2from
zielinsky:metalsv2/supress-warnings

Conversation

@zielinsky

@zielinsky zielinsky commented Jul 6, 2026

Copy link
Copy Markdown
Member

Part of #8502

Summary by CodeRabbit

  • New Features

    • Added a new Java quick fix to insert or update @SuppressWarnings(...) for compiler warnings.
    • Added a new user setting to control which Java lint warnings are enabled.
    • Java code actions now include the suppress-warnings fix.
  • Bug Fixes

    • Improved Java target resolution so compiler actions work more reliably across target types.
    • Suppress-warnings fixes now handle existing annotations more intelligently and avoid duplicate entries.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 50ea71f0-7486-4033-8a4c-2c5fc2baaec9

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
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions suppress-warnings, but also claims a redundant-cast quick-fix that is not part of this changeset. Retitle it to describe the actual change, e.g. "Add suppress-warnings quick-fix code action".
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch 3 times, most recently from 0d30058 to 3af8b1e Compare July 6, 2026 13:51

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala (1)

436-452: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Naming ambiguity: field javaTarget is typed JvmTarget, then pattern-matched against JavaTarget.

This isn't introduced by this diff, but the changed lines make the ambiguity more visible: javaTarget: JvmTarget (line 437) is matched with case j: JavaTarget => j.options (line 450). Consider renaming the field (e.g. target: JvmTarget) to reduce confusion now that the surrounding PR stack explicitly distinguishes JavaTarget from JvmTarget.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala`
around lines 436 - 452, The `JavaLazyCompiler` field name is ambiguous because
`javaTarget` is typed as `JvmTarget` but later pattern-matched against
`JavaTarget` in `newCompiler`. Rename the field to something neutral like
`target` (and update its uses such as `buildTargetId` and the `javaTarget match`
block) so the `JavaTarget` vs `JvmTarget` distinction is clear and the code is
easier to read.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala`:
- Around line 91-112: Update warningName in SuppressWarnings so it only returns
a suppressible category for javac warnings, not ERROR diagnostics; gate the
lookup on diagnostic severity before calling warningNameFrom. Also tighten
warningNameFrom to avoid substring matches by using word-boundary/whole-token
matching instead of plain text.contains, and ensure overlapping lint names are
resolved deterministically so cases like unchecked cast map to the correct
category.

---

Nitpick comments:
In
`@metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala`:
- Around line 436-452: The `JavaLazyCompiler` field name is ambiguous because
`javaTarget` is typed as `JvmTarget` but later pattern-matched against
`JavaTarget` in `newCompiler`. Rename the field to something neutral like
`target` (and update its uses such as `buildTargetId` and the `javaTarget match`
block) so the `JavaTarget` vs `JvmTarget` distinction is clear and the code is
easier to read.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 64c263cf-77b1-49f1-a005-7a55602498a2

📥 Commits

Reviewing files that changed from the base of the PR and between e862680 and 0d30058.

📒 Files selected for processing (7)
  • metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala
  • metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala
  • metals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scala
  • mtags-interfaces/src/main/java/scala/meta/infra/FeatureFlag.java
  • tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala
💤 Files with no reviewable changes (1)
  • mtags-interfaces/src/main/java/scala/meta/infra/FeatureFlag.java

@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch from 3af8b1e to b217fe0 Compare July 6, 2026 16:18

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unit/src/test/scala/tests/InfraSuite.scala (1)

15-22: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Avoid leaking enabledFlags between suites. SuppressWarningsLspSuite.beforeAll() mutates a shared singleton before calling super.beforeAll(), so a setup failure can leave JAVAC_OPTIONS enabled for later suites. Move the toggle into a fixture/try-finally teardown or reset the set centrally.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/src/test/scala/tests/InfraSuite.scala` around lines 15 - 22, The
shared TestingInfra.enabledFlags set is being mutated by
SuppressWarningsLspSuite.beforeAll() without guaranteed cleanup, so a failed
setup can leak state into later suites. Update the test setup to either use a
fixture or wrap the toggle in a try-finally teardown that always removes the
JAVAC_OPTIONS flag, or centralize reset logic for TestingInfra.enabledFlags so
each suite starts from a clean state. Use the existing TestingInfra singleton
and SuppressWarningsLspSuite.beforeAll() as the main places to apply the fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tests/unit/src/test/scala/tests/InfraSuite.scala`:
- Around line 15-22: The shared TestingInfra.enabledFlags set is being mutated
by SuppressWarningsLspSuite.beforeAll() without guaranteed cleanup, so a failed
setup can leak state into later suites. Update the test setup to either use a
fixture or wrap the toggle in a try-finally teardown that always removes the
JAVAC_OPTIONS flag, or centralize reset logic for TestingInfra.enabledFlags so
each suite starts from a clean state. Use the existing TestingInfra singleton
and SuppressWarningsLspSuite.beforeAll() as the main places to apply the fix.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e08126e6-9956-4f39-94cd-b85abb70e10d

📥 Commits

Reviewing files that changed from the base of the PR and between 3af8b1e and b217fe0.

📒 Files selected for processing (7)
  • metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala
  • metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala
  • metals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scala
  • tests/unit/src/test/scala/tests/InfraSuite.scala
  • tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala
🚧 Files skipped from review as they are similar to previous changes (6)
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala
  • metals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scala
  • metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
  • tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala
  • metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala

@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch 4 times, most recently from 5e375ac to 249d4f9 Compare July 9, 2026 10:19

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala (1)

802-812: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider documenting the concurrent diagnostics-wait pattern.

The diagnosticsPublished = server.awaitNextDiagnostics(...) assignment before _ <- server.didFocus(path) is a deliberate pattern to register the diagnostics handler before the focus event triggers publishing. A brief comment would help future readers understand why the future is created here rather than inline with <-.

📝 Suggested comment
       _ <- server.didOpen(path)
+      // Register the diagnostics handler before didFocus so diagnostics
+      // triggered by the focus event are captured.
       diagnosticsPublished =
         server.awaitNextDiagnostics(
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala`
around lines 802 - 812, The diagnostics wait is intentionally started before the
focus event to avoid missing the publish, so document this concurrent pattern in
the test flow around the diagnosticsPublished assignment and server.didFocus
call. Add a brief comment near the awaitNextDiagnostics setup in
SuppressWarningsLspSuite to explain that the handler must be registered first,
then the focus event can trigger diagnostics, and keep the existing sequencing
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala`:
- Around line 802-812: The diagnostics wait is intentionally started before the
focus event to avoid missing the publish, so document this concurrent pattern in
the test flow around the diagnosticsPublished assignment and server.didFocus
call. Add a brief comment near the awaitNextDiagnostics setup in
SuppressWarningsLspSuite to explain that the handler must be registered first,
then the focus event can trigger diagnostics, and keep the existing sequencing
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 67e22879-e85c-4937-a673-59bcb6707da5

📥 Commits

Reviewing files that changed from the base of the PR and between b217fe0 and 249d4f9.

📒 Files selected for processing (9)
  • metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala
  • metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
  • metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala
  • metals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scala
  • tests/unit/src/test/scala/tests/InfraSuite.scala
  • tests/unit/src/test/scala/tests/UserConfigurationSuite.scala
  • tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala
🚧 Files skipped from review as they are similar to previous changes (6)
  • tests/unit/src/test/scala/tests/InfraSuite.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala
  • metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala
  • metals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scala
  • metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala

@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch from 249d4f9 to f79fc10 Compare July 9, 2026 13:52
@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch from c9a3884 to e6255ce Compare July 9, 2026 22:34
@zielinsky zielinsky changed the title Add suppress warnings quick-fix code action Add suppress warnings & remove redudant cast quick-fix code action Jul 9, 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.

1 participant