Skip to content

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

Open
zielinsky wants to merge 8 commits into
scalameta:main-v2from
zielinsky:metalsv2/supress-warnings
Open

Add suppress warnings & remove redudant cast quick-fix code action#8646
zielinsky wants to merge 8 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 Java quick fixes to remove redundant casts and suppress compiler warnings.
    • Suppression fixes support classes, methods, constructors, fields, and local variables.
    • Improved Java compiler option handling and Java-target detection.
  • Bug Fixes

    • Improved formatting when applying Java annotations and removing casts.
  • Tests

    • Added comprehensive coverage for Java quick fixes and compiler option behavior.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Adds Java quick fixes for redundant casts and warning suppression. Adds configurable Java lint options, integrates them into Java compiler creation, and updates Java target resolution. Adds unit and LSP coverage for the new behavior.

Changes

Java Quick Fixes

Layer / File(s) Summary
Redundant cast quick fix
metals/src/main/scala/scala/meta/internal/metals/codeactions/RemoveRedundantCast.scala
Adds a Java action that removes redundant casts from matching javac diagnostics.
Suppress-warnings detection
metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala
Adds diagnostic filtering, warning-name derivation, and enclosing Java member resolution.
Suppress-warnings annotation edits
metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala
Adds insertion and update edits for @SuppressWarnings annotations.
Quick-fix wiring and variable lookup
metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala, metals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scala
Registers both Java actions and expands variable lookup to declaration ranges when requested.
Java quick-fix LSP coverage
tests/unit/src/test/scala/tests/codeactions/*, tests/unit/src/test/scala/tests/InfraSuite.scala
Adds LSP tests for redundant-cast removal and warning suppression across Java declarations and expressions.

Java Lint Configuration

Layer / File(s) Summary
Java lint configuration
metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala
Adds validated JavaLintOptions and the java-lint-options configuration setting.
Java lint configuration tests
tests/unit/src/main/scala/tests/BaseLspSuite.scala, tests/unit/src/test/scala/tests/UserConfigurationSuite.scala
Updates test configuration and verifies parsing, validation, serialization, and option listing.
Java compiler target and lint integration
metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala, metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
Passes configured lint options to Java compilers and prefers Java build targets with a JVM-target fallback.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant CodeActionProvider
  participant SuppressWarnings
  participant JavaTrees
  participant Buffers
  Client->>CodeActionProvider: request Java code actions
  CodeActionProvider->>SuppressWarnings: process diagnostics
  SuppressWarnings->>Buffers: read document text
  SuppressWarnings->>JavaTrees: resolve enclosing member
  JavaTrees-->>SuppressWarnings: return Java element
  SuppressWarnings-->>CodeActionProvider: return TextEdit code action
  CodeActionProvider-->>Client: return available action
Loading

Possibly related PRs

Suggested reviewers: tgodzik

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: the new suppress-warnings and redundant-cast quick-fix code actions.
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.
✨ 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
@zielinsky
zielinsky marked this pull request as ready for review August 6, 2026 20:43
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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: 2

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

621-719: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add a runtime-JDK guard for JDK-only lint cases.

These fixtures require newer compiler diagnostics: this-escape needs JDK 21, value-based class synchronization needs JDK 16, and obsolete strictfp needs JDK 17. On older CI runtimes, checkSuppressWarnings waits for diagnostics that do not exist. Guard these cases with a Java-version assume, or split the suite by JDK versions.

🤖 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 621 - 719, Add Java runtime-version assumptions to the
JDK-dependent cases in checkSuppressWarnings: require JDK 17+ for
strictfp-method, JDK 16+ for synchronization-method, and JDK 21+ for
this-escape-constructor. Keep the existing fixtures and assertions unchanged,
and leave the text-blocks-method case unguarded unless its diagnostics also
require a version check.
🤖 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/UserConfiguration.scala`:
- Line 559: Update the Java lint options default formatting near
JavaLintOptions.default so each option value is quoted before joining, producing
a valid JSON array of strings such as ["cast","deprecation",...].
- Around line 50-60: Remove "this-escape" from the allValues used to construct
JavaLintOptions.default, while preserving it in allowed if user configuration
should still accept it. Ensure the default lint flags remain compatible with
Java 11/17.

---

Nitpick comments:
In `@tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala`:
- Around line 621-719: Add Java runtime-version assumptions to the JDK-dependent
cases in checkSuppressWarnings: require JDK 17+ for strictfp-method, JDK 16+ for
synchronization-method, and JDK 21+ for this-escape-constructor. Keep the
existing fixtures and assertions unchanged, and leave the text-blocks-method
case unguarded unless its diagnostics also require a version check.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 42ea884d-32e3-4622-a2f0-2f9c7d541875

📥 Commits

Reviewing files that changed from the base of the PR and between 79568e2 and d263f9f.

📒 Files selected for processing (12)
  • 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/RemoveRedundantCast.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/main/scala/tests/BaseLspSuite.scala
  • tests/unit/src/test/scala/tests/InfraSuite.scala
  • tests/unit/src/test/scala/tests/UserConfigurationSuite.scala
  • tests/unit/src/test/scala/tests/codeactions/RemoveRedundantCastLspSuite.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/Compilers.scala
  • tests/unit/src/test/scala/tests/UserConfigurationSuite.scala
  • metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala
  • tests/unit/src/test/scala/tests/InfraSuite.scala
  • metals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scala
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scala

Comment thread metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala Outdated
Comment thread metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala Outdated
@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch 3 times, most recently from 431f438 to f437208 Compare August 6, 2026 22:08
@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch from f437208 to 301267b Compare August 6, 2026 22:15
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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 (2)
tests/unit/src/test/scala/tests/codeactions/RemoveRedundantCastLspSuite.scala (1)

31-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the l alias for CodeAction.

Line 8 imports org.eclipse.{lsp4j => l}. Line 31 uses the fully qualified org.eclipse.lsp4j.CodeAction instead. If no other reference to l exists in this file, the alias import becomes unused. The Metals build enables fatal warnings for unused imports in several modules, so this can break compilation.

♻️ Proposed change
-  private val onlyRemoveRedundantCast: org.eclipse.lsp4j.CodeAction => Boolean =
+  private val onlyRemoveRedundantCast: l.CodeAction => Boolean =
     _.getTitle() == RemoveRedundantCast.title

Compile this module with Metals MCP tools to confirm no unused-import warning is raised.

🤖 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/RemoveRedundantCastLspSuite.scala`
around lines 31 - 32, Update the onlyRemoveRedundantCast type annotation to use
the imported l alias instead of the fully qualified org.eclipse.lsp4j name,
ensuring the existing lsp4j alias import remains used and the CodeAction
predicate behavior is unchanged.

Source: Coding guidelines

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

82-89: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the repeated DeprecatedApi layout into a shared value.

The same DeprecatedApi.java layout appears three times. Define it once as a private val and reuse it.

♻️ Proposed refactor
+  private val deprecatedApiLayout =
+    """|/a/src/main/java/a/DeprecatedApi.java
+       |package a;
+       |
+       |class DeprecatedApi {
+       |  `@Deprecated`
+       |  static void old() {}
+       |}
+       |""".stripMargin

Then pass extraLayout = deprecatedApiLayout in the three cases.

Also applies to: 218-225, 281-288

🤖 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 82 - 89, Extract the repeated DeprecatedApi.java content into a
private shared value in SuppressWarningsLspSuite, then replace each of the three
inline layouts with extraLayout = deprecatedApiLayout. Preserve the existing
string contents and stripMargin behavior.
🤖 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 229-260: Update appendWarningEdit to handle empty annotation
arrays and named value forms before constructing the TextEdit: render an empty
{} as {"warning"}, and preserve value = syntax by converting scalar or array
named values into valid forms such as {value = "deprecation", "warning"}. Keep
the existing duplicate-warning check and add coverage for empty, scalar named,
and array named annotations.

---

Nitpick comments:
In
`@tests/unit/src/test/scala/tests/codeactions/RemoveRedundantCastLspSuite.scala`:
- Around line 31-32: Update the onlyRemoveRedundantCast type annotation to use
the imported l alias instead of the fully qualified org.eclipse.lsp4j name,
ensuring the existing lsp4j alias import remains used and the CodeAction
predicate behavior is unchanged.

In `@tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala`:
- Around line 82-89: Extract the repeated DeprecatedApi.java content into a
private shared value in SuppressWarningsLspSuite, then replace each of the three
inline layouts with extraLayout = deprecatedApiLayout. Preserve the existing
string contents and stripMargin behavior.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ac5d9c3a-21f5-4897-b0bb-9e475fbc3e81

📥 Commits

Reviewing files that changed from the base of the PR and between 79568e2 and 301267b.

📒 Files selected for processing (13)
  • 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/MetalsEnrichments.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/RemoveRedundantCast.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/main/scala/tests/BaseLspSuite.scala
  • tests/unit/src/test/scala/tests/InfraSuite.scala
  • tests/unit/src/test/scala/tests/UserConfigurationSuite.scala
  • tests/unit/src/test/scala/tests/codeactions/RemoveRedundantCastLspSuite.scala
  • tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala
🚧 Files skipped from review as they are similar to previous changes (7)
  • metals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scala
  • tests/unit/src/test/scala/tests/UserConfigurationSuite.scala
  • tests/unit/src/test/scala/tests/InfraSuite.scala
  • metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scala
  • metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
  • tests/unit/src/main/scala/tests/BaseLspSuite.scala
  • metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala

@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch from c17a998 to 03d2b80 Compare August 6, 2026 22:56
@zielinsky
zielinsky force-pushed the metalsv2/supress-warnings branch from 03d2b80 to 7d98a0b Compare August 6, 2026 23:06
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