Skip to content

feature: Add editor for .class, .semanticdb and tasty files#1908

Merged
tgodzik merged 1 commit intoscalameta:mainfrom
tgodzik:show-class
Apr 7, 2026
Merged

feature: Add editor for .class, .semanticdb and tasty files#1908
tgodzik merged 1 commit intoscalameta:mainfrom
tgodzik:show-class

Conversation

@tgodzik
Copy link
Copy Markdown
Contributor

@tgodzik tgodzik commented Apr 3, 2026

This allows users to use metals decoding for binary files. It will show up after "open anyway" and we can make Metals the default in the settings.

Summary by CodeRabbit

  • New Features
    • Open decompiled class files (.class, .tasty, .semanticdb) in a readable custom editor instead of being treated as binary, making decoded output viewable inline.
    • Added a new window-scoped setting to control class-file decoding behavior (default uses a decompiler, with options like cfr, javap, javap-verbose, or disable), so you can choose how class files are displayed.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4e821d50-5cdf-4366-94b0-af22f32283a5

📥 Commits

Reviewing files that changed from the base of the PR and between 20d0401 and b06fd31.

📒 Files selected for processing (3)
  • package.json
  • src/classFileCustomEditor.ts
  • src/extension.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/extension.ts
  • src/classFileCustomEditor.ts

📝 Walkthrough

Walkthrough

Adds a VS Code custom readonly editor (viewType "metals.classDecoder") to decode and display .class, .tasty, and .semanticdb files; introduces a window-scoped metals.classFileOpenEncoding setting (default "cfr") to control decode mode or disable decoding.

Changes

Cohort / File(s) Summary
Configuration & Custom Editor Registration
package.json
Added contributes.customEditors entry for metals.classDecoder targeting *.class, *.tasty, *.semanticdb. Added window-scoped metals.classFileOpenEncoding (string, default "cfr", enum ["none","cfr","javap","javap-verbose"]).
Custom Editor Implementation
src/classFileCustomEditor.ts
New exported METALS_CLASS_FILE_CUSTOM_EDITOR_VIEW_TYPE constant and registerMetalsClassFileCustomEditor. Implements a CustomReadonlyEditorProvider that ensures the LanguageClient is running, selects decode mode (suffix-based or config), calls decodeAndShowFile for supported modes, and falls back to opening raw text with error handling.
Extension Integration
src/extension.ts
Imports and registers the Metals class-file custom editor during launchMetals after content providers and before command registration.

Sequence Diagram

sequenceDiagram
    participant User
    participant VSCode as VS Code
    participant CustomEditor as Custom Editor Provider
    participant LanguageClient
    participant MetalsServer as Metals Server
    participant FileDecoder as decodeAndShowFile

    User->>VSCode: Open `.class`/`.tasty`/`.semanticdb` file
    VSCode->>CustomEditor: Resolve custom editor (metals.classDecoder)
    CustomEditor->>LanguageClient: Ensure client started
    LanguageClient-->>CustomEditor: Client ready
    CustomEditor->>CustomEditor: Determine decode mode (file suffix or `metals.classFileOpenEncoding`)
    alt Mode is "none" or unsupported
        CustomEditor->>VSCode: Open file as text editor
    else Mode is supported
        CustomEditor->>FileDecoder: Request decoded content with mode
        FileDecoder->>MetalsServer: Ask for decoded output
        MetalsServer-->>FileDecoder: Return decoded content
        FileDecoder->>VSCode: Render decoded content in webview
    end
    VSCode-->>User: Display file content
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibble bytes and hop with glee,
I peel back class files for you to see,
CFR or javap, tasty treats unfold,
Semantic whispers quietly told,
Hooray—decoded daisies in my code-filled tree!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a custom editor for binary file types (.class, .semanticdb, and .tasty files), which aligns with the core functionality implemented across the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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)
src/classFileCustomEditor.ts (1)

79-81: Simplify redundant mode check.

mode !== "tasty-decoded" is unnecessary here because "tasty-decoded" is already allowed by isClassFileOpenDecoder(mode).

Suggested cleanup
-          if (
-            mode === "none" ||
-            (!isClassFileOpenDecoder(mode) && mode !== "tasty-decoded")
-          ) {
+          if (mode === "none" || !isClassFileOpenDecoder(mode)) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/classFileCustomEditor.ts` around lines 79 - 81, The condition block in
the class file editor contains a redundant check: remove the explicit `mode !==
"tasty-decoded"` from the compound conditional and rely on
`isClassFileOpenDecoder(mode)` to already allow `"tasty-decoded"`; update the
conditional around `mode === "none" || (!isClassFileOpenDecoder(mode) && mode
!== "tasty-decoded")` to the simplified form using only `mode === "none" ||
!isClassFileOpenDecoder(mode)` so the logic stays equivalent and clearer (locate
the check near the existing `isClassFileOpenDecoder(mode)` usage in
classFileCustomEditor.ts).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/classFileCustomEditor.ts`:
- Line 68: Replace the use of the var declaration for the variable named "mode"
with a block-scoped let declaration to satisfy the ESLint no-var rule; locate
the var mode declaration in src/classFileCustomEditor.ts (identifier: mode) and
change it to let mode so CI linting passes and scoping is correct.

---

Nitpick comments:
In `@src/classFileCustomEditor.ts`:
- Around line 79-81: The condition block in the class file editor contains a
redundant check: remove the explicit `mode !== "tasty-decoded"` from the
compound conditional and rely on `isClassFileOpenDecoder(mode)` to already allow
`"tasty-decoded"`; update the conditional around `mode === "none" ||
(!isClassFileOpenDecoder(mode) && mode !== "tasty-decoded")` to the simplified
form using only `mode === "none" || !isClassFileOpenDecoder(mode)` so the logic
stays equivalent and clearer (locate the check near the existing
`isClassFileOpenDecoder(mode)` usage in classFileCustomEditor.ts).
🪄 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: ffd54823-fadc-4d91-83d0-b59c12e546ad

📥 Commits

Reviewing files that changed from the base of the PR and between 8d61f27 and 20d0401.

📒 Files selected for processing (3)
  • package.json
  • src/classFileCustomEditor.ts
  • src/extension.ts

Comment thread src/classFileCustomEditor.ts Outdated
This allows users to use metals decoding for binary files. It will show up after "open anyway" and we can make Metals the default in the settings.
@tgodzik tgodzik merged commit 6d594c4 into scalameta:main Apr 7, 2026
11 checks passed
@tgodzik tgodzik deleted the show-class branch April 7, 2026 09:10
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