Skip to content

Add metadata pane for non-module files in module inspector#4059

Merged
lukemelia merged 8 commits intomainfrom
cs-10197-metadata-pane-for-non-module-files-in-module-inspector
Feb 26, 2026
Merged

Add metadata pane for non-module files in module inspector#4059
lukemelia merged 8 commits intomainfrom
cs-10197-metadata-pane-for-non-module-files-in-module-inspector

Conversation

@lukemelia
Copy link
Contributor

@lukemelia lukemelia commented Feb 24, 2026

Summary

  • Adds a "Metadata" format option in the preview pane's format chooser when a non-.gts / non-card .json file is open in CodeMode
  • Shows a read-only, syntax-highlighted JSON-API representation of the FileDef instance
  • Adds serializeFileDef() to card-serialization.ts, sharing internal serialization logic with serializeCard() via a widened serializeCardResource()
  • Moves [meta] property from CardDef to BaseDef to enable clean serialization of any BaseDef subclass

Test plan

  • Open a non-module file (e.g. an image or markdown file) in CodeMode
  • Verify "Metadata" appears in the format chooser
  • Select "Metadata" and verify syntax-highlighted JSON-API doc is displayed
  • Switch to a card/.gts file and verify "Metadata" is not available
  • Verify existing card serialization and preview formats still work

Closes CS-10197

🤖 Generated with Claude Code

image

@github-actions
Copy link

Preview deployments

@github-actions
Copy link

github-actions bot commented Feb 24, 2026

Host Test Results

    1 files  ± 0      1 suites  ±0   1h 35m 16s ⏱️ - 4m 7s
1 889 tests +11  1 874 ✅ +11  15 💤 ±0  0 ❌ ±0 
1 904 runs  +11  1 889 ✅ +11  15 💤 ±0  0 ❌ ±0 

Results for commit 1d11311. ± Comparison against base commit c2e3fb9.

♻️ This comment has been updated with latest results.

When a non-.gts file or non-card .json file is open in CodeMode, the
preview pane's format chooser now includes a "Metadata" option that
displays a read-only, syntax-highlighted JSON-API representation of
the FileDef instance.

Key changes:
- Add serializeFileDef() to card-serialization.ts, sharing internal
  serialization logic with serializeCard() via a widened
  serializeCardResource()
- Move [meta] property from CardDef to BaseDef to support clean
  serialization of any BaseDef subclass
- Add MetadataPanel component with JSON syntax highlighting
- Add 'metadata' to Format type and expose it for FileDef instances

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lukemelia lukemelia force-pushed the cs-10197-metadata-pane-for-non-module-files-in-module-inspector branch from 1224a16 to 6dc7925 Compare February 25, 2026 19:10
Fix JSON syntax highlighting so numbers/booleans/nulls inside strings
are not re-highlighted. Use placeholder strategy to protect key and
string spans from subsequent regex passes.

Add visual divider before the metadata button in the format chooser
and widen the container to prevent overflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lukemelia lukemelia marked this pull request as ready for review February 25, 2026 20:00
@lukemelia lukemelia requested a review from Copilot February 25, 2026 20:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds metadata viewing capability for non-module files in the module inspector. When a non-card, non-module file (like an image or markdown file) is opened in CodeMode, users can now select a "Metadata" format option to view a syntax-highlighted JSON-API representation of the FileDef instance.

Changes:

  • Added 'metadata' as a new Format type and made it available only for FileDef instances in the preview panel
  • Implemented serializeFileDef() function to generate JSON-API representations of FileDef instances, sharing internal logic with serializeCard() via a widened serializeCardResource()
  • Moved [meta] property from CardDef to BaseDef to enable serialization of any BaseDef subclass including FileDef

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/runtime-common/resource-types.ts Added LooseFileMetaResource type definition
packages/runtime-common/index.ts Added LooseSingleFileMetaDocument interface for file metadata documents
packages/runtime-common/formats.ts Added 'metadata' as a new Format option
packages/host/app/services/store.ts Added serializeFileDefAsDocument() method to serialize FileDef instances
packages/host/app/components/operator-mode/preview-panel/metadata-panel.gts New component that displays syntax-highlighted JSON-API metadata with proper HTML escaping and error handling
packages/host/app/components/operator-mode/preview-panel/index.gts Integrated MetadataPanel component and made 'metadata' format available only for FileDef instances
packages/host/app/components/operator-mode/code-submode/format-chooser.gts Added visual divider before metadata format option and adjusted width to accommodate new format
packages/base/card-serialization.ts Implemented serializeFileDef() function and widened serializeCardResource() to support both CardDef and FileDef serialization
packages/base/card-api.gts Moved [meta] property from CardDef to BaseDef and exported serializeFileDef function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Fixes TS2366 glint error caused by 'metadata' being added to the Format
union without a corresponding case in the switch statement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lukemelia lukemelia force-pushed the cs-10197-metadata-pane-for-non-module-files-in-module-inspector branch from e9c996f to 422f58f Compare February 25, 2026 20:22
Luke Melia and others added 3 commits February 25, 2026 20:30
- Add blank line between @ember/@Glimmer imports and ember-resources/
  tracked-built-ins to satisfy import/order rule
- Replace \x00 (NUL control character) sentinel with \uE000 (Unicode
  private use area) to fix no-control-regex rule

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…sues

Use String.fromCharCode(0xe000) to build the placeholder sentinel at
runtime rather than a literal escape sequence. This avoids:
- no-control-regex: ESLint flags control chars in regex literals/patterns
- content-tag parse failure: regex literal with \uE000 confused the GTS
  parser, causing glint to fail to parse the entire file

Also converts PLACEHOLDER_RE to new RegExp() constructor per the file's
existing pattern for regex literals in .gts files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Fix error message variable name: use possibleURL (the parameter)
  instead of maybeRelativeURL (the function being defined)
- Widen serializeCardResource return type to LooseCardResource |
  LooseFileMetaResource to accurately reflect what the function produces
  when called with FileMetaResourceType

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lukemelia lukemelia requested review from a team and jurgenwerk February 25, 2026 21:46
Luke Melia added 2 commits February 25, 2026 21:57
- Integration tests for serializeFileDef in file-def-serialization-test.gts
  covering: type 'file-meta', id inclusion, adoptsFrom, attributes, type guard,
  URL handling, and full document shape
- Export serializeFileDef from base-realm test helpers
- Acceptance tests in code-submode-test.ts:
  - non-card files show 'metadata' format button (and not 'edit')
  - clicking metadata shows the panel with file-meta JSON content
  - switching away from metadata hides the panel
  - card instances do not show 'metadata' format button (assertion added
    to existing test)
- Collapse single-item type import to one line (prettier)
- Use assert.notEqual instead of assert.ok with != null (qunit/no-ok-equality)
- Simplify subdirectory URL test to avoid accessing CodeRef.module (TS2339)
@backspace
Copy link
Contributor

This is unrelated to your PR but should there be a head format preview for images?

green-mango png in Experiments Workspace 2026-02-26 10-25-30

Copy link
Contributor

@backspace backspace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this locally, worked as expected

--boxel-button-text-color: var(--boxel-dark);
}

.format-chooser__divider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for BEM with scoping, could just be divider, but I see __buttons and __button already exist, so…

@lukemelia lukemelia merged commit 371d6d1 into main Feb 26, 2026
107 checks passed
@lukemelia
Copy link
Contributor Author

This is unrelated to your PR but should there be a head format preview for images?

Should there be? There should definitely be a preview, since you can view a file's isolated view in host mode and presumably that should show its head format.

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.

4 participants