Skip to content

Commit ed5613d

Browse files
committed
Add token inspector for standalone editor
1 parent 38912c0 commit ed5613d

7 files changed

Lines changed: 382 additions & 6 deletions

File tree

src/vs/editor/common/model/textModelWithTokens.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
1313
import { TextModel } from 'vs/editor/common/model/textModel';
1414
import { TokenIterator } from 'vs/editor/common/model/tokenIterator';
1515
import { ITokenizationSupport, IState, TokenizationRegistry, LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
16-
import { NULL_LANGUAGE_IDENTIFIER, nullTokenize3 } from 'vs/editor/common/modes/nullMode';
16+
import { NULL_LANGUAGE_IDENTIFIER, nullTokenize2 } from 'vs/editor/common/modes/nullMode';
1717
import { ignoreBracketsInToken } from 'vs/editor/common/modes/supports';
1818
import { BracketsUtils, RichEditBrackets, RichEditBracket } from 'vs/editor/common/modes/supports/richEditBrackets';
1919
import { Position } from 'vs/editor/common/core/position';
@@ -352,7 +352,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
352352
}
353353

354354
if (!r) {
355-
r = nullTokenize3(this._languageIdentifier.id, text, this._lines[lineIndex].getState(), 0);
355+
r = nullTokenize2(this._languageIdentifier.id, text, this._lines[lineIndex].getState(), 0);
356356
}
357357
this._lines[lineIndex].setTokens(this._languageIdentifier.id, r.tokens);
358358
eventBuilder.registerChangedTokens(lineIndex + 1);

src/vs/editor/common/modes/nullMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function nullTokenize(modeId: string, buffer: string, state: IState, delt
2828
return new TokenizationResult([new Token(deltaOffset, '', modeId)], state);
2929
}
3030

31-
export function nullTokenize3(languageId: LanguageId, buffer: string, state: IState, deltaOffset: number): TokenizationResult2 {
31+
export function nullTokenize2(languageId: LanguageId, buffer: string, state: IState, deltaOffset: number): TokenizationResult2 {
3232
let tokens = new Uint32Array(2);
3333
tokens[0] = deltaOffset;
3434
tokens[1] = (

src/vs/editor/common/modes/textToHtmlTokenizer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import * as strings from 'vs/base/common/strings';
88
import { IState, ITokenizationSupport, TokenizationRegistry, LanguageId } from 'vs/editor/common/modes';
9-
import { NULL_STATE, nullTokenize3 } from 'vs/editor/common/modes/nullMode';
9+
import { NULL_STATE, nullTokenize2 } from 'vs/editor/common/modes/nullMode';
1010
import { LineTokens } from 'vs/editor/common/core/lineTokens';
1111

1212
export function tokenizeToString(text: string, languageId: string): string {
@@ -21,7 +21,7 @@ function _getSafeTokenizationSupport(languageId: string): ITokenizationSupport {
2121
return {
2222
getInitialState: () => NULL_STATE,
2323
tokenize: undefined,
24-
tokenize2: (buffer: string, state: IState, deltaOffset: number) => nullTokenize3(LanguageId.Null, buffer, state, deltaOffset)
24+
tokenize2: (buffer: string, state: IState, deltaOffset: number) => nullTokenize2(LanguageId.Null, buffer, state, deltaOffset)
2525
};
2626
}
2727

src/vs/editor/contrib/inspectTMScopes/electron-browser/inspectTMScopes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
187187
public dispose(): void {
188188
this._isDisposed = true;
189189
this._editor.removeContentWidget(this);
190+
super.dispose();
190191
}
191192

192193
public getId(): string {
@@ -197,7 +198,6 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
197198
dom.clearNode(this._domNode);
198199
this._domNode.appendChild(document.createTextNode(nls.localize('inspectTMScopesWidget.loading', "Loading...")));
199200
this._grammar.then((grammar) => this._compute(grammar, position));
200-
this._editor.layoutContentWidget(this);
201201
}
202202

203203
private _compute(grammar: IGrammar, position: Position): void {
@@ -262,6 +262,7 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
262262

263263

264264
this._domNode.innerHTML = result;
265+
this._editor.layoutContentWidget(this);
265266
}
266267

267268
private _decodeMetadata(metadata: number): IDecodedMetadata {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*---------------------------------------------------------------------------------------------
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+
.monaco-editor .tokens-inspect-widget {
7+
background-color: #F3F3F3;
8+
border: 1px solid #CCC;
9+
z-index: 50;
10+
-webkit-user-select: text;
11+
-ms-user-select: text;
12+
-khtml-user-select: text;
13+
-moz-user-select: text;
14+
-o-user-select: text;
15+
user-select: text;
16+
padding: 10px;
17+
}
18+
19+
.monaco-editor.vs-dark .tokens-inspect-widget { background-color: #2D2D30; border-color: #555; }
20+
21+
.monaco-editor.hc-black .tokens-inspect-widget { background-color: #0C141F; }
22+
23+
.monaco-editor .tokens-inspect-widget .tm-token {
24+
font-family: monospace;
25+
}
26+
27+
.monaco-editor .tokens-inspect-widget .tm-token-length {
28+
font-weight: normal;
29+
font-size: 60%;
30+
float: right;
31+
}
32+
33+
.monaco-editor .tokens-inspect-widget .tm-metadata-table {
34+
width: 100%;
35+
}
36+
37+
.monaco-editor .tokens-inspect-widget .tm-metadata-value {
38+
font-family: monospace;
39+
text-align: right;
40+
}
41+
42+
.monaco-editor .tokens-inspect-widget .tm-token-type {
43+
font-family: monospace;
44+
}

0 commit comments

Comments
 (0)