@codingame/monaco-vscode-monarch-service-override 4.5.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/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './monarch.js';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default } from './monarch.js';
package/monarch.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { IEditorOverrideServices } from 'vscode/vscode/vs/editor/standalone/browser/standaloneServices';
2
+
3
+ declare function getServiceOverride(): IEditorOverrideServices;
4
+
5
+ export { getServiceOverride as default };
package/monarch.js ADDED
@@ -0,0 +1,8 @@
1
+ import './vscode/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.js';
2
+ import './vscode/src/vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast.js';
3
+
4
+ function getServiceOverride() {
5
+ return {};
6
+ }
7
+
8
+ export { getServiceOverride as default };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@codingame/monaco-vscode-monarch-service-override",
3
+ "version": "4.5.0",
4
+ "keywords": [],
5
+ "author": {
6
+ "name": "CodinGame",
7
+ "url": "http://www.codingame.com"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git@github.com:CodinGame/monaco-vscode-api.git"
13
+ },
14
+ "type": "module",
15
+ "private": false,
16
+ "description": "VSCode public API plugged on the monaco editor - monarch service-override",
17
+ "main": "index.js",
18
+ "module": "index.js",
19
+ "types": "index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "default": "./index.js"
23
+ },
24
+ "./vscode/*": {
25
+ "default": "./vscode/src/*.js"
26
+ }
27
+ },
28
+ "dependencies": {
29
+ "vscode": "npm:@codingame/monaco-vscode-api@4.5.0"
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import n from 'vscode/external/rollup-plugin-styles/dist/runtime/inject-css.js';
2
+
3
+ var css = ".monaco-editor .tokens-inspect-widget{background-color:var(--vscode-editorHoverWidget-background);border:1px solid var(--vscode-editorHoverWidget-border);color:var(--vscode-editorHoverWidget-foreground);padding:10px;user-select:text;-webkit-user-select:text;z-index:50}.monaco-editor.hc-black .tokens-inspect-widget,.monaco-editor.hc-light .tokens-inspect-widget{border-width:2px}.monaco-editor .tokens-inspect-widget .tokens-inspect-separator{background-color:var(--vscode-editorHoverWidget-border);border:0;height:1px}.monaco-editor .tokens-inspect-widget .tm-token{font-family:var(--monaco-monospace-font)}.monaco-editor .tokens-inspect-widget .tm-token-length{float:right;font-size:60%;font-weight:400}.monaco-editor .tokens-inspect-widget .tm-metadata-table{width:100%}.monaco-editor .tokens-inspect-widget .tm-metadata-value{font-family:var(--monaco-monospace-font);text-align:right}.monaco-editor .tokens-inspect-widget .tm-token-type{font-family:var(--monaco-monospace-font)}";
4
+ n(css,{});
5
+
6
+ export { css, css as default };
@@ -0,0 +1,227 @@
1
+ import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
2
+ import './inspectTokens.css.js';
3
+ import { reset, $, append } from 'vscode/vscode/vs/base/browser/dom';
4
+ import { Color } from 'vscode/vscode/vs/base/common/color';
5
+ import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
6
+ import { EditorAction, registerEditorContribution, registerEditorAction } from 'vscode/vscode/vs/editor/browser/editorExtensions';
7
+ import { TokenizationRegistry } from 'vscode/vscode/vs/editor/common/languages';
8
+ import { TokenMetadata } from 'vscode/vscode/vs/editor/common/encodedTokenAttributes';
9
+ import { NullState, nullTokenize, nullTokenizeEncoded } from 'vscode/vscode/vs/editor/common/languages/nullTokenize';
10
+ import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
11
+ import { IStandaloneThemeService } from 'vscode/vscode/vs/editor/standalone/common/standaloneTheme';
12
+ import { InspectTokensNLS } from 'vscode/vscode/vs/editor/common/standaloneStrings';
13
+
14
+ var InspectTokensController_1;
15
+ let InspectTokensController = class InspectTokensController extends Disposable {
16
+ static { InspectTokensController_1 = this; }
17
+ static { this.ID = 'editor.contrib.inspectTokens'; }
18
+ static get(editor) {
19
+ return editor.getContribution(InspectTokensController_1.ID);
20
+ }
21
+ constructor(editor, standaloneColorService, languageService) {
22
+ super();
23
+ this._editor = editor;
24
+ this._languageService = languageService;
25
+ this._widget = null;
26
+ this._register(this._editor.onDidChangeModel((e) => this.stop()));
27
+ this._register(this._editor.onDidChangeModelLanguage((e) => this.stop()));
28
+ this._register(TokenizationRegistry.onDidChange((e) => this.stop()));
29
+ this._register(this._editor.onKeyUp((e) => e.keyCode === 9 && this.stop()));
30
+ }
31
+ dispose() {
32
+ this.stop();
33
+ super.dispose();
34
+ }
35
+ launch() {
36
+ if (this._widget) {
37
+ return;
38
+ }
39
+ if (!this._editor.hasModel()) {
40
+ return;
41
+ }
42
+ this._widget = ( new InspectTokensWidget(this._editor, this._languageService));
43
+ }
44
+ stop() {
45
+ if (this._widget) {
46
+ this._widget.dispose();
47
+ this._widget = null;
48
+ }
49
+ }
50
+ };
51
+ InspectTokensController = InspectTokensController_1 = ( __decorate([
52
+ ( __param(1, IStandaloneThemeService)),
53
+ ( __param(2, ILanguageService))
54
+ ], InspectTokensController));
55
+ class InspectTokens extends EditorAction {
56
+ constructor() {
57
+ super({
58
+ id: 'editor.action.inspectTokens',
59
+ label: InspectTokensNLS.inspectTokensAction,
60
+ alias: 'Developer: Inspect Tokens',
61
+ precondition: undefined
62
+ });
63
+ }
64
+ run(accessor, editor) {
65
+ const controller = InspectTokensController.get(editor);
66
+ controller?.launch();
67
+ }
68
+ }
69
+ function renderTokenText(tokenText) {
70
+ let result = '';
71
+ for (let charIndex = 0, len = tokenText.length; charIndex < len; charIndex++) {
72
+ const charCode = tokenText.charCodeAt(charIndex);
73
+ switch (charCode) {
74
+ case 9 :
75
+ result += '\u2192';
76
+ break;
77
+ case 32 :
78
+ result += '\u00B7';
79
+ break;
80
+ default:
81
+ result += String.fromCharCode(charCode);
82
+ }
83
+ }
84
+ return result;
85
+ }
86
+ function getSafeTokenizationSupport(languageIdCodec, languageId) {
87
+ const tokenizationSupport = TokenizationRegistry.get(languageId);
88
+ if (tokenizationSupport) {
89
+ return tokenizationSupport;
90
+ }
91
+ const encodedLanguageId = languageIdCodec.encodeLanguageId(languageId);
92
+ return {
93
+ getInitialState: () => NullState,
94
+ tokenize: (line, hasEOL, state) => nullTokenize(languageId, state),
95
+ tokenizeEncoded: (line, hasEOL, state) => nullTokenizeEncoded(encodedLanguageId, state)
96
+ };
97
+ }
98
+ class InspectTokensWidget extends Disposable {
99
+ static { this._ID = 'editor.contrib.inspectTokensWidget'; }
100
+ constructor(editor, languageService) {
101
+ super();
102
+ this.allowEditorOverflow = true;
103
+ this._editor = editor;
104
+ this._languageService = languageService;
105
+ this._model = this._editor.getModel();
106
+ this._domNode = document.createElement('div');
107
+ this._domNode.className = 'tokens-inspect-widget';
108
+ this._tokenizationSupport = getSafeTokenizationSupport(this._languageService.languageIdCodec, this._model.getLanguageId());
109
+ this._compute(this._editor.getPosition());
110
+ this._register(this._editor.onDidChangeCursorPosition((e) => this._compute(this._editor.getPosition())));
111
+ this._editor.addContentWidget(this);
112
+ }
113
+ dispose() {
114
+ this._editor.removeContentWidget(this);
115
+ super.dispose();
116
+ }
117
+ getId() {
118
+ return InspectTokensWidget._ID;
119
+ }
120
+ _compute(position) {
121
+ const data = this._getTokensAtLine(position.lineNumber);
122
+ let token1Index = 0;
123
+ for (let i = data.tokens1.length - 1; i >= 0; i--) {
124
+ const t = data.tokens1[i];
125
+ if (position.column - 1 >= t.offset) {
126
+ token1Index = i;
127
+ break;
128
+ }
129
+ }
130
+ let token2Index = 0;
131
+ for (let i = (data.tokens2.length >>> 1); i >= 0; i--) {
132
+ if (position.column - 1 >= data.tokens2[(i << 1)]) {
133
+ token2Index = i;
134
+ break;
135
+ }
136
+ }
137
+ const lineContent = this._model.getLineContent(position.lineNumber);
138
+ let tokenText = '';
139
+ if (token1Index < data.tokens1.length) {
140
+ const tokenStartIndex = data.tokens1[token1Index].offset;
141
+ const tokenEndIndex = token1Index + 1 < data.tokens1.length ? data.tokens1[token1Index + 1].offset : lineContent.length;
142
+ tokenText = lineContent.substring(tokenStartIndex, tokenEndIndex);
143
+ }
144
+ reset(this._domNode, $('h2.tm-token', undefined, renderTokenText(tokenText), $('span.tm-token-length', undefined, `${tokenText.length} ${tokenText.length === 1 ? 'char' : 'chars'}`)));
145
+ append(this._domNode, $('hr.tokens-inspect-separator', { 'style': 'clear:both' }));
146
+ const metadata = (token2Index << 1) + 1 < data.tokens2.length ? this._decodeMetadata(data.tokens2[(token2Index << 1) + 1]) : null;
147
+ append(this._domNode, $('table.tm-metadata-table', undefined, $('tbody', undefined, $('tr', undefined, $('td.tm-metadata-key', undefined, 'language'), $('td.tm-metadata-value', undefined, `${metadata ? metadata.languageId : '-?-'}`)), $('tr', undefined, $('td.tm-metadata-key', undefined, 'token type'), $('td.tm-metadata-value', undefined, `${metadata ? this._tokenTypeToString(metadata.tokenType) : '-?-'}`)), $('tr', undefined, $('td.tm-metadata-key', undefined, 'font style'), $('td.tm-metadata-value', undefined, `${metadata ? this._fontStyleToString(metadata.fontStyle) : '-?-'}`)), $('tr', undefined, $('td.tm-metadata-key', undefined, 'foreground'), $('td.tm-metadata-value', undefined, `${metadata ? Color.Format.CSS.formatHex(metadata.foreground) : '-?-'}`)), $('tr', undefined, $('td.tm-metadata-key', undefined, 'background'), $('td.tm-metadata-value', undefined, `${metadata ? Color.Format.CSS.formatHex(metadata.background) : '-?-'}`)))));
148
+ append(this._domNode, $('hr.tokens-inspect-separator'));
149
+ if (token1Index < data.tokens1.length) {
150
+ append(this._domNode, $('span.tm-token-type', undefined, data.tokens1[token1Index].type));
151
+ }
152
+ this._editor.layoutContentWidget(this);
153
+ }
154
+ _decodeMetadata(metadata) {
155
+ const colorMap = TokenizationRegistry.getColorMap();
156
+ const languageId = TokenMetadata.getLanguageId(metadata);
157
+ const tokenType = TokenMetadata.getTokenType(metadata);
158
+ const fontStyle = TokenMetadata.getFontStyle(metadata);
159
+ const foreground = TokenMetadata.getForeground(metadata);
160
+ const background = TokenMetadata.getBackground(metadata);
161
+ return {
162
+ languageId: this._languageService.languageIdCodec.decodeLanguageId(languageId),
163
+ tokenType: tokenType,
164
+ fontStyle: fontStyle,
165
+ foreground: colorMap[foreground],
166
+ background: colorMap[background]
167
+ };
168
+ }
169
+ _tokenTypeToString(tokenType) {
170
+ switch (tokenType) {
171
+ case 0 : return 'Other';
172
+ case 1 : return 'Comment';
173
+ case 2 : return 'String';
174
+ case 3 : return 'RegEx';
175
+ default: return '??';
176
+ }
177
+ }
178
+ _fontStyleToString(fontStyle) {
179
+ let r = '';
180
+ if (fontStyle & 1 ) {
181
+ r += 'italic ';
182
+ }
183
+ if (fontStyle & 2 ) {
184
+ r += 'bold ';
185
+ }
186
+ if (fontStyle & 4 ) {
187
+ r += 'underline ';
188
+ }
189
+ if (fontStyle & 8 ) {
190
+ r += 'strikethrough ';
191
+ }
192
+ if (r.length === 0) {
193
+ r = '---';
194
+ }
195
+ return r;
196
+ }
197
+ _getTokensAtLine(lineNumber) {
198
+ const stateBeforeLine = this._getStateBeforeLine(lineNumber);
199
+ const tokenizationResult1 = this._tokenizationSupport.tokenize(this._model.getLineContent(lineNumber), true, stateBeforeLine);
200
+ const tokenizationResult2 = this._tokenizationSupport.tokenizeEncoded(this._model.getLineContent(lineNumber), true, stateBeforeLine);
201
+ return {
202
+ startState: stateBeforeLine,
203
+ tokens1: tokenizationResult1.tokens,
204
+ tokens2: tokenizationResult2.tokens,
205
+ endState: tokenizationResult1.endState
206
+ };
207
+ }
208
+ _getStateBeforeLine(lineNumber) {
209
+ let state = this._tokenizationSupport.getInitialState();
210
+ for (let i = 1; i < lineNumber; i++) {
211
+ const tokenizationResult = this._tokenizationSupport.tokenize(this._model.getLineContent(i), true, state);
212
+ state = tokenizationResult.endState;
213
+ }
214
+ return state;
215
+ }
216
+ getDomNode() {
217
+ return this._domNode;
218
+ }
219
+ getPosition() {
220
+ return {
221
+ position: this._editor.getPosition(),
222
+ preference: [2 , 1 ]
223
+ };
224
+ }
225
+ }
226
+ registerEditorContribution(InspectTokensController.ID, InspectTokensController, 4 );
227
+ registerEditorAction(InspectTokens);
@@ -0,0 +1,30 @@
1
+ import { EditorAction, registerEditorAction } from 'vscode/vscode/vs/editor/browser/editorExtensions';
2
+ import { IStandaloneThemeService } from 'vscode/vscode/vs/editor/standalone/common/standaloneTheme';
3
+ import { ToggleHighContrastNLS } from 'vscode/vscode/vs/editor/common/standaloneStrings';
4
+ import { isHighContrast, isDark } from 'vscode/vscode/vs/platform/theme/common/theme';
5
+ import { VS_DARK_THEME_NAME, VS_LIGHT_THEME_NAME, HC_BLACK_THEME_NAME, HC_LIGHT_THEME_NAME } from 'vscode/vscode/vs/editor/standalone/browser/standaloneThemeService';
6
+
7
+ class ToggleHighContrast extends EditorAction {
8
+ constructor() {
9
+ super({
10
+ id: 'editor.action.toggleHighContrast',
11
+ label: ToggleHighContrastNLS.toggleHighContrast,
12
+ alias: 'Toggle High Contrast Theme',
13
+ precondition: undefined
14
+ });
15
+ this._originalThemeName = null;
16
+ }
17
+ run(accessor, editor) {
18
+ const standaloneThemeService = accessor.get(IStandaloneThemeService);
19
+ const currentTheme = standaloneThemeService.getColorTheme();
20
+ if (isHighContrast(currentTheme.type)) {
21
+ standaloneThemeService.setTheme(this._originalThemeName || (isDark(currentTheme.type) ? VS_DARK_THEME_NAME : VS_LIGHT_THEME_NAME));
22
+ this._originalThemeName = null;
23
+ }
24
+ else {
25
+ standaloneThemeService.setTheme(isDark(currentTheme.type) ? HC_BLACK_THEME_NAME : HC_LIGHT_THEME_NAME);
26
+ this._originalThemeName = currentTheme.themeName;
27
+ }
28
+ }
29
+ }
30
+ registerEditorAction(ToggleHighContrast);