Skip to content

Commit

Permalink
[editor/monaco] enable semantic highlighting by default
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Oct 6, 2020
1 parent a5c8ed7 commit 1078bba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/editor/src/browser/editor-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const codeEditorPreferenceProperties = {
},
'editor.semanticHighlighting.enabled': {
'type': 'boolean',
'default': false,
'default': true,
'description': 'Controls whether the semanticHighlighting is shown for the languages that support it.'
},
'editor.stablePeek': {
Expand Down
17 changes: 17 additions & 0 deletions packages/monaco/src/browser/monaco-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ decorate(injectable(), monaco.contextKeyService.ContextKeyService);

MonacoThemingService.init();

// based on https://github.com/microsoft/vscode/commit/4731a227e377da8cb14ed5697dd1ba8faea40538
// TODO remove after migrating to monaco 0.21
const standaloneThemeService = monaco.services.StaticServices.standaloneThemeService.get();
standaloneThemeService.getTokenStyleMetadata = (type, modifiers, modelLanguage) => {
// use theme rules match
const style = standaloneThemeService.tokenTheme._match([type].concat(modifiers).join('.'));
const metadata = style.metadata;
const foreground = monaco.modes.TokenMetadata.getForeground(metadata);
const fontStyle = monaco.modes.TokenMetadata.getFontStyle(metadata);
return {
foreground: foreground,
italic: Boolean(fontStyle & monaco.modes.FontStyle.Italic),
bold: Boolean(fontStyle & monaco.modes.FontStyle.Bold),
underline: Boolean(fontStyle & monaco.modes.FontStyle.Underline)
};
};

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(MonacoThemingService).toSelf().inSingletonScope();

Expand Down
22 changes: 22 additions & 0 deletions packages/monaco/src/typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,24 @@ declare module monaco.services {
get(overrides?: monaco.editor.IEditorOverrideServices): T;
}

// https://github.com/microsoft/vscode/blob/0eb3a02ca2bcfab5faa3dc6e52d7c079efafcab0/src/vs/platform/theme/common/themeService.ts#L78
export interface ITokenStyle {
readonly foreground?: number;
readonly bold?: boolean;
readonly underline?: boolean;
readonly italic?: boolean;
}

// https://github.com/theia-ide/vscode/blob/standalone/0.20.x/src/vs/editor/standalone/common/standaloneThemeService.ts#L28
export interface IStandaloneThemeService extends monaco.theme.IThemeService {
// https://github.com/theia-ide/vscode/blob/standalone/0.20.x/src/vs/editor/standalone/browser/standaloneThemeServiceImpl.ts#L178
readonly _knownThemes: Map<string, IStandaloneTheme>;

getTheme(): IStandaloneTheme;

readonly tokenTheme: TokenTheme;

getTokenStyleMetadata(type: string, modifiers: string[], modelLanguage: string): ITokenStyle | undefined;
}

// https://github.com/theia-ide/vscode/blob/standalone/0.20.x/src/vs/editor/standalone/common/standaloneThemeService.ts#L23
Expand All @@ -781,6 +793,7 @@ declare module monaco.services {
// https://github.com/theia-ide/vscode/blob/standalone/0.20.x/src/vs/editor/common/modes/supports/tokenization.ts#L188
export interface TokenTheme {
match(languageId: LanguageId, scope: string): number;
_match(token: string): any;
getColorMap(): monaco.color.Color[];
}

Expand Down Expand Up @@ -1298,6 +1311,15 @@ declare module monaco.modes {
}
export const TokenizationRegistry: TokenizationRegistry;

// https://github.com/microsoft/vscode/blob/0eb3a02ca2bcfab5faa3dc6e52d7c079efafcab0/src/vs/editor/common/modes.ts#L66-L76
export const enum FontStyle {
NotSet = -1,
None = 0,
Italic = 1,
Bold = 2,
Underline = 4
}

// https://github.com/theia-ide/vscode/blob/standalone/0.20.x/src/vs/editor/common/modes.ts#L148
export class TokenMetadata {

Expand Down

0 comments on commit 1078bba

Please sign in to comment.