Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: color.charCodeAt is not a function when using github-dark-default with @shikijs/monaco #894

Closed
3 of 5 tasks
MathiasWP opened this issue Jan 16, 2025 · 11 comments
Closed
3 of 5 tasks

Comments

@MathiasWP
Copy link

MathiasWP commented Jan 16, 2025

Validations

Describe the bug

I have this shiki setup:

import { shikiToMonaco } from '@shikijs/monaco';
import { bundledLanguagesInfo, createHighlighter } from 'shiki';

export async function registerShiki(monaco: typeof Monaco) {
	const highlighter = await createHighlighter({
		themes: ['github-dark-default'],
		langs: bundledLanguagesInfo.map(lang => lang.id) // This isn't very performant, but shouldn't all of these work?
	});

	const languagesAlreadyInMonaco = monaco.languages.getLanguages();
	for (const language of bundledLanguagesInfo.filter((language) => !languagesAlreadyInMonaco.some((l) => l.id === language.id))) {
		monaco.languages.register({ id: language.id });
	}

	shikiToMonaco(highlighter, monaco);
}

If i github-dark-default as a theme i get the following error in my console:

Image

It works fine if i set github-dark as my theme. What am i doing wrong here?

Reproduction

look at code example

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
@DavidSeptimus
Copy link

Same here. Running into the same issue with github-dark-high-contrast as well. I haven't noticed it with any other bundled themes.

@MathiasWP
Copy link
Author

This section right here is the culprit in both themes:

shikijs/textmate-grammars-themes@ceea760/packages/tm-themes/themes/github-dark-default.json#L171-L182

symbolIcon.constantForeground Should be a string. I can't imagine why it's an array here.

wraith13/vscode-schemas@6ca800d/en/latest/schemas/workbench-colors.json#L2245-L2254

Then it's clearly a bug, no? If it's the wrong data-type. Do we know which of these values are the correct symbolIcon.constantForeground? Doesn't seem like a difficult fix if we just have to change this value in the JSON file.

@DavidSeptimus
Copy link

Definitely a bug. The published version of this theme has the same issue, so I'm guessing VS Code is ignoring it gracefully. The colors are steps in a green color scale.

Image

@DavidSeptimus
Copy link

DavidSeptimus commented Feb 3, 2025

Took a bit of time to track it down in the outline pane since most "constants" aren't categorized that way. Python screaming-snake-case style constants seem to be the only thing I can find that gets categorized as "constant."

Current state: (no color loaded)
Image

Going by luminosity, #3fb950 is probably the right shade:

Image

@MathiasWP
Copy link
Author

Took a bit of time to track it down in the outline pane since most "constants" aren't categorized that way. Python screaming-snake-case style constants seem to be the only thing I can find that gets categorized as "constant."

Current state: (no color loaded) Image

Going by luminosity, #3fb950 is probably the right shade:

Image

So replacing the array with this hardcoded value seems like the correct solution? 😺

@MathiasWP
Copy link
Author

I've created a PR that hopefully resolves this shikijs/textmate-grammars-themes#117 @DavidSeptimus

@taiyuuki
Copy link

taiyuuki commented Feb 6, 2025

Same issue here #668

@MathiasWP
Copy link
Author

Same issue here #668

Weird that this has been an issue for so long 👀

@MathiasWP
Copy link
Author

A possible workaround until this has been fixed properly is to do the following:

const highlighter = await createHighlighter({
	themes: ['github-dark-default'],
	langs: languages
});

const githubDarkDefaultTheme = highlighter.getTheme('github-dark-default');
githubDarkDefaultTheme.colors!['symbolIcon.constantForeground'] = '#3fb950';

This will overwrite the invalid array with the correct string color, and then it works as expected.

@antfu antfu closed this as completed in e30181b Feb 6, 2025
@antfu
Copy link
Member

antfu commented Feb 6, 2025

I don't know if it's intended in the source theme, but I add a workaround to fix this for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants