Skip to content

Fix preview loading for JSONC themes#45

Open
subhajitlucky wants to merge 1 commit into
zigcBenx:masterfrom
subhajitlucky:fix-preview-theme-loading-32
Open

Fix preview loading for JSONC themes#45
subhajitlucky wants to merge 1 commit into
zigcBenx:masterfrom
subhajitlucky:fix-preview-theme-loading-32

Conversation

@subhajitlucky
Copy link
Copy Markdown

Fixes #32.

Summary

  • Adds a resilient theme-file loader that can parse VS Code JSONC theme files with comments and trailing commas.
  • Uses the loader when resolving the active VS Code color theme for Shiki preview highlighting.
  • Adds a focused regression test for JSONC theme loading.

Validation

  • npm run test:theme-loader
  • git diff --check

Note: npm run lint still fails because the repository has no ESLint configuration file for the existing lint script.

Copilot AI review requested due to automatic review settings May 13, 2026 03:19
Copy link
Copy Markdown

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 PR addresses preview syntax highlighting failures when the active VS Code theme is a JSONC theme (comments + trailing commas) by adding a JSONC-capable theme loader and using it during theme resolution for Shiki.

Changes:

  • Added a theme-file loader that strips JSONC comments and trailing commas before parsing.
  • Updated theme resolution in SyntaxHighlightService to use the new loader instead of directly require()-ing theme files.
  • Added a regression test script for loading a JSONC theme file.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/themeLoader.ts Introduces JSONC comment stripping / trailing-comma removal and a theme loader wrapper.
src/services/SyntaxHighlightService.ts Switches theme loading to the new loader to support JSONC themes.
tests/themeLoader.test.js Adds a regression test that validates loading JSONC with comments and trailing commas.
package.json Adds a dedicated test:theme-loader script for running the new regression test.

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

Comment thread src/themeLoader.ts
Comment on lines +58 to +63
try {
return require(themePath);
} catch {
const themeContent = fs.readFileSync(themePath, 'utf8');
return JSON.parse(removeTrailingCommas(stripJsonComments(themeContent)));
}
Comment thread src/themeLoader.ts
Comment on lines +60 to +62
} catch {
const themeContent = fs.readFileSync(themePath, 'utf8');
return JSON.parse(removeTrailingCommas(stripJsonComments(themeContent)));
Comment thread tests/themeLoader.test.js
Comment on lines +26 to +33
const theme = loadThemeFile(themePath);

assert.equal(theme.name, 'Commented Theme');
assert.equal(theme.colors['editor.foreground'], '#eeeeee');
assert.equal(theme.tokenColors[0].settings.foreground, '#ff00ff');

fs.rmSync(dir, { recursive: true, force: true });
console.log('themeLoader tests passed');
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.

Won't load preview

2 participants