Fix preview loading for JSONC themes#45
Open
subhajitlucky wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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
SyntaxHighlightServiceto use the new loader instead of directlyrequire()-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 on lines
+58
to
+63
| try { | ||
| return require(themePath); | ||
| } catch { | ||
| const themeContent = fs.readFileSync(themePath, 'utf8'); | ||
| return JSON.parse(removeTrailingCommas(stripJsonComments(themeContent))); | ||
| } |
Comment on lines
+60
to
+62
| } catch { | ||
| const themeContent = fs.readFileSync(themePath, 'utf8'); | ||
| return JSON.parse(removeTrailingCommas(stripJsonComments(themeContent))); |
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #32.
Summary
Validation
npm run test:theme-loadergit diff --checkNote:
npm run lintstill fails because the repository has no ESLint configuration file for the existing lint script.