@codingame/monaco-vscode-9a934394-0cf8-512d-939b-77e71f69cebb-common 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/empty.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {}
|
package/package.json
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
{
|
2
|
+
"name": "@codingame/monaco-vscode-9a934394-0cf8-512d-939b-77e71f69cebb-common",
|
3
|
+
"version": "20.0.0",
|
4
|
+
"private": false,
|
5
|
+
"description": "VSCode public API plugged on the monaco editor - common package (chat, interactive, notebook, search, textmate, theme, treesitter)",
|
6
|
+
"keywords": [],
|
7
|
+
"author": {
|
8
|
+
"name": "CodinGame",
|
9
|
+
"url": "http://www.codingame.com"
|
10
|
+
},
|
11
|
+
"license": "MIT",
|
12
|
+
"repository": {
|
13
|
+
"type": "git",
|
14
|
+
"url": "git+ssh://git@github.com/CodinGame/monaco-vscode-api.git"
|
15
|
+
},
|
16
|
+
"type": "module",
|
17
|
+
"dependencies": {
|
18
|
+
"@codingame/monaco-vscode-api": "20.0.0"
|
19
|
+
},
|
20
|
+
"exports": {
|
21
|
+
".": {
|
22
|
+
"default": "./empty.js"
|
23
|
+
},
|
24
|
+
"./vscode/*.css": {
|
25
|
+
"default": "./vscode/src/*.css"
|
26
|
+
},
|
27
|
+
"./vscode/*": {
|
28
|
+
"types": "./vscode/src/*.d.ts",
|
29
|
+
"default": "./vscode/src/*.js"
|
30
|
+
},
|
31
|
+
"./*": {
|
32
|
+
"types": "./*.d.ts",
|
33
|
+
"default": "./*.js"
|
34
|
+
}
|
35
|
+
},
|
36
|
+
"typesVersions": {
|
37
|
+
"*": {
|
38
|
+
"vscode/*": [
|
39
|
+
"./vscode/src/*.d.ts"
|
40
|
+
]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
export declare const canASAR = false;
|
2
|
+
export declare function importAMDNodeModule<T>(nodeModuleName: string, pathInsideNodeModule: string, isBuilt?: boolean): Promise<T>;
|
3
|
+
export declare function resolveAmdNodeModulePath(nodeModuleName: string, pathInsideNodeModule: string): string;
|
@@ -0,0 +1,196 @@
|
|
1
|
+
|
2
|
+
import { Schemas, VSCODE_AUTHORITY, nodeModulesPath, FileAccess } from '@codingame/monaco-vscode-api/vscode/vs/base/common/network';
|
3
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/platform';
|
4
|
+
import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
|
5
|
+
import { generateUuid } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uuid';
|
6
|
+
|
7
|
+
class DefineCall {
|
8
|
+
constructor(id, dependencies, callback) {
|
9
|
+
this.id = id;
|
10
|
+
this.dependencies = dependencies;
|
11
|
+
this.callback = callback;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
var AMDModuleImporterState;
|
15
|
+
(function (AMDModuleImporterState) {
|
16
|
+
AMDModuleImporterState[AMDModuleImporterState["Uninitialized"] = 1] = "Uninitialized";
|
17
|
+
AMDModuleImporterState[AMDModuleImporterState["InitializedInternal"] = 2] = "InitializedInternal";
|
18
|
+
AMDModuleImporterState[AMDModuleImporterState["InitializedExternal"] = 3] = "InitializedExternal";
|
19
|
+
})(AMDModuleImporterState || (AMDModuleImporterState = {}));
|
20
|
+
class AMDModuleImporter {
|
21
|
+
static { this.INSTANCE = ( new AMDModuleImporter()); }
|
22
|
+
constructor() {
|
23
|
+
this._isWebWorker = (typeof self === 'object' && self.constructor && self.constructor.name === 'DedicatedWorkerGlobalScope');
|
24
|
+
this._isRenderer = typeof document === 'object';
|
25
|
+
this._defineCalls = [];
|
26
|
+
this._state = AMDModuleImporterState.Uninitialized;
|
27
|
+
}
|
28
|
+
_initialize() {
|
29
|
+
if (this._state === AMDModuleImporterState.Uninitialized) {
|
30
|
+
if (globalThis.define) {
|
31
|
+
this._state = AMDModuleImporterState.InitializedExternal;
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
this._state = AMDModuleImporterState.InitializedInternal;
|
39
|
+
globalThis.define = (id, dependencies, callback) => {
|
40
|
+
if (typeof id !== 'string') {
|
41
|
+
callback = dependencies;
|
42
|
+
dependencies = id;
|
43
|
+
id = null;
|
44
|
+
}
|
45
|
+
if (typeof dependencies !== 'object' || !Array.isArray(dependencies)) {
|
46
|
+
callback = dependencies;
|
47
|
+
dependencies = null;
|
48
|
+
}
|
49
|
+
this._defineCalls.push(( new DefineCall(id, dependencies, callback)));
|
50
|
+
};
|
51
|
+
globalThis.define.amd = true;
|
52
|
+
if (this._isRenderer) {
|
53
|
+
this._amdPolicy = globalThis._VSCODE_WEB_PACKAGE_TTP ?? window.trustedTypes?.createPolicy('amdLoader', {
|
54
|
+
createScriptURL(value) {
|
55
|
+
if (value.startsWith(window.location.origin)) {
|
56
|
+
return value;
|
57
|
+
}
|
58
|
+
if (value.startsWith(`${Schemas.vscodeFileResource}://${VSCODE_AUTHORITY}`)) {
|
59
|
+
return value;
|
60
|
+
}
|
61
|
+
throw ( new Error(`[trusted_script_src] Invalid script url: ${value}`));
|
62
|
+
}
|
63
|
+
});
|
64
|
+
}
|
65
|
+
else if (this._isWebWorker) {
|
66
|
+
this._amdPolicy = globalThis._VSCODE_WEB_PACKAGE_TTP ?? globalThis.trustedTypes?.createPolicy('amdLoader', {
|
67
|
+
createScriptURL(value) {
|
68
|
+
return value;
|
69
|
+
}
|
70
|
+
});
|
71
|
+
}
|
72
|
+
}
|
73
|
+
async load(scriptSrc) {
|
74
|
+
this._initialize();
|
75
|
+
if (this._state === AMDModuleImporterState.InitializedExternal) {
|
76
|
+
return ( new Promise(resolve => {
|
77
|
+
const tmpModuleId = generateUuid();
|
78
|
+
globalThis.define(tmpModuleId, [scriptSrc], function (moduleResult) {
|
79
|
+
resolve(moduleResult);
|
80
|
+
});
|
81
|
+
}));
|
82
|
+
}
|
83
|
+
const defineCall = await (this._isWebWorker ? this._workerLoadScript(scriptSrc) : this._isRenderer ? this._rendererLoadScript(scriptSrc) : this._nodeJSLoadScript(scriptSrc));
|
84
|
+
if (!defineCall) {
|
85
|
+
console.warn(`Did not receive a define call from script ${scriptSrc}`);
|
86
|
+
return undefined;
|
87
|
+
}
|
88
|
+
const exports = {};
|
89
|
+
const dependencyObjs = [];
|
90
|
+
const dependencyModules = [];
|
91
|
+
if (Array.isArray(defineCall.dependencies)) {
|
92
|
+
for (const mod of defineCall.dependencies) {
|
93
|
+
if (mod === 'exports') {
|
94
|
+
dependencyObjs.push(exports);
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
dependencyModules.push(mod);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
if (dependencyModules.length > 0) {
|
102
|
+
throw ( new Error(
|
103
|
+
`Cannot resolve dependencies for script ${scriptSrc}. The dependencies are: ${dependencyModules.join(', ')}`
|
104
|
+
));
|
105
|
+
}
|
106
|
+
if (typeof defineCall.callback === 'function') {
|
107
|
+
return defineCall.callback(...dependencyObjs) ?? exports;
|
108
|
+
}
|
109
|
+
else {
|
110
|
+
return defineCall.callback;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
_rendererLoadScript(scriptSrc) {
|
114
|
+
return ( new Promise((resolve, reject) => {
|
115
|
+
const scriptElement = document.createElement('script');
|
116
|
+
scriptElement.setAttribute('async', 'async');
|
117
|
+
scriptElement.setAttribute('type', 'text/javascript');
|
118
|
+
const unbind = () => {
|
119
|
+
scriptElement.removeEventListener('load', loadEventListener);
|
120
|
+
scriptElement.removeEventListener('error', errorEventListener);
|
121
|
+
};
|
122
|
+
const loadEventListener = (e) => {
|
123
|
+
unbind();
|
124
|
+
resolve(this._defineCalls.pop());
|
125
|
+
};
|
126
|
+
const errorEventListener = (e) => {
|
127
|
+
unbind();
|
128
|
+
reject(e);
|
129
|
+
};
|
130
|
+
scriptElement.addEventListener('load', loadEventListener);
|
131
|
+
scriptElement.addEventListener('error', errorEventListener);
|
132
|
+
if (this._amdPolicy) {
|
133
|
+
scriptSrc = this._amdPolicy.createScriptURL(scriptSrc);
|
134
|
+
}
|
135
|
+
scriptElement.setAttribute('src', scriptSrc);
|
136
|
+
window.document.getElementsByTagName('head')[0].appendChild(scriptElement);
|
137
|
+
}));
|
138
|
+
}
|
139
|
+
async _workerLoadScript(scriptSrc) {
|
140
|
+
if (this._amdPolicy) {
|
141
|
+
scriptSrc = this._amdPolicy.createScriptURL(scriptSrc);
|
142
|
+
}
|
143
|
+
await import(scriptSrc).then(module => module.default ?? module);
|
144
|
+
return this._defineCalls.pop();
|
145
|
+
}
|
146
|
+
async _nodeJSLoadScript(scriptSrc) {
|
147
|
+
try {
|
148
|
+
const fs = (await import(`${'fs'}`).then(module => module.default ?? module)).default;
|
149
|
+
const vm = (await import(`${'vm'}`).then(module => module.default ?? module)).default;
|
150
|
+
const module = (await import(`${'module'}`).then(module => module.default ?? module)).default;
|
151
|
+
const filePath = ( URI.parse(scriptSrc)).fsPath;
|
152
|
+
const content = ( fs.readFileSync(filePath).toString());
|
153
|
+
const scriptSource = module.wrap(content.replace(/^#!.*/, ''));
|
154
|
+
const script = new vm.Script(scriptSource);
|
155
|
+
const compileWrapper = script.runInThisContext();
|
156
|
+
compileWrapper.apply();
|
157
|
+
return this._defineCalls.pop();
|
158
|
+
}
|
159
|
+
catch (error) {
|
160
|
+
throw error;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
const cache = ( new Map());
|
165
|
+
async function importAMDNodeModule(nodeModuleName, pathInsideNodeModule, isBuilt) {
|
166
|
+
if (isBuilt === undefined) {
|
167
|
+
const product = globalThis._VSCODE_PRODUCT_JSON;
|
168
|
+
isBuilt = Boolean((product ?? globalThis.vscode?.context?.configuration()?.product)?.commit);
|
169
|
+
}
|
170
|
+
const nodeModulePath = pathInsideNodeModule ? `${nodeModuleName}/${pathInsideNodeModule}` : nodeModuleName;
|
171
|
+
if (( cache.has(nodeModulePath))) {
|
172
|
+
return cache.get(nodeModulePath);
|
173
|
+
}
|
174
|
+
let scriptSrc;
|
175
|
+
if (/^\w[\w\d+.-]*:\/\//.test(nodeModulePath)) {
|
176
|
+
scriptSrc = nodeModulePath;
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
const actualNodeModulesPath = (nodeModulesPath);
|
180
|
+
const resourcePath = `${actualNodeModulesPath}/${nodeModulePath}`;
|
181
|
+
scriptSrc = ( ( FileAccess.asBrowserUri(resourcePath)).toString(true));
|
182
|
+
}
|
183
|
+
const result = AMDModuleImporter.INSTANCE.load(scriptSrc);
|
184
|
+
cache.set(nodeModulePath, result);
|
185
|
+
return result;
|
186
|
+
}
|
187
|
+
function resolveAmdNodeModulePath(nodeModuleName, pathInsideNodeModule) {
|
188
|
+
const product = globalThis._VSCODE_PRODUCT_JSON;
|
189
|
+
Boolean((product ?? globalThis.vscode?.context?.configuration()?.product)?.commit);
|
190
|
+
const nodeModulePath = `${nodeModuleName}/${pathInsideNodeModule}`;
|
191
|
+
const actualNodeModulesPath = (nodeModulesPath);
|
192
|
+
const resourcePath = `${actualNodeModulesPath}/${nodeModulePath}`;
|
193
|
+
return ( ( FileAccess.asBrowserUri(resourcePath)).toString(true));
|
194
|
+
}
|
195
|
+
|
196
|
+
export { importAMDNodeModule, resolveAmdNodeModulePath };
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import { Color } from "@codingame/monaco-vscode-api/vscode/vs/base/common/color";
|
2
|
+
import { Event } from "@codingame/monaco-vscode-api/vscode/vs/base/common/event";
|
3
|
+
import { IJSONSchema } from "@codingame/monaco-vscode-api/vscode/vs/base/common/jsonSchema";
|
4
|
+
import { IColorTheme } from "@codingame/monaco-vscode-api/vscode/vs/platform/theme/common/themeService";
|
5
|
+
type TokenClassificationString = string;
|
6
|
+
export declare const typeAndModifierIdPattern = "^\\w+[-_\\w+]*$";
|
7
|
+
export interface TokenSelector {
|
8
|
+
match(type: string, modifiers: string[], language: string): number;
|
9
|
+
readonly id: string;
|
10
|
+
}
|
11
|
+
export interface TokenTypeOrModifierContribution {
|
12
|
+
readonly num: number;
|
13
|
+
readonly id: string;
|
14
|
+
readonly superType?: string;
|
15
|
+
readonly description: string;
|
16
|
+
readonly deprecationMessage?: string;
|
17
|
+
}
|
18
|
+
export interface TokenStyleData {
|
19
|
+
foreground: Color | undefined;
|
20
|
+
bold: boolean | undefined;
|
21
|
+
underline: boolean | undefined;
|
22
|
+
strikethrough: boolean | undefined;
|
23
|
+
italic: boolean | undefined;
|
24
|
+
}
|
25
|
+
export declare class TokenStyle implements Readonly<TokenStyleData> {
|
26
|
+
readonly foreground: Color | undefined;
|
27
|
+
readonly bold: boolean | undefined;
|
28
|
+
readonly underline: boolean | undefined;
|
29
|
+
readonly strikethrough: boolean | undefined;
|
30
|
+
readonly italic: boolean | undefined;
|
31
|
+
constructor(foreground: Color | undefined, bold: boolean | undefined, underline: boolean | undefined, strikethrough: boolean | undefined, italic: boolean | undefined);
|
32
|
+
}
|
33
|
+
export declare namespace TokenStyle {
|
34
|
+
function toJSONObject(style: TokenStyle): any;
|
35
|
+
function fromJSONObject(obj: any): TokenStyle | undefined;
|
36
|
+
function equals(s1: any, s2: any): boolean;
|
37
|
+
function is(s: any): s is TokenStyle;
|
38
|
+
function fromData(data: {
|
39
|
+
foreground: Color | undefined;
|
40
|
+
bold: boolean | undefined;
|
41
|
+
underline: boolean | undefined;
|
42
|
+
strikethrough: boolean | undefined;
|
43
|
+
italic: boolean | undefined;
|
44
|
+
}): TokenStyle;
|
45
|
+
function fromSettings(foreground: string | undefined, fontStyle: string | undefined): TokenStyle;
|
46
|
+
function fromSettings(foreground: string | undefined, fontStyle: string | undefined, bold: boolean | undefined, underline: boolean | undefined, strikethrough: boolean | undefined, italic: boolean | undefined): TokenStyle;
|
47
|
+
}
|
48
|
+
export type ProbeScope = string[];
|
49
|
+
export interface TokenStyleFunction {
|
50
|
+
(theme: IColorTheme): TokenStyle | undefined;
|
51
|
+
}
|
52
|
+
export interface TokenStyleDefaults {
|
53
|
+
scopesToProbe?: ProbeScope[];
|
54
|
+
light?: TokenStyleValue;
|
55
|
+
dark?: TokenStyleValue;
|
56
|
+
hcDark?: TokenStyleValue;
|
57
|
+
hcLight?: TokenStyleValue;
|
58
|
+
}
|
59
|
+
export interface SemanticTokenDefaultRule {
|
60
|
+
selector: TokenSelector;
|
61
|
+
defaults: TokenStyleDefaults;
|
62
|
+
}
|
63
|
+
export interface SemanticTokenRule {
|
64
|
+
style: TokenStyle;
|
65
|
+
selector: TokenSelector;
|
66
|
+
}
|
67
|
+
export declare namespace SemanticTokenRule {
|
68
|
+
function fromJSONObject(registry: ITokenClassificationRegistry, o: any): SemanticTokenRule | undefined;
|
69
|
+
function toJSONObject(rule: SemanticTokenRule): any;
|
70
|
+
function equals(r1: SemanticTokenRule | undefined, r2: SemanticTokenRule | undefined): boolean;
|
71
|
+
function is(r: any): r is SemanticTokenRule;
|
72
|
+
}
|
73
|
+
export type TokenStyleValue = TokenStyle | TokenClassificationString;
|
74
|
+
export interface ITokenClassificationRegistry {
|
75
|
+
readonly onDidChangeSchema: Event<void>;
|
76
|
+
registerTokenType(id: string, description: string, superType?: string, deprecationMessage?: string): void;
|
77
|
+
registerTokenModifier(id: string, description: string): void;
|
78
|
+
parseTokenSelector(selectorString: string, language?: string): TokenSelector;
|
79
|
+
registerTokenStyleDefault(selector: TokenSelector, defaults: TokenStyleDefaults): void;
|
80
|
+
deregisterTokenStyleDefault(selector: TokenSelector): void;
|
81
|
+
deregisterTokenType(id: string): void;
|
82
|
+
deregisterTokenModifier(id: string): void;
|
83
|
+
getTokenTypes(): TokenTypeOrModifierContribution[];
|
84
|
+
getTokenModifiers(): TokenTypeOrModifierContribution[];
|
85
|
+
getTokenStylingDefaultRules(): SemanticTokenDefaultRule[];
|
86
|
+
getTokenStylingSchema(): IJSONSchema;
|
87
|
+
}
|
88
|
+
export declare function parseClassifierString(s: string, defaultLanguage: string): {
|
89
|
+
type: string;
|
90
|
+
modifiers: string[];
|
91
|
+
language: string;
|
92
|
+
};
|
93
|
+
export declare function parseClassifierString(s: string, defaultLanguage?: string): {
|
94
|
+
type: string;
|
95
|
+
modifiers: string[];
|
96
|
+
language: string | undefined;
|
97
|
+
};
|
98
|
+
export declare function getTokenClassificationRegistry(): ITokenClassificationRegistry;
|
99
|
+
export declare const tokenStylingSchemaId = "vscode://schemas/token-styling";
|
100
|
+
export {};
|
@@ -0,0 +1,472 @@
|
|
1
|
+
|
2
|
+
import { RunOnceScheduler } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
|
3
|
+
import { Color } from '@codingame/monaco-vscode-api/vscode/vs/base/common/color';
|
4
|
+
import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
5
|
+
import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
6
|
+
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
|
7
|
+
import { Extensions as Extensions$1 } from '@codingame/monaco-vscode-api/vscode/vs/platform/jsonschemas/common/jsonContributionRegistry';
|
8
|
+
import { Registry } from '@codingame/monaco-vscode-api/vscode/vs/platform/registry/common/platform';
|
9
|
+
|
10
|
+
const TOKEN_TYPE_WILDCARD = '*';
|
11
|
+
const TOKEN_CLASSIFIER_LANGUAGE_SEPARATOR = ':';
|
12
|
+
const CLASSIFIER_MODIFIER_SEPARATOR = '.';
|
13
|
+
const idPattern = '\\w+[-_\\w+]*';
|
14
|
+
const typeAndModifierIdPattern = `^${idPattern}$`;
|
15
|
+
const selectorPattern = `^(${idPattern}|\\*)(\\${CLASSIFIER_MODIFIER_SEPARATOR}${idPattern})*(${TOKEN_CLASSIFIER_LANGUAGE_SEPARATOR}${idPattern})?$`;
|
16
|
+
const fontStylePattern = '^(\\s*(italic|bold|underline|strikethrough))*\\s*$';
|
17
|
+
class TokenStyle {
|
18
|
+
constructor(foreground, bold, underline, strikethrough, italic) {
|
19
|
+
this.foreground = foreground;
|
20
|
+
this.bold = bold;
|
21
|
+
this.underline = underline;
|
22
|
+
this.strikethrough = strikethrough;
|
23
|
+
this.italic = italic;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
(function (TokenStyle) {
|
27
|
+
function toJSONObject(style) {
|
28
|
+
return {
|
29
|
+
_foreground: style.foreground === undefined ? null : Color.Format.CSS.formatHexA(style.foreground, true),
|
30
|
+
_bold: style.bold === undefined ? null : style.bold,
|
31
|
+
_underline: style.underline === undefined ? null : style.underline,
|
32
|
+
_italic: style.italic === undefined ? null : style.italic,
|
33
|
+
_strikethrough: style.strikethrough === undefined ? null : style.strikethrough,
|
34
|
+
};
|
35
|
+
}
|
36
|
+
TokenStyle.toJSONObject = toJSONObject;
|
37
|
+
function fromJSONObject(obj) {
|
38
|
+
if (obj) {
|
39
|
+
const boolOrUndef = (b) => (typeof b === 'boolean') ? b : undefined;
|
40
|
+
const colorOrUndef = (s) => (typeof s === 'string') ? ( Color.fromHex(s)) : undefined;
|
41
|
+
return ( new TokenStyle(
|
42
|
+
colorOrUndef(obj._foreground),
|
43
|
+
boolOrUndef(obj._bold),
|
44
|
+
boolOrUndef(obj._underline),
|
45
|
+
boolOrUndef(obj._strikethrough),
|
46
|
+
boolOrUndef(obj._italic)
|
47
|
+
));
|
48
|
+
}
|
49
|
+
return undefined;
|
50
|
+
}
|
51
|
+
TokenStyle.fromJSONObject = fromJSONObject;
|
52
|
+
function equals(s1, s2) {
|
53
|
+
if (s1 === s2) {
|
54
|
+
return true;
|
55
|
+
}
|
56
|
+
return s1 !== undefined && s2 !== undefined
|
57
|
+
&& (s1.foreground instanceof Color ? s1.foreground.equals(s2.foreground) : s2.foreground === undefined)
|
58
|
+
&& s1.bold === s2.bold
|
59
|
+
&& s1.underline === s2.underline
|
60
|
+
&& s1.strikethrough === s2.strikethrough
|
61
|
+
&& s1.italic === s2.italic;
|
62
|
+
}
|
63
|
+
TokenStyle.equals = equals;
|
64
|
+
function is(s) {
|
65
|
+
return s instanceof TokenStyle;
|
66
|
+
}
|
67
|
+
TokenStyle.is = is;
|
68
|
+
function fromData(data) {
|
69
|
+
return ( new TokenStyle(
|
70
|
+
data.foreground,
|
71
|
+
data.bold,
|
72
|
+
data.underline,
|
73
|
+
data.strikethrough,
|
74
|
+
data.italic
|
75
|
+
));
|
76
|
+
}
|
77
|
+
TokenStyle.fromData = fromData;
|
78
|
+
function fromSettings(foreground, fontStyle, bold, underline, strikethrough, italic) {
|
79
|
+
let foregroundColor = undefined;
|
80
|
+
if (foreground !== undefined) {
|
81
|
+
foregroundColor = ( Color.fromHex(foreground));
|
82
|
+
}
|
83
|
+
if (fontStyle !== undefined) {
|
84
|
+
bold = italic = underline = strikethrough = false;
|
85
|
+
const expression = /italic|bold|underline|strikethrough/g;
|
86
|
+
let match;
|
87
|
+
while ((match = expression.exec(fontStyle))) {
|
88
|
+
switch (match[0]) {
|
89
|
+
case 'bold':
|
90
|
+
bold = true;
|
91
|
+
break;
|
92
|
+
case 'italic':
|
93
|
+
italic = true;
|
94
|
+
break;
|
95
|
+
case 'underline':
|
96
|
+
underline = true;
|
97
|
+
break;
|
98
|
+
case 'strikethrough':
|
99
|
+
strikethrough = true;
|
100
|
+
break;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
return ( new TokenStyle(foregroundColor, bold, underline, strikethrough, italic));
|
105
|
+
}
|
106
|
+
TokenStyle.fromSettings = fromSettings;
|
107
|
+
})(TokenStyle || (TokenStyle = {}));
|
108
|
+
var SemanticTokenRule;
|
109
|
+
(function (SemanticTokenRule) {
|
110
|
+
function fromJSONObject(registry, o) {
|
111
|
+
if (o && typeof o._selector === 'string' && o._style) {
|
112
|
+
const style = TokenStyle.fromJSONObject(o._style);
|
113
|
+
if (style) {
|
114
|
+
try {
|
115
|
+
return { selector: registry.parseTokenSelector(o._selector), style };
|
116
|
+
}
|
117
|
+
catch (_ignore) {
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
return undefined;
|
122
|
+
}
|
123
|
+
SemanticTokenRule.fromJSONObject = fromJSONObject;
|
124
|
+
function toJSONObject(rule) {
|
125
|
+
return {
|
126
|
+
_selector: rule.selector.id,
|
127
|
+
_style: TokenStyle.toJSONObject(rule.style)
|
128
|
+
};
|
129
|
+
}
|
130
|
+
SemanticTokenRule.toJSONObject = toJSONObject;
|
131
|
+
function equals(r1, r2) {
|
132
|
+
if (r1 === r2) {
|
133
|
+
return true;
|
134
|
+
}
|
135
|
+
return r1 !== undefined && r2 !== undefined
|
136
|
+
&& r1.selector && r2.selector && r1.selector.id === r2.selector.id
|
137
|
+
&& TokenStyle.equals(r1.style, r2.style);
|
138
|
+
}
|
139
|
+
SemanticTokenRule.equals = equals;
|
140
|
+
function is(r) {
|
141
|
+
return r && r.selector && typeof r.selector.id === 'string' && TokenStyle.is(r.style);
|
142
|
+
}
|
143
|
+
SemanticTokenRule.is = is;
|
144
|
+
})(SemanticTokenRule || (SemanticTokenRule = {}));
|
145
|
+
const Extensions = {
|
146
|
+
TokenClassificationContribution: 'base.contributions.tokenClassification'
|
147
|
+
};
|
148
|
+
class TokenClassificationRegistry extends Disposable {
|
149
|
+
constructor() {
|
150
|
+
super();
|
151
|
+
this._onDidChangeSchema = this._register(( new Emitter()));
|
152
|
+
this.onDidChangeSchema = this._onDidChangeSchema.event;
|
153
|
+
this.currentTypeNumber = 0;
|
154
|
+
this.currentModifierBit = 1;
|
155
|
+
this.tokenStylingDefaultRules = [];
|
156
|
+
this.tokenStylingSchema = {
|
157
|
+
type: 'object',
|
158
|
+
properties: {},
|
159
|
+
patternProperties: {
|
160
|
+
[selectorPattern]: getStylingSchemeEntry()
|
161
|
+
},
|
162
|
+
additionalProperties: false,
|
163
|
+
definitions: {
|
164
|
+
style: {
|
165
|
+
type: 'object',
|
166
|
+
description: ( localize(2331, 'Colors and styles for the token.')),
|
167
|
+
properties: {
|
168
|
+
foreground: {
|
169
|
+
type: 'string',
|
170
|
+
description: ( localize(2332, 'Foreground color for the token.')),
|
171
|
+
format: 'color-hex',
|
172
|
+
default: '#ff0000'
|
173
|
+
},
|
174
|
+
background: {
|
175
|
+
type: 'string',
|
176
|
+
deprecationMessage: ( localize(2333, 'Token background colors are currently not supported.'))
|
177
|
+
},
|
178
|
+
fontStyle: {
|
179
|
+
type: 'string',
|
180
|
+
description: ( localize(
|
181
|
+
2334,
|
182
|
+
'Sets the all font styles of the rule: \'italic\', \'bold\', \'underline\' or \'strikethrough\' or a combination. All styles that are not listed are unset. The empty string unsets all styles.'
|
183
|
+
)),
|
184
|
+
pattern: fontStylePattern,
|
185
|
+
patternErrorMessage: ( localize(
|
186
|
+
2335,
|
187
|
+
'Font style must be \'italic\', \'bold\', \'underline\' or \'strikethrough\' or a combination. The empty string unsets all styles.'
|
188
|
+
)),
|
189
|
+
defaultSnippets: [
|
190
|
+
{ label: ( localize(2336, 'None (clear inherited style)')), bodyText: '""' },
|
191
|
+
{ body: 'italic' },
|
192
|
+
{ body: 'bold' },
|
193
|
+
{ body: 'underline' },
|
194
|
+
{ body: 'strikethrough' },
|
195
|
+
{ body: 'italic bold' },
|
196
|
+
{ body: 'italic underline' },
|
197
|
+
{ body: 'italic strikethrough' },
|
198
|
+
{ body: 'bold underline' },
|
199
|
+
{ body: 'bold strikethrough' },
|
200
|
+
{ body: 'underline strikethrough' },
|
201
|
+
{ body: 'italic bold underline' },
|
202
|
+
{ body: 'italic bold strikethrough' },
|
203
|
+
{ body: 'italic underline strikethrough' },
|
204
|
+
{ body: 'bold underline strikethrough' },
|
205
|
+
{ body: 'italic bold underline strikethrough' }
|
206
|
+
]
|
207
|
+
},
|
208
|
+
bold: {
|
209
|
+
type: 'boolean',
|
210
|
+
description: ( localize(
|
211
|
+
2337,
|
212
|
+
'Sets or unsets the font style to bold. Note, the presence of \'fontStyle\' overrides this setting.'
|
213
|
+
)),
|
214
|
+
},
|
215
|
+
italic: {
|
216
|
+
type: 'boolean',
|
217
|
+
description: ( localize(
|
218
|
+
2338,
|
219
|
+
'Sets or unsets the font style to italic. Note, the presence of \'fontStyle\' overrides this setting.'
|
220
|
+
)),
|
221
|
+
},
|
222
|
+
underline: {
|
223
|
+
type: 'boolean',
|
224
|
+
description: ( localize(
|
225
|
+
2339,
|
226
|
+
'Sets or unsets the font style to underline. Note, the presence of \'fontStyle\' overrides this setting.'
|
227
|
+
)),
|
228
|
+
},
|
229
|
+
strikethrough: {
|
230
|
+
type: 'boolean',
|
231
|
+
description: ( localize(
|
232
|
+
2340,
|
233
|
+
'Sets or unsets the font style to strikethrough. Note, the presence of \'fontStyle\' overrides this setting.'
|
234
|
+
)),
|
235
|
+
}
|
236
|
+
},
|
237
|
+
defaultSnippets: [{ body: { foreground: '${1:#FF0000}', fontStyle: '${2:bold}' } }]
|
238
|
+
}
|
239
|
+
}
|
240
|
+
};
|
241
|
+
this.tokenTypeById = Object.create(null);
|
242
|
+
this.tokenModifierById = Object.create(null);
|
243
|
+
this.typeHierarchy = Object.create(null);
|
244
|
+
}
|
245
|
+
registerTokenType(id, description, superType, deprecationMessage) {
|
246
|
+
if (!id.match(typeAndModifierIdPattern)) {
|
247
|
+
throw ( new Error('Invalid token type id.'));
|
248
|
+
}
|
249
|
+
if (superType && !superType.match(typeAndModifierIdPattern)) {
|
250
|
+
throw ( new Error('Invalid token super type id.'));
|
251
|
+
}
|
252
|
+
const num = this.currentTypeNumber++;
|
253
|
+
const tokenStyleContribution = { num, id, superType, description, deprecationMessage };
|
254
|
+
this.tokenTypeById[id] = tokenStyleContribution;
|
255
|
+
const stylingSchemeEntry = getStylingSchemeEntry(description, deprecationMessage);
|
256
|
+
this.tokenStylingSchema.properties[id] = stylingSchemeEntry;
|
257
|
+
this.typeHierarchy = Object.create(null);
|
258
|
+
}
|
259
|
+
registerTokenModifier(id, description, deprecationMessage) {
|
260
|
+
if (!id.match(typeAndModifierIdPattern)) {
|
261
|
+
throw ( new Error('Invalid token modifier id.'));
|
262
|
+
}
|
263
|
+
const num = this.currentModifierBit;
|
264
|
+
this.currentModifierBit = this.currentModifierBit * 2;
|
265
|
+
const tokenStyleContribution = { num, id, description, deprecationMessage };
|
266
|
+
this.tokenModifierById[id] = tokenStyleContribution;
|
267
|
+
this.tokenStylingSchema.properties[`*.${id}`] = getStylingSchemeEntry(description, deprecationMessage);
|
268
|
+
}
|
269
|
+
parseTokenSelector(selectorString, language) {
|
270
|
+
const selector = parseClassifierString(selectorString, language);
|
271
|
+
if (!selector.type) {
|
272
|
+
return {
|
273
|
+
match: () => -1,
|
274
|
+
id: '$invalid'
|
275
|
+
};
|
276
|
+
}
|
277
|
+
return {
|
278
|
+
match: (type, modifiers, language) => {
|
279
|
+
let score = 0;
|
280
|
+
if (selector.language !== undefined) {
|
281
|
+
if (selector.language !== language) {
|
282
|
+
return -1;
|
283
|
+
}
|
284
|
+
score += 10;
|
285
|
+
}
|
286
|
+
if (selector.type !== TOKEN_TYPE_WILDCARD) {
|
287
|
+
const hierarchy = this.getTypeHierarchy(type);
|
288
|
+
const level = hierarchy.indexOf(selector.type);
|
289
|
+
if (level === -1) {
|
290
|
+
return -1;
|
291
|
+
}
|
292
|
+
score += (100 - level);
|
293
|
+
}
|
294
|
+
for (const selectorModifier of selector.modifiers) {
|
295
|
+
if (modifiers.indexOf(selectorModifier) === -1) {
|
296
|
+
return -1;
|
297
|
+
}
|
298
|
+
}
|
299
|
+
return score + selector.modifiers.length * 100;
|
300
|
+
},
|
301
|
+
id: `${[selector.type, ...selector.modifiers.sort()].join('.')}${selector.language !== undefined ? ':' + selector.language : ''}`
|
302
|
+
};
|
303
|
+
}
|
304
|
+
registerTokenStyleDefault(selector, defaults) {
|
305
|
+
this.tokenStylingDefaultRules.push({ selector, defaults });
|
306
|
+
}
|
307
|
+
deregisterTokenStyleDefault(selector) {
|
308
|
+
const selectorString = selector.id;
|
309
|
+
this.tokenStylingDefaultRules = this.tokenStylingDefaultRules.filter(r => r.selector.id !== selectorString);
|
310
|
+
}
|
311
|
+
deregisterTokenType(id) {
|
312
|
+
delete this.tokenTypeById[id];
|
313
|
+
delete this.tokenStylingSchema.properties[id];
|
314
|
+
this.typeHierarchy = Object.create(null);
|
315
|
+
}
|
316
|
+
deregisterTokenModifier(id) {
|
317
|
+
delete this.tokenModifierById[id];
|
318
|
+
delete this.tokenStylingSchema.properties[`*.${id}`];
|
319
|
+
}
|
320
|
+
getTokenTypes() {
|
321
|
+
return ( ( Object.keys(this.tokenTypeById)).map(id => this.tokenTypeById[id]));
|
322
|
+
}
|
323
|
+
getTokenModifiers() {
|
324
|
+
return ( ( Object.keys(this.tokenModifierById)).map(id => this.tokenModifierById[id]));
|
325
|
+
}
|
326
|
+
getTokenStylingSchema() {
|
327
|
+
return this.tokenStylingSchema;
|
328
|
+
}
|
329
|
+
getTokenStylingDefaultRules() {
|
330
|
+
return this.tokenStylingDefaultRules;
|
331
|
+
}
|
332
|
+
getTypeHierarchy(typeId) {
|
333
|
+
let hierarchy = this.typeHierarchy[typeId];
|
334
|
+
if (!hierarchy) {
|
335
|
+
this.typeHierarchy[typeId] = hierarchy = [typeId];
|
336
|
+
let type = this.tokenTypeById[typeId];
|
337
|
+
while (type && type.superType) {
|
338
|
+
hierarchy.push(type.superType);
|
339
|
+
type = this.tokenTypeById[type.superType];
|
340
|
+
}
|
341
|
+
}
|
342
|
+
return hierarchy;
|
343
|
+
}
|
344
|
+
toString() {
|
345
|
+
const sorter = (a, b) => {
|
346
|
+
const cat1 = a.indexOf('.') === -1 ? 0 : 1;
|
347
|
+
const cat2 = b.indexOf('.') === -1 ? 0 : 1;
|
348
|
+
if (cat1 !== cat2) {
|
349
|
+
return cat1 - cat2;
|
350
|
+
}
|
351
|
+
return a.localeCompare(b);
|
352
|
+
};
|
353
|
+
return ( ( Object.keys(this.tokenTypeById)).sort(sorter).map(k => `- \`${k}\`: ${this.tokenTypeById[k].description}`)).join('\n');
|
354
|
+
}
|
355
|
+
}
|
356
|
+
const CHAR_LANGUAGE = TOKEN_CLASSIFIER_LANGUAGE_SEPARATOR.charCodeAt(0);
|
357
|
+
const CHAR_MODIFIER = CLASSIFIER_MODIFIER_SEPARATOR.charCodeAt(0);
|
358
|
+
function parseClassifierString(s, defaultLanguage) {
|
359
|
+
let k = s.length;
|
360
|
+
let language = defaultLanguage;
|
361
|
+
const modifiers = [];
|
362
|
+
for (let i = k - 1; i >= 0; i--) {
|
363
|
+
const ch = s.charCodeAt(i);
|
364
|
+
if (ch === CHAR_LANGUAGE || ch === CHAR_MODIFIER) {
|
365
|
+
const segment = s.substring(i + 1, k);
|
366
|
+
k = i;
|
367
|
+
if (ch === CHAR_LANGUAGE) {
|
368
|
+
language = segment;
|
369
|
+
}
|
370
|
+
else {
|
371
|
+
modifiers.push(segment);
|
372
|
+
}
|
373
|
+
}
|
374
|
+
}
|
375
|
+
const type = s.substring(0, k);
|
376
|
+
return { type, modifiers, language };
|
377
|
+
}
|
378
|
+
const tokenClassificationRegistry = createDefaultTokenClassificationRegistry();
|
379
|
+
Registry.add(Extensions.TokenClassificationContribution, tokenClassificationRegistry);
|
380
|
+
function createDefaultTokenClassificationRegistry() {
|
381
|
+
const registry = ( new TokenClassificationRegistry());
|
382
|
+
function registerTokenType(id, description, scopesToProbe = [], superType, deprecationMessage) {
|
383
|
+
registry.registerTokenType(id, description, superType, deprecationMessage);
|
384
|
+
if (scopesToProbe) {
|
385
|
+
registerTokenStyleDefault(id, scopesToProbe);
|
386
|
+
}
|
387
|
+
return id;
|
388
|
+
}
|
389
|
+
function registerTokenStyleDefault(selectorString, scopesToProbe) {
|
390
|
+
try {
|
391
|
+
const selector = registry.parseTokenSelector(selectorString);
|
392
|
+
registry.registerTokenStyleDefault(selector, { scopesToProbe });
|
393
|
+
}
|
394
|
+
catch (e) {
|
395
|
+
console.log(e);
|
396
|
+
}
|
397
|
+
}
|
398
|
+
registerTokenType('comment', ( localize(2341, "Style for comments.")), [['comment']]);
|
399
|
+
registerTokenType('string', ( localize(2342, "Style for strings.")), [['string']]);
|
400
|
+
registerTokenType('keyword', ( localize(2343, "Style for keywords.")), [['keyword.control']]);
|
401
|
+
registerTokenType('number', ( localize(2344, "Style for numbers.")), [['constant.numeric']]);
|
402
|
+
registerTokenType('regexp', ( localize(2345, "Style for expressions.")), [['constant.regexp']]);
|
403
|
+
registerTokenType('operator', ( localize(2346, "Style for operators.")), [['keyword.operator']]);
|
404
|
+
registerTokenType('namespace', ( localize(2347, "Style for namespaces.")), [['entity.name.namespace']]);
|
405
|
+
registerTokenType('type', ( localize(2348, "Style for types.")), [['entity.name.type'], ['support.type']]);
|
406
|
+
registerTokenType('struct', ( localize(2349, "Style for structs.")), [['entity.name.type.struct']]);
|
407
|
+
registerTokenType('class', ( localize(2350, "Style for classes.")), [['entity.name.type.class'], ['support.class']]);
|
408
|
+
registerTokenType('interface', ( localize(2351, "Style for interfaces.")), [['entity.name.type.interface']]);
|
409
|
+
registerTokenType('enum', ( localize(2352, "Style for enums.")), [['entity.name.type.enum']]);
|
410
|
+
registerTokenType('typeParameter', ( localize(2353, "Style for type parameters.")), [['entity.name.type.parameter']]);
|
411
|
+
registerTokenType('function', ( localize(2354, "Style for functions")), [['entity.name.function'], ['support.function']]);
|
412
|
+
registerTokenType('member', ( localize(2355, "Style for member functions")), [], 'method', 'Deprecated use `method` instead');
|
413
|
+
registerTokenType('method', ( localize(2356, "Style for method (member functions)")), [['entity.name.function.member'], ['support.function']]);
|
414
|
+
registerTokenType('macro', ( localize(2357, "Style for macros.")), [['entity.name.function.preprocessor']]);
|
415
|
+
registerTokenType('variable', ( localize(2358, "Style for variables.")), [['variable.other.readwrite'], ['entity.name.variable']]);
|
416
|
+
registerTokenType('parameter', ( localize(2359, "Style for parameters.")), [['variable.parameter']]);
|
417
|
+
registerTokenType('property', ( localize(2360, "Style for properties.")), [['variable.other.property']]);
|
418
|
+
registerTokenType('enumMember', ( localize(2361, "Style for enum members.")), [['variable.other.enummember']]);
|
419
|
+
registerTokenType('event', ( localize(2362, "Style for events.")), [['variable.other.event']]);
|
420
|
+
registerTokenType('decorator', ( localize(2363, "Style for decorators & annotations.")), [['entity.name.decorator'], ['entity.name.function']]);
|
421
|
+
registerTokenType('label', ( localize(2364, "Style for labels. ")), undefined);
|
422
|
+
registry.registerTokenModifier('declaration', ( localize(2365, "Style for all symbol declarations.")), undefined);
|
423
|
+
registry.registerTokenModifier('documentation', ( localize(2366, "Style to use for references in documentation.")), undefined);
|
424
|
+
registry.registerTokenModifier('static', ( localize(2367, "Style to use for symbols that are static.")), undefined);
|
425
|
+
registry.registerTokenModifier('abstract', ( localize(2368, "Style to use for symbols that are abstract.")), undefined);
|
426
|
+
registry.registerTokenModifier('deprecated', ( localize(2369, "Style to use for symbols that are deprecated.")), undefined);
|
427
|
+
registry.registerTokenModifier('modification', ( localize(2370, "Style to use for write accesses.")), undefined);
|
428
|
+
registry.registerTokenModifier('async', ( localize(2371, "Style to use for symbols that are async.")), undefined);
|
429
|
+
registry.registerTokenModifier('readonly', ( localize(2372, "Style to use for symbols that are read-only.")), undefined);
|
430
|
+
registerTokenStyleDefault('variable.readonly', [['variable.other.constant']]);
|
431
|
+
registerTokenStyleDefault('property.readonly', [['variable.other.constant.property']]);
|
432
|
+
registerTokenStyleDefault('type.defaultLibrary', [['support.type']]);
|
433
|
+
registerTokenStyleDefault('class.defaultLibrary', [['support.class']]);
|
434
|
+
registerTokenStyleDefault('interface.defaultLibrary', [['support.class']]);
|
435
|
+
registerTokenStyleDefault('variable.defaultLibrary', [['support.variable'], ['support.other.variable']]);
|
436
|
+
registerTokenStyleDefault('variable.defaultLibrary.readonly', [['support.constant']]);
|
437
|
+
registerTokenStyleDefault('property.defaultLibrary', [['support.variable.property']]);
|
438
|
+
registerTokenStyleDefault('property.defaultLibrary.readonly', [['support.constant.property']]);
|
439
|
+
registerTokenStyleDefault('function.defaultLibrary', [['support.function']]);
|
440
|
+
registerTokenStyleDefault('member.defaultLibrary', [['support.function']]);
|
441
|
+
return registry;
|
442
|
+
}
|
443
|
+
function getTokenClassificationRegistry() {
|
444
|
+
return tokenClassificationRegistry;
|
445
|
+
}
|
446
|
+
function getStylingSchemeEntry(description, deprecationMessage) {
|
447
|
+
return {
|
448
|
+
description,
|
449
|
+
deprecationMessage,
|
450
|
+
defaultSnippets: [{ body: '${1:#ff0000}' }],
|
451
|
+
anyOf: [
|
452
|
+
{
|
453
|
+
type: 'string',
|
454
|
+
format: 'color-hex'
|
455
|
+
},
|
456
|
+
{
|
457
|
+
$ref: '#/definitions/style'
|
458
|
+
}
|
459
|
+
]
|
460
|
+
};
|
461
|
+
}
|
462
|
+
const tokenStylingSchemaId = 'vscode://schemas/token-styling';
|
463
|
+
const schemaRegistry = Registry.as(Extensions$1.JSONContribution);
|
464
|
+
schemaRegistry.registerSchema(tokenStylingSchemaId, tokenClassificationRegistry.getTokenStylingSchema());
|
465
|
+
const delayer = ( new RunOnceScheduler(() => schemaRegistry.notifySchemaChanged(tokenStylingSchemaId), 200));
|
466
|
+
tokenClassificationRegistry.onDidChangeSchema(() => {
|
467
|
+
if (!delayer.isScheduled()) {
|
468
|
+
delayer.schedule();
|
469
|
+
}
|
470
|
+
});
|
471
|
+
|
472
|
+
export { SemanticTokenRule, TokenStyle, getTokenClassificationRegistry, parseClassifierString, tokenStylingSchemaId, typeAndModifierIdPattern };
|