Skip to content

Commit 37167ef

Browse files
committed
Use nullToUndefined more widely
1 parent 794735f commit 37167ef

28 files changed

Lines changed: 63 additions & 44 deletions

File tree

src/vs/base/browser/ui/toolbar/toolbar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IContextMenuProvider, DropdownMenuActionItem } from 'vs/base/browser/ui
1111
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
1212
import { Disposable } from 'vs/base/common/lifecycle';
1313
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
14+
import { withNullAsUndefined } from 'vs/base/common/types';
1415

1516
export const CONTEXT = 'context.toolbar';
1617

@@ -135,7 +136,7 @@ export class ToolBar extends Disposable {
135136
private getKeybindingLabel(action: IAction): string | undefined {
136137
const key = this.lookupKeybindings && this.options.getKeyBinding ? this.options.getKeyBinding(action) : undefined;
137138

138-
return (key && key.getLabel()) || undefined;
139+
return withNullAsUndefined(key && key.getLabel());
139140
}
140141

141142
addPrimaryAction(primaryAction: IAction): () => void {

src/vs/base/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,6 @@ export function getAllPropertyNames(obj: object): string[] {
194194
/**
195195
* Converts null undefined, passes all other values through.
196196
*/
197-
export function nullToUndefined<T>(x: T | null): T | undefined {
197+
export function withNullAsUndefined<T>(x: T | null): T | undefined {
198198
return x === null ? undefined : x;
199199
}

src/vs/base/parts/quickopen/browser/quickOpenModel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,13 @@ class Renderer implements IRenderer<QuickOpenEntry> {
471471
// Label
472472
const options: IIconLabelValueOptions = entry.getLabelOptions() || Object.create(null);
473473
options.matches = labelHighlights || [];
474-
options.title = entry.getTooltip() || undefined;
475-
options.descriptionTitle = entry.getDescriptionTooltip() || entry.getDescription() || undefined; // tooltip over description because it could overflow
474+
options.title = types.withNullAsUndefined(entry.getTooltip());
475+
options.descriptionTitle = entry.getDescriptionTooltip() || types.withNullAsUndefined(entry.getDescription()); // tooltip over description because it could overflow
476476
options.descriptionMatches = descriptionHighlights || [];
477-
data.label.setLabel(entry.getLabel() || undefined, entry.getDescription() || undefined, options);
477+
data.label.setLabel(types.withNullAsUndefined(entry.getLabel()), types.withNullAsUndefined(entry.getDescription()), options);
478478

479479
// Meta
480-
data.detail.set(entry.getDetail() || undefined, detailHighlights);
480+
data.detail.set(types.withNullAsUndefined(entry.getDetail()), detailHighlights);
481481

482482
// Keybinding
483483
data.keybinding.set(entry.getKeybinding()!);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as perf from 'vs/base/common/performance';
2525
import { resolveMarketplaceHeaders } from 'vs/platform/extensionManagement/node/extensionGalleryService';
2626
import { getBackgroundColor } from 'vs/code/electron-main/theme';
2727
import { RunOnceScheduler } from 'vs/base/common/async';
28+
import { withNullAsUndefined } from 'vs/base/common/types';
2829

2930
export interface IWindowCreationOptions {
3031
state: IWindowState;
@@ -699,7 +700,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
699700
private restoreWindowState(state?: IWindowState): IWindowState {
700701
if (state) {
701702
try {
702-
state = this.validateWindowState(state) || undefined;
703+
state = withNullAsUndefined(this.validateWindowState(state));
703704
} catch (err) {
704705
this.logService.warn(`Unexpected error validating window state: ${err}\n${err.stack}`); // somehow display API can be picky about the state to validate
705706
}

src/vs/editor/contrib/contextmenu/contextmenu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export class ContextMenuController implements IEditorContribution {
190190
},
191191

192192
getKeyBinding: (action): ResolvedKeybinding | undefined => {
193-
return this._keybindingFor(action) || undefined;
193+
return this._keybindingFor(action);
194194
},
195195

196196
onHide: (wasCancelled: boolean) => {

src/vs/editor/contrib/goToDefinition/goToDefinitionMouse.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { DefinitionAction, DefinitionActionConfig } from './goToDefinitionComman
2525
import { ClickLinkGesture, ClickLinkMouseEvent, ClickLinkKeyboardEvent } from 'vs/editor/contrib/goToDefinition/clickLinkGesture';
2626
import { IWordAtPosition, IModelDeltaDecoration, ITextModel, IFoundBracket } from 'vs/editor/common/model';
2727
import { Position } from 'vs/editor/common/core/position';
28+
import { withNullAsUndefined } from 'vs/base/common/types';
2829

2930
class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorContribution {
3031

@@ -51,7 +52,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
5152
this.toUnhook.push(linkGesture);
5253

5354
this.toUnhook.push(linkGesture.onMouseMoveOrRelevantKeyDown(([mouseEvent, keyboardEvent]) => {
54-
this.startFindDefinition(mouseEvent, keyboardEvent || undefined);
55+
this.startFindDefinition(mouseEvent, withNullAsUndefined(keyboardEvent));
5556
}));
5657

5758
this.toUnhook.push(linkGesture.onExecute((mouseEvent: ClickLinkMouseEvent) => {

src/vs/editor/contrib/hover/modesContentHover.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { applyCodeAction, QuickFixAction } from 'vs/editor/contrib/codeAction/co
4040
import { Action } from 'vs/base/common/actions';
4141
import { CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger';
4242
import { IModeService } from 'vs/editor/common/services/modeService';
43+
import { withNullAsUndefined } from 'vs/base/common/types';
4344

4445
const $ = dom.$;
4546

@@ -190,7 +191,7 @@ class ModesContentComputer implements IHoverComputer<HoverPart[]> {
190191

191192
private _getLoadingMessage(): HoverPart {
192193
return {
193-
range: this._range || undefined,
194+
range: withNullAsUndefined(this._range),
194195
contents: [new MarkdownString().appendText(nls.localize('modesContentHover.loading', "Loading..."))]
195196
};
196197
}

src/vs/platform/keybinding/common/abstractKeybindingService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
1717
import { INotificationService } from 'vs/platform/notification/common/notification';
1818
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
1919
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
20+
import { withNullAsUndefined } from 'vs/base/common/types';
2021

2122
interface CurrentChord {
2223
keypress: string;
@@ -99,7 +100,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
99100
if (!result) {
100101
return undefined;
101102
}
102-
return result.resolvedKeybinding || undefined;
103+
return withNullAsUndefined(result.resolvedKeybinding);
103104
}
104105

105106
public dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean {

src/vs/platform/markers/common/markerService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class MarkerService implements IMarkerService {
201201
return {
202202
resource,
203203
owner,
204-
code: code || undefined,
204+
code,
205205
severity,
206206
message,
207207
source,

src/vs/workbench/api/electron-browser/mainThreadEditor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2
1616
import { IApplyEditsOptions, IEditorPropertiesChangeData, IResolvedTextEditorConfiguration, ITextEditorConfigurationUpdate, IUndoStopOptions, TextEditorRevealType } from 'vs/workbench/api/node/extHost.protocol';
1717
import { EndOfLine, TextEditorLineNumbersStyle } from 'vs/workbench/api/node/extHostTypes';
1818
import { IEditor } from 'vs/workbench/common/editor';
19+
import { withNullAsUndefined } from 'vs/base/common/types';
1920

2021
export interface IFocusTracker {
2122
onGainedFocus(): void;
@@ -114,7 +115,7 @@ export class MainThreadTextEditorProperties {
114115
if (!oldProps || !MainThreadTextEditorProperties._selectionsEqual(oldProps.selections, this.selections)) {
115116
delta.selections = {
116117
selections: this.selections,
117-
source: selectionChangeSource || undefined
118+
source: withNullAsUndefined(selectionChangeSource)
118119
};
119120
}
120121

0 commit comments

Comments
 (0)