Skip to content

Commit 02468f9

Browse files
committed
Adding withUndefinedAsNull
1 parent 9598b8d commit 02468f9

6 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/vs/base/common/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,15 @@ export function getAllPropertyNames(obj: object): string[] {
192192
}
193193

194194
/**
195-
* Converts null undefined, passes all other values through.
195+
* Converts null to undefined, passes all other values through.
196196
*/
197197
export function withNullAsUndefined<T>(x: T | null): T | undefined {
198198
return x === null ? undefined : x;
199+
}
200+
201+
/**
202+
* Converts undefined to null, passes all other values through.
203+
*/
204+
export function withUndefinedAsNull<T>(x: T | undefined): T | null {
205+
return typeof x === 'undefined' ? null : x;
199206
}

src/vs/code/electron-main/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
3939
import { ConfigurationService } from 'vs/platform/configuration/node/configurationService';
4040
import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-main/windows';
4141
import { IHistoryMainService } from 'vs/platform/history/common/history';
42-
import { isUndefinedOrNull } from 'vs/base/common/types';
42+
import { isUndefinedOrNull, withUndefinedAsNull } from 'vs/base/common/types';
4343
import { KeyboardLayoutMonitor } from 'vs/code/electron-main/keyboard';
4444
import { URI } from 'vs/base/common/uri';
4545
import { WorkspacesChannel } from 'vs/platform/workspaces/node/workspacesIpc';
@@ -686,7 +686,7 @@ export class CodeApplication extends Disposable {
686686
this.logService.info('Resolving authority', authority);
687687
if (authority.indexOf('+') >= 0) {
688688
if (resolvedAuthorities.has(authority)) {
689-
return resolvedAuthorities.get(authority) || null;
689+
return withUndefinedAsNull(resolvedAuthorities.get(authority));
690690
}
691691
this.logService.info('Didnot find resolved authority for', authority);
692692
return null;

src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v
1414
import { ViewContext } from 'vs/editor/common/view/viewContext';
1515
import * as viewEvents from 'vs/editor/common/view/viewEvents';
1616
import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData';
17+
import { withUndefinedAsNull } from 'vs/base/common/types';
1718

1819
class Coordinate {
1920
_coordinateBrand: void;
@@ -242,8 +243,8 @@ class Widget {
242243
}
243244

244245
private _setPosition(position: IPosition | null | undefined, range: IRange | null | undefined): void {
245-
this._position = position || null;
246-
this._range = range || null;
246+
this._position = withUndefinedAsNull(position);
247+
this._range = withUndefinedAsNull(range);
247248
this._viewPosition = null;
248249
this._viewRange = null;
249250

src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4646
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
4747
import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor';
4848
import { onDidChangeZoomLevel } from 'vs/base/browser/browser';
49-
import { withNullAsUndefined } from 'vs/base/common/types';
49+
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
5050

5151
class Item extends BreadcrumbsItem {
5252

@@ -459,7 +459,7 @@ export class BreadcrumbsControl {
459459
selection: Range.collapseToStart(element.symbol.selectionRange),
460460
revealInCenterIfOutsideViewport: true
461461
}
462-
}, this._getActiveCodeEditor() || null, group === SIDE_GROUP);
462+
}, withUndefinedAsNull(this._getActiveCodeEditor()), group === SIDE_GROUP);
463463
}
464464
}
465465
}

src/vs/workbench/browser/parts/editor/editorControl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { IProgressService, LongRunningOperation } from 'vs/platform/progress/com
1515
import { IEditorGroupView, DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs/workbench/browser/parts/editor/editor';
1616
import { Event, Emitter } from 'vs/base/common/event';
1717
import { IVisibleEditor } from 'vs/workbench/services/editor/common/editorService';
18+
import { withUndefinedAsNull } from 'vs/base/common/types';
1819

1920
export interface IOpenEditorResult {
2021
readonly control: BaseEditor;
@@ -67,7 +68,7 @@ export class EditorControl extends Disposable {
6768
const control = this.doShowEditorControl(descriptor);
6869

6970
// Set input
70-
return this.doSetInput(control, editor, options || null).then((editorChanged => (({ control, editorChanged } as IOpenEditorResult))));
71+
return this.doSetInput(control, editor, withUndefinedAsNull(options)).then((editorChanged => (({ control, editorChanged } as IOpenEditorResult))));
7172
}
7273

7374
private doShowEditorControl(descriptor: IEditorDescriptor): BaseEditor {

src/vs/workbench/browser/parts/editor/titleControl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { Themable } from 'vs/workbench/common/theme';
3939
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
4040
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
4141
import { IFileService } from 'vs/platform/files/common/files';
42+
import { withUndefinedAsNull } from 'vs/base/common/types';
4243

4344
export interface IToolbarActions {
4445
primary: IAction[];
@@ -165,7 +166,7 @@ export abstract class TitleControl extends Themable {
165166

166167
// Check extensions
167168
if (!actionItem) {
168-
actionItem = createActionItem(action, this.keybindingService, this.notificationService, this.contextMenuService) || null;
169+
actionItem = withUndefinedAsNull(createActionItem(action, this.keybindingService, this.notificationService, this.contextMenuService));
169170
}
170171

171172
return actionItem;

0 commit comments

Comments
 (0)