1
>
/*---------------------------------------------------------------------------------------------
colorThemeData.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { basename } from '../../../../base/common/path.js';
7
>
import * as Json from '../../../../base/common/json.js';
8
>
import { Color } from '../../../../base/common/color.js';
9
>
import { ExtensionData, ITokenColorCustomizations, ITextMateThemingRule, IWorkbenchColorTheme, IColorMap, IThemeExtensionPoint, IColorCustomizations, ISemanticTokenRules, ISemanticTokenColorizationSetting, ISemanticTokenColorCustomizations, IThemeScopableCustomizations, IThemeScopedCustomizations, THEME_SCOPE_CLOSE_PAREN, THEME_SCOPE_OPEN_PAREN, themeScopeRegex, THEME_SCOPE_WILDCARD } from './workbenchThemeService.js';
10
>
import { convertSettings } from './themeCompatibility.js';
11
>
import * as nls from '../../../../nls.js';
12
>
import * as types from '../../../../base/common/types.js';
13
>
import * as resources from '../../../../base/common/resources.js';
14
>
import { Extensions as ColorRegistryExtensions, IColorRegistry, ColorIdentifier, editorBackground, editorForeground, DEFAULT_COLOR_CONFIG_VALUE } from '../../../../platform/theme/common/colorRegistry.js';
15
>
import { IFontTokenOptions, ITokenStyle, getThemeTypeSelector } from '../../../../platform/theme/common/themeService.js';
16
>
import { Registry } from '../../../../platform/registry/common/platform.js';
17
>
import { getParseErrorMessage } from '../../../../base/common/jsonErrorMessages.js';
18
>
import { URI } from '../../../../base/common/uri.js';
19
>
import { parse as parsePList } from './plistParser.js';
20
>
import { TokenStyle, SemanticTokenRule, ProbeScope, getTokenClassificationRegistry, TokenStyleValue, TokenStyleData, parseClassifierString } from '../../../../platform/theme/common/tokenClassificationRegistry.js';
21
>
import { MatcherWithPriority, Matcher, createMatchers } from './textMateScopeMatcher.js';
22
>
import { IExtensionResourceLoaderService } from '../../../../platform/extensionResourceLoader/common/extensionResourceLoader.js';
23
>
import { CharCode } from '../../../../base/common/charCode.js';
24
>
import { StorageScope, IStorageService, StorageTarget } from '../../../../platform/storage/common/storage.js';
25
>
import { ThemeConfiguration } from './themeConfiguration.js';
26
>
import { ColorScheme, ThemeTypeSelector } from '../../../../platform/theme/common/theme.js';
27
>
import { ColorId, FontStyle, MetadataConsts } from '../../../../editor/common/encodedTokenAttributes.js';
28
>
import { toStandardTokenType } from '../../../../editor/common/languages/supports/tokenization.js';
29
>
30
>
const colorRegistry = Registry.as<IColorRegistry>(ColorRegistryExtensions.ColorContribution);
31
>
32
>
const tokenClassificationRegistry = getTokenClassificationRegistry();
33
>
34
>
const tokenGroupToScopesMap = {
35
>
comments: ['comment', 'punctuation.definition.comment'],
36
>
strings: ['string', 'meta.embedded.assembly'],
37
>
keywords: ['keyword - keyword.operator', 'keyword.control', 'storage', 'storage.type'],
38
>
numbers: ['constant.numeric'],
39
>
types: ['entity.name.type', 'entity.name.class', 'support.type', 'support.class'],
40
>
functions: ['entity.name.function', 'support.function'],
41
>
variables: ['variable', 'entity.name.variable']
42
>
};
43
>
44
>
45
>
export type TokenStyleDefinition = SemanticTokenRule | ProbeScope[] | TokenStyleValue;
46
>
export type TokenStyleDefinitions = { [P in keyof TokenStyleData]?: TokenStyleDefinition | undefined };
47
>
48
>
export type TextMateThemingRuleDefinitions = { [P in keyof TokenStyleData]?: ITextMateThemingRule | undefined; } & { scope?: ProbeScope };
49
>
50
>
interface IColorOrDefaultMap {
51
>
[id: string]: Color | typeof DEFAULT_COLOR_CONFIG_VALUE;
52
>
}
53
>
54
>
export class ColorThemeData implements IWorkbenchColorTheme {
55
>
56
>
static readonly STORAGE_KEY = 'colorThemeData';
57
>
58
>
id: string;
59
>
label: string;
60
>
settingsId: string;
61
>
description?: string;
62
>
isLoaded: boolean;
63
>
location?: URI; // only set for extension from the registry, not for themes restored from the storage
64
>
watch?: boolean;
65
>
extensionData?: ExtensionData;
66
>
67
>
private themeSemanticHighlighting: boolean | undefined;
68
>
private customSemanticHighlighting: boolean | undefined;
69
>
private customSemanticHighlightingDeprecated: boolean | undefined;
70
>
71
>
private themeTokenColors: ITextMateThemingRule[] = [];
72
>
private customTokenColors: ITextMateThemingRule[] = [];
73
>
private colorMap: IColorMap = {};
74
>
private customColorMap: IColorOrDefaultMap = {};
75
>
76
>
private semanticTokenRules: SemanticTokenRule[] = [];
77
>
private customSemanticTokenRules: SemanticTokenRule[] = [];
78
>
79
>
private themeTokenScopeMatchers: Matcher<ProbeScope>[] | undefined;
80
>
private customTokenScopeMatchers: Matcher<ProbeScope>[] | undefined;
81
>
82
>
private textMateThemingRules: ITextMateThemingRule[] | undefined = undefined; // created on demand
83
>
private tokenColorIndex: TokenColorIndex | undefined = undefined; // created on demand
84
>
private tokenFontIndex: TokenFontIndex | undefined = undefined; // created on demand
85
>
86
>
private constructor(id: string, label: string, settingsId: string) {
87
>
this.id = id;
88
>
this.label = label;
89
>
this.settingsId = settingsId;
90
>
this.isLoaded = false;
91
>
}
92
>
93
>
get semanticHighlighting(): boolean {
94
if (this.customSemanticHighlighting !== undefined) {
95
return this.customSemanticHighlighting;