Skip to content

Commit 616957b

Browse files
committed
Remove ModeTransition
1 parent 8998f7a commit 616957b

13 files changed

Lines changed: 290 additions & 453 deletions

File tree

build/monaco/monaco.d.ts.recipe

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ declare module monaco {
4848
#include(vs/editor/common/core/position): Position
4949
#include(vs/editor/common/core/range): Range
5050
#include(vs/editor/common/core/selection): Selection, SelectionDirection
51+
#include(vs/editor/common/core/token): Token
5152
}
5253

5354
declare module monaco.editor {
5455

55-
#includeAll(vs/editor/browser/standalone/standaloneEditor;modes.=>languages.):
56+
#includeAll(vs/editor/browser/standalone/standaloneEditor;modes.=>languages.;editorCommon.=>):
5657
#include(vs/editor/common/services/webWorker): MonacoWebWorker, IWebWorkerOptions
5758
#include(vs/editor/browser/standalone/standaloneCodeEditor): IEditorConstructionOptions, IDiffEditorConstructionOptions, IStandaloneCodeEditor, IStandaloneDiffEditor
5859
export interface ICommandHandler {

src/vs/editor/browser/standalone/standaloneEditor.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
import 'vs/css!./media/standalone-tokens';
88
import * as editorCommon from 'vs/editor/common/editorCommon';
9-
/* tslint:disable:duplicate-imports */
10-
import { IModel } from 'vs/editor/common/editorCommon';
11-
/* tslint:disable:duplicate-imports */
129
import { ContentWidgetPositionPreference, OverlayWidgetPositionPreference } from 'vs/editor/browser/editorBrowser';
1310
import { StandaloneEditor, IStandaloneCodeEditor, StandaloneDiffEditor, IStandaloneDiffEditor, IEditorConstructionOptions, IDiffEditorConstructionOptions } from 'vs/editor/browser/standalone/standaloneCodeEditor';
1411
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
@@ -33,9 +30,9 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3330
import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService';
3431
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
3532
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
36-
import { IState, ITokenizationSupport, TokenizationRegistry } from 'vs/editor/common/modes';
3733
import { NULL_STATE, nullTokenize } from 'vs/editor/common/modes/nullMode';
3834
import { IStandaloneColorService } from 'vs/editor/common/services/standaloneColorService';
35+
import { Token } from 'vs/editor/common/core/token';
3936

4037
/**
4138
* @internal
@@ -136,15 +133,15 @@ export function createDiffNavigator(diffEditor: IStandaloneDiffEditor, opts?: ID
136133
return new DiffNavigator(diffEditor, opts);
137134
}
138135

139-
function doCreateModel(value: string, mode: TPromise<modes.IMode>, uri?: URI): IModel {
136+
function doCreateModel(value: string, mode: TPromise<modes.IMode>, uri?: URI): editorCommon.IModel {
140137
return StaticServices.modelService.get().createModel(value, mode, uri);
141138
}
142139

143140
/**
144141
* Create a new editor model.
145142
* You can specify the language that should be set for this model or let the language be inferred from the `uri`.
146143
*/
147-
export function createModel(value: string, language?: string, uri?: URI): IModel {
144+
export function createModel(value: string, language?: string, uri?: URI): editorCommon.IModel {
148145
value = value || '';
149146

150147
if (!language) {
@@ -164,14 +161,14 @@ export function createModel(value: string, language?: string, uri?: URI): IModel
164161
/**
165162
* Change the language for a model.
166163
*/
167-
export function setModelLanguage(model: IModel, language: string): void {
164+
export function setModelLanguage(model: editorCommon.IModel, language: string): void {
168165
StaticServices.modelService.get().setMode(model, StaticServices.modeService.get().getOrCreateMode(language));
169166
}
170167

171168
/**
172169
* Set the markers for a model.
173170
*/
174-
export function setModelMarkers(model: IModel, owner: string, markers: IMarkerData[]): void {
171+
export function setModelMarkers(model: editorCommon.IModel, owner: string, markers: IMarkerData[]): void {
175172
if (model) {
176173
StaticServices.markerService.get().changeOne(owner, model.uri, markers);
177174
}
@@ -180,38 +177,38 @@ export function setModelMarkers(model: IModel, owner: string, markers: IMarkerDa
180177
/**
181178
* Get the model that has `uri` if it exists.
182179
*/
183-
export function getModel(uri: URI): IModel {
180+
export function getModel(uri: URI): editorCommon.IModel {
184181
return StaticServices.modelService.get().getModel(uri);
185182
}
186183

187184
/**
188185
* Get all the created models.
189186
*/
190-
export function getModels(): IModel[] {
187+
export function getModels(): editorCommon.IModel[] {
191188
return StaticServices.modelService.get().getModels();
192189
}
193190

194191
/**
195192
* Emitted when a model is created.
196193
* @event
197194
*/
198-
export function onDidCreateModel(listener: (model: IModel) => void): IDisposable {
195+
export function onDidCreateModel(listener: (model: editorCommon.IModel) => void): IDisposable {
199196
return StaticServices.modelService.get().onModelAdded(listener);
200197
}
201198

202199
/**
203200
* Emitted right before a model is disposed.
204201
* @event
205202
*/
206-
export function onWillDisposeModel(listener: (model: IModel) => void): IDisposable {
203+
export function onWillDisposeModel(listener: (model: editorCommon.IModel) => void): IDisposable {
207204
return StaticServices.modelService.get().onModelRemoved(listener);
208205
}
209206

210207
/**
211208
* Emitted when a different language is set to a model.
212209
* @event
213210
*/
214-
export function onDidChangeModelLanguage(listener: (e: { readonly model: IModel; readonly oldLanguage: string; }) => void): IDisposable {
211+
export function onDidChangeModelLanguage(listener: (e: { readonly model: editorCommon.IModel; readonly oldLanguage: string; }) => void): IDisposable {
215212
return StaticServices.modelService.get().onModelModeChanged((e) => {
216213
listener({
217214
model: e.model,
@@ -255,31 +252,21 @@ export function colorize(text: string, languageId: string, options: IColorizerOp
255252
/**
256253
* Colorize a line in a model.
257254
*/
258-
export function colorizeModelLine(model: IModel, lineNumber: number, tabSize: number = 4): string {
255+
export function colorizeModelLine(model: editorCommon.IModel, lineNumber: number, tabSize: number = 4): string {
259256
return Colorizer.colorizeModelLine(model, lineNumber, tabSize);
260257
}
261258

262-
export class Token {
263-
public readonly offset: number;
264-
public readonly type: string;
265-
266-
constructor(offset: number, type: string) {
267-
this.offset = offset;
268-
this.type = type;
269-
}
270-
}
271-
272259
/**
273260
* @internal
274261
*/
275-
function getSafeTokenizationSupport(languageId: string): ITokenizationSupport {
276-
let tokenizationSupport = TokenizationRegistry.get(languageId);
262+
function getSafeTokenizationSupport(languageId: string): modes.ITokenizationSupport {
263+
let tokenizationSupport = modes.TokenizationRegistry.get(languageId);
277264
if (tokenizationSupport) {
278265
return tokenizationSupport;
279266
}
280267
return {
281268
getInitialState: () => NULL_STATE,
282-
tokenize: (line: string, state: IState, deltaOffset: number) => nullTokenize(languageId, line, state, deltaOffset),
269+
tokenize: (line: string, state: modes.IState, deltaOffset: number) => nullTokenize(languageId, line, state, deltaOffset),
283270
tokenize3: undefined,
284271
};
285272
}
@@ -300,7 +287,7 @@ export function tokenize(text: string, languageId: string): Token[][] {
300287
let line = lines[i];
301288
let tokenizationResult = tokenizationSupport.tokenize(line, state, 0);
302289

303-
result[i] = tokenizationResult.tokens.map((t) => new Token(t.startIndex, t.type));
290+
result[i] = tokenizationResult.tokens;
304291
state = tokenizationResult.endState;
305292
}
306293
return result;
@@ -358,7 +345,6 @@ export function createMonacoEditorAPI(): typeof monaco.editor {
358345
BareFontInfo: <any>editorCommon.BareFontInfo,
359346
FontInfo: <any>editorCommon.FontInfo,
360347
TextModelResolvedOptions: <any>editorCommon.TextModelResolvedOptions,
361-
Token: Token,
362348

363349
// vars
364350
EditorType: editorCommon.EditorType,

src/vs/editor/browser/standalone/standaloneLanguages.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { createTokenizationSupport } from 'vs/editor/common/modes/monarch/monarc
2424
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
2525
import { IMarkerData } from 'vs/platform/markers/common/markers';
2626
import { Token } from 'vs/editor/common/core/token';
27-
import { ModeTransition } from 'vs/editor/common/core/modeTransition';
2827
import { IStandaloneColorService } from 'vs/editor/common/services/standaloneColorService';
2928

3029
/**
@@ -90,18 +89,18 @@ export class TokenizationSupport2Adapter implements modes.ITokenizationSupport {
9089
return this._actual.getInitialState();
9190
}
9291

93-
private _toClassicTokens(tokens: modes.IToken2[], offsetDelta: number): Token[] {
92+
private _toClassicTokens(tokens: modes.IToken2[], language: string, offsetDelta: number): Token[] {
9493
let result: Token[] = [];
9594
for (let i = 0, len = tokens.length; i < len; i++) {
9695
let t = tokens[i];
97-
result[i] = new Token(t.startIndex + offsetDelta, t.scopes);
96+
result[i] = new Token(t.startIndex + offsetDelta, t.scopes, language);
9897
}
9998
return result;
10099
}
101100

102101
public tokenize(line: string, state: modes.IState, offsetDelta: number): modes.ILineTokens {
103102
let actualResult = this._actual.tokenize(line, state);
104-
let tokens = this._toClassicTokens(actualResult.tokens, offsetDelta);
103+
let tokens = this._toClassicTokens(actualResult.tokens, this._languageIdentifier.sid, offsetDelta);
105104

106105
let endState: modes.IState;
107106
// try to save an object if possible
@@ -113,8 +112,7 @@ export class TokenizationSupport2Adapter implements modes.ITokenizationSupport {
113112

114113
return {
115114
tokens: tokens,
116-
endState: endState,
117-
modeTransitions: [new ModeTransition(offsetDelta, this._languageIdentifier.sid)],
115+
endState: endState
118116
};
119117
}
120118

src/vs/editor/common/core/modeTransition.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/vs/editor/common/core/token.ts

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,20 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7-
import { Arrays } from 'vs/editor/common/core/arrays';
8-
97
export class Token {
108
_tokenBrand: void;
119

12-
public readonly startIndex: number;
10+
public readonly offset: number;
1311
public readonly type: string;
12+
public readonly language: string;
1413

15-
constructor(startIndex: number, type: string) {
16-
this.startIndex = startIndex | 0;// @perf
14+
constructor(offset: number, type: string, language: string) {
15+
this.offset = offset | 0;// @perf
1716
this.type = type;
17+
this.language = language;
1818
}
1919

2020
public toString(): string {
21-
return '(' + this.startIndex + ', ' + this.type + ')';
22-
}
23-
24-
public equals(other: Token): boolean {
25-
return (
26-
this.startIndex === other.startIndex
27-
&& this.type === other.type
28-
);
29-
}
30-
31-
public static findIndexInSegmentsArray(arr: Token[], desiredIndex: number): number {
32-
return Arrays.findIndexInSegmentsArray(arr, desiredIndex);
33-
}
34-
35-
public static equalsArray(a: Token[], b: Token[]): boolean {
36-
let aLen = a.length;
37-
let bLen = b.length;
38-
if (aLen !== bLen) {
39-
return false;
40-
}
41-
for (let i = 0; i < aLen; i++) {
42-
if (!a[i].equals(b[i])) {
43-
return false;
44-
}
45-
}
46-
return true;
21+
return '(' + this.offset + ', ' + this.type + ')';
4722
}
4823
}

src/vs/editor/common/modes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { IDisposable } from 'vs/base/common/lifecycle';
99
import URI from 'vs/base/common/uri';
1010
import { IFilter } from 'vs/base/common/filters';
1111
import * as editorCommon from 'vs/editor/common/editorCommon';
12-
import { ModeTransition } from 'vs/editor/common/core/modeTransition';
1312
import { Token } from 'vs/editor/common/core/token';
1413
import LanguageFeatureRegistry from 'vs/editor/common/modes/languageFeatureRegistry';
1514
import { CancellationToken } from 'vs/base/common/cancellation';
@@ -55,7 +54,6 @@ export interface IMode {
5554
export interface ILineTokens {
5655
tokens: Token[];
5756
endState: IState;
58-
modeTransitions: ModeTransition[];
5957
}
6058

6159
/**

src/vs/editor/common/modes/monarch/monarchLexer.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import * as monarchCommon from 'vs/editor/common/modes/monarch/monarchCommon';
1515
import { IModeService } from 'vs/editor/common/services/modeService';
1616
import { Token } from 'vs/editor/common/core/token';
1717
import { NULL_STATE, NULL_MODE_ID } from 'vs/editor/common/modes/nullMode';
18-
import { ModeTransition } from 'vs/editor/common/core/modeTransition';
1918
import { IStandaloneColorService } from 'vs/editor/common/services/standaloneColorService';
2019
import { Theme } from 'vs/editor/common/modes/supports/tokenization';
2120

@@ -240,35 +239,29 @@ interface IMonarchTokensCollector {
240239

241240
class MonarchClassicTokensCollector implements IMonarchTokensCollector {
242241

243-
private _modeTransitions: ModeTransition[];
244242
private _tokens: Token[];
245-
246-
private _lastModeId: string;
243+
private _language: string;
247244
private _lastTokenType: string;
245+
private _lastTokenLanguage: string;
248246

249247
constructor() {
250-
this._modeTransitions = [];
251248
this._tokens = [];
252-
253-
this._lastModeId = null;
249+
this._language = null;
254250
this._lastTokenType = null;
251+
this._lastTokenLanguage = null;
255252
}
256253

257254
public enterMode(startOffset: number, modeId: string): void {
258-
if (this._lastModeId === modeId) {
259-
// Avoid transitioning to the same mode (this can happen in case of empty embedded modes)
260-
return;
261-
}
262-
this._lastModeId = modeId;
263-
this._modeTransitions.push(new ModeTransition(startOffset, modeId));
255+
this._language = modeId;
264256
}
265257

266258
public emit(startOffset: number, type: string): void {
267-
if (this._lastTokenType === type) {
259+
if (this._lastTokenType === type && this._lastTokenLanguage === this._language) {
268260
return;
269261
}
270262
this._lastTokenType = type;
271-
this._tokens.push(new Token(startOffset, type));
263+
this._lastTokenLanguage = this._language;
264+
this._tokens.push(new Token(startOffset, type, this._language));
272265
}
273266

274267
public nestedModeTokenize(embeddedModeLine: string, embeddedModeData: EmbeddedModeData, offsetDelta: number): modes.IState {
@@ -285,15 +278,14 @@ class MonarchClassicTokensCollector implements IMonarchTokensCollector {
285278
let nestedResult = nestedModeTokenizationSupport.tokenize(embeddedModeLine, embeddedModeState, offsetDelta);
286279
this._tokens = this._tokens.concat(nestedResult.tokens);
287280
this._lastTokenType = null;
288-
this._modeTransitions = this._modeTransitions.concat(nestedResult.modeTransitions);
289-
this._lastModeId = null;
281+
this._lastTokenLanguage = null;
282+
this._language = null;
290283
return nestedResult.endState;
291284
}
292285

293286
public finalize(endState: MonarchLineState): modes.ILineTokens {
294287
return {
295288
tokens: this._tokens,
296-
modeTransitions: this._modeTransitions,
297289
endState: endState
298290
};
299291
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
'use strict';
66

77
import { IState, ILineTokens, ILineTokens3, ColorId, MetadataConsts, LanguageIdentifier, FontStyle, StandardTokenType, LanguageId } from 'vs/editor/common/modes';
8-
import { ModeTransition } from 'vs/editor/common/core/modeTransition';
98
import { Token } from 'vs/editor/common/core/token';
109

1110
class NullStateImpl implements IState {
@@ -26,14 +25,9 @@ export const NULL_MODE_ID = 'vs.editor.nullMode';
2625
export const NULL_LANGUAGE_IDENTIFIER = new LanguageIdentifier(NULL_MODE_ID, LanguageId.Null);
2726

2827
export function nullTokenize(modeId: string, buffer: string, state: IState, deltaOffset: number): ILineTokens {
29-
let tokens: Token[] = [new Token(deltaOffset, '')];
30-
31-
let modeTransitions: ModeTransition[] = [new ModeTransition(deltaOffset, modeId)];
32-
3328
return {
34-
tokens: tokens,
35-
endState: state,
36-
modeTransitions: modeTransitions
29+
tokens: [new Token(deltaOffset, '', modeId)],
30+
endState: state
3731
};
3832
}
3933

0 commit comments

Comments
 (0)