Add suppress warnings & remove redudant cast quick-fix code action - #8646
Add suppress warnings & remove redudant cast quick-fix code action#8646zielinsky wants to merge 4 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
0d30058 to
3af8b1e
Compare
There was a problem hiding this comment.
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 valueNaming ambiguity: field
javaTargetis typedJvmTarget, then pattern-matched againstJavaTarget.This isn't introduced by this diff, but the changed lines make the ambiguity more visible:
javaTarget: JvmTarget(line 437) is matched withcase j: JavaTarget => j.options(line 450). Consider renaming the field (e.g.target: JvmTarget) to reduce confusion now that the surrounding PR stack explicitly distinguishesJavaTargetfromJvmTarget.🤖 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
📒 Files selected for processing (7)
metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scalametals/src/main/scala/scala/meta/internal/metals/Compilers.scalametals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scalametals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scalametals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scalamtags-interfaces/src/main/java/scala/meta/infra/FeatureFlag.javatests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala
💤 Files with no reviewable changes (1)
- mtags-interfaces/src/main/java/scala/meta/infra/FeatureFlag.java
3af8b1e to
b217fe0
Compare
There was a problem hiding this comment.
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 winAvoid leaking
enabledFlagsbetween suites.SuppressWarningsLspSuite.beforeAll()mutates a shared singleton before callingsuper.beforeAll(), so a setup failure can leaveJAVAC_OPTIONSenabled for later suites. Move the toggle into a fixture/try-finallyteardown 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
📒 Files selected for processing (7)
metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scalametals/src/main/scala/scala/meta/internal/metals/Compilers.scalametals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scalametals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scalametals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scalatests/unit/src/test/scala/tests/InfraSuite.scalatests/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
5e375ac to
249d4f9
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/src/test/scala/tests/codeactions/SuppressWarningsLspSuite.scala (1)
802-812: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider 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
📒 Files selected for processing (9)
metals/src/main/scala/scala/meta/internal/metals/CompilerConfiguration.scalametals/src/main/scala/scala/meta/internal/metals/Compilers.scalametals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scalametals/src/main/scala/scala/meta/internal/metals/codeactions/CodeActionProvider.scalametals/src/main/scala/scala/meta/internal/metals/codeactions/SuppressWarnings.scalametals/src/main/scala/scala/meta/internal/parsing/JavaTrees.scalatests/unit/src/test/scala/tests/InfraSuite.scalatests/unit/src/test/scala/tests/UserConfigurationSuite.scalatests/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
249d4f9 to
f79fc10
Compare
c9a3884 to
e6255ce
Compare
Part of #8502
Summary by CodeRabbit
New Features
@SuppressWarnings(...)for compiler warnings.Bug Fixes