Skip to content

Commit 76be820

Browse files
committed
Revert "Converting a few functions in ITokenizationRegistry to return undefined instead of null"
This reverts commit 4a461d2. Revert "null -> undefined" This reverts commit 30dc021
1 parent 5727722 commit 76be820

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class Settings {
6161
const minimapOpts = options.get(EditorOption.minimap);
6262
const minimapEnabled = minimapOpts.enabled;
6363
const minimapSide = minimapOpts.side;
64-
const backgroundColor = (minimapEnabled ? TokenizationRegistry.getDefaultBackground() : undefined);
65-
if (typeof backgroundColor === 'undefined' || minimapSide === 'left') {
64+
const backgroundColor = (minimapEnabled ? TokenizationRegistry.getDefaultBackground() : null);
65+
if (backgroundColor === null || minimapSide === 'left') {
6666
this.backgroundColor = null;
6767
} else {
6868
this.backgroundColor = Color.Format.CSS.formatHex(backgroundColor);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ export class TextModelTokenization extends Disposable {
198198
private readonly _textModel: TextModel;
199199
private readonly _tokenizationStateStore: TokenizationStateStore;
200200
private _isDisposed: boolean;
201-
private _tokenizationSupport: ITokenizationSupport | undefined;
201+
private _tokenizationSupport: ITokenizationSupport | null;
202202

203203
constructor(textModel: TextModel) {
204204
super();
205205
this._isDisposed = false;
206206
this._textModel = textModel;
207207
this._tokenizationStateStore = new TokenizationStateStore();
208+
this._tokenizationSupport = null;
208209

209210
this._register(TokenizationRegistry.onDidChange((e) => {
210211
const languageIdentifier = this._textModel.getLanguageIdentifier();
@@ -423,11 +424,11 @@ export class TextModelTokenization extends Disposable {
423424
}
424425
}
425426

426-
function initializeTokenization(textModel: TextModel): [ITokenizationSupport | undefined, IState | null] {
427+
function initializeTokenization(textModel: TextModel): [ITokenizationSupport | null, IState | null] {
427428
const languageIdentifier = textModel.getLanguageIdentifier();
428429
let tokenizationSupport = (
429430
textModel.isTooLargeForTokenization()
430-
? undefined
431+
? null
431432
: TokenizationRegistry.get(languageIdentifier.language)
432433
);
433434
let initialState: IState | null = null;
@@ -436,7 +437,7 @@ function initializeTokenization(textModel: TextModel): [ITokenizationSupport | u
436437
initialState = tokenizationSupport.getInitialState();
437438
} catch (e) {
438439
onUnexpectedError(e);
439-
tokenizationSupport = undefined;
440+
tokenizationSupport = null;
440441
}
441442
}
442443
return [tokenizationSupport, initialState];

src/vs/editor/common/modes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,9 +1617,9 @@ export interface ITokenizationRegistry {
16171617

16181618
/**
16191619
* Get the tokenization support for a language.
1620-
* Returns `undefined` if not found.
1620+
* Returns `null` if not found.
16211621
*/
1622-
get(language: string): ITokenizationSupport | undefined;
1622+
get(language: string): ITokenizationSupport | null;
16231623

16241624
/**
16251625
* Get the promise of a tokenization support for a language.
@@ -1632,9 +1632,9 @@ export interface ITokenizationRegistry {
16321632
*/
16331633
setColorMap(colorMap: Color[]): void;
16341634

1635-
getColorMap(): Color[] | undefined;
1635+
getColorMap(): Color[] | null;
16361636

1637-
getDefaultBackground(): Color | undefined;
1637+
getDefaultBackground(): Color | null;
16381638
}
16391639

16401640
/**

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Color } from 'vs/base/common/color';
77
import { Emitter, Event } from 'vs/base/common/event';
88
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
99
import { ColorId, ITokenizationRegistry, ITokenizationSupport, ITokenizationSupportChangedEvent } from 'vs/editor/common/modes';
10+
import { withUndefinedAsNull } from 'vs/base/common/types';
1011
import { keys } from 'vs/base/common/map';
1112

1213
export class TokenizationRegistryImpl implements ITokenizationRegistry {
@@ -17,7 +18,11 @@ export class TokenizationRegistryImpl implements ITokenizationRegistry {
1718
private readonly _onDidChange = new Emitter<ITokenizationSupportChangedEvent>();
1819
public readonly onDidChange: Event<ITokenizationSupportChangedEvent> = this._onDidChange.event;
1920

20-
private _colorMap: Color[] | undefined;
21+
private _colorMap: Color[] | null;
22+
23+
constructor() {
24+
this._colorMap = null;
25+
}
2126

2227
public fire(languages: string[]): void {
2328
this._onDidChange.fire({
@@ -71,8 +76,8 @@ export class TokenizationRegistryImpl implements ITokenizationRegistry {
7176
return null;
7277
}
7378

74-
public get(language: string): ITokenizationSupport | undefined {
75-
return this._map.get(language);
79+
public get(language: string): ITokenizationSupport | null {
80+
return withUndefinedAsNull(this._map.get(language));
7681
}
7782

7883
public setColorMap(colorMap: Color[]): void {
@@ -83,14 +88,14 @@ export class TokenizationRegistryImpl implements ITokenizationRegistry {
8388
});
8489
}
8590

86-
public getColorMap(): Color[] | undefined {
91+
public getColorMap(): Color[] | null {
8792
return this._colorMap;
8893
}
8994

90-
public getDefaultBackground(): Color | undefined {
95+
public getDefaultBackground(): Color | null {
9196
if (this._colorMap && this._colorMap.length > ColorId.DefaultBackground) {
9297
return this._colorMap[ColorId.DefaultBackground];
9398
}
94-
return undefined;
99+
return null;
95100
}
96101
}

0 commit comments

Comments
 (0)