Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withUndefinedAsNull(x) -> x ?? null #189983

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/vs/base/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,6 @@ export function withNullAsUndefined<T>(x: T | null): T | undefined {
return x === null ? undefined : x;
}

/**
* Converts undefined to null, passes all other values through.
*/
export function withUndefinedAsNull<T>(x: T | undefined): T | null {
return typeof x === 'undefined' ? null : x;
}

type AddFirstParameterToFunction<T, TargetFunctionsReturnType, FirstParameter> = T extends (...args: any[]) => TargetFunctionsReturnType ?
// Function: add param to function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { UriList, VSDataTransfer, createStringDataTransferItem, matchesMimeType
import { Disposable } from 'vs/base/common/lifecycle';
import { Mimes } from 'vs/base/common/mime';
import * as platform from 'vs/base/common/platform';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { generateUuid } from 'vs/base/common/uuid';
import { ClipboardEventUtils } from 'vs/editor/browser/controller/textAreaInput';
import { toExternalVSDataTransfer, toVSDataTransfer } from 'vs/editor/browser/dnd';
Expand Down Expand Up @@ -398,7 +397,7 @@ export class CopyPasteController extends Disposable implements IEditorContributi
return {
defaultPastePayload: {
mode: metadata.mode,
multicursorText: withUndefinedAsNull(metadata.multicursorText),
multicursorText: metadata.multicursorText ?? null,
pasteOnNewLine: !!metadata.isFromEmptySelection,
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/quickinput/browser/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Disposable, DisposableStore, dispose } from 'vs/base/common/lifecycle';
import { isIOS } from 'vs/base/common/platform';
import Severity from 'vs/base/common/severity';
import { ThemeIcon } from 'vs/base/common/themables';
import { isString, withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
import { isString, withNullAsUndefined } from 'vs/base/common/types';
import 'vs/css!./media/quickInput';
import { localize } from 'vs/nls';
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
Expand Down Expand Up @@ -1077,7 +1077,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
}
}
if (this.ui.list.ariaLabel !== ariaLabel) {
this.ui.list.ariaLabel = withUndefinedAsNull(ariaLabel);
this.ui.list.ariaLabel = ariaLabel ?? null;
}
this.ui.list.matchOnDescription = this.matchOnDescription;
this.ui.list.matchOnDetail = this.matchOnDetail;
Expand Down
11 changes: 5 additions & 6 deletions src/vs/workbench/api/common/extHostWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Schemas } from 'vs/base/common/network';
import { Counter } from 'vs/base/common/numbers';
import { basename, basenameOrAuthority, dirname, ExtUri, relativePath } from 'vs/base/common/resources';
import { compare } from 'vs/base/common/strings';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { URI, UriComponents } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
Expand Down Expand Up @@ -462,10 +461,10 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac

const { includePattern, folder } = parseSearchInclude(GlobPattern.from(include));
return this._proxy.$startFileSearch(
withUndefinedAsNull(includePattern),
withUndefinedAsNull(folder),
withUndefinedAsNull(excludePatternOrDisregardExcludes),
withUndefinedAsNull(maxResults),
includePattern ?? null,
folder ?? null,
excludePatternOrDisregardExcludes ?? null,
maxResults ?? null,
token
)
.then(data => Array.isArray(data) ? data.map(d => URI.revive(d)) : []);
Expand Down Expand Up @@ -541,7 +540,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
try {
const result = await this._proxy.$startTextSearch(
query,
withUndefinedAsNull(folder),
folder ?? null,
queryOptions,
requestId,
token);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { localize } from 'vs/nls';
import { runAtThisOrScheduleAtNextAnimationFrame } from 'vs/base/browser/dom';
import { format, compare, splitLines } from 'vs/base/common/strings';
import { extname, basename, isEqual } from 'vs/base/common/resources';
import { areFunctions, assertIsDefined, withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
import { areFunctions, assertIsDefined, withNullAsUndefined } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { Action } from 'vs/base/common/actions';
import { Language } from 'vs/base/common/platform';
Expand Down Expand Up @@ -1110,7 +1110,7 @@ export class ChangeLanguageAction extends Action2 {

// User decided to configure settings for current language
if (pick === configureLanguageSettings) {
preferencesService.openUserSettings({ jsonEditor: true, revealSetting: { key: `[${withUndefinedAsNull(currentLanguageId)}]`, edit: true } });
preferencesService.openUserSettings({ jsonEditor: true, revealSetting: { key: `[${currentLanguageId ?? null}]`, edit: true } });
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/editor/titleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { ResourceContextKey, ActiveEditorPinnedContext, ActiveEditorStickyContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, ActiveEditorLastInGroupContext, ActiveEditorFirstInGroupContext, ActiveEditorAvailableEditorIdsContext, applyAvailableEditorIds } from 'vs/workbench/common/contextkeys';
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
import { IFileService } from 'vs/platform/files/common/files';
import { withNullAsUndefined, withUndefinedAsNull, assertIsDefined } from 'vs/base/common/types';
import { withNullAsUndefined, assertIsDefined } from 'vs/base/common/types';
import { isFirefox } from 'vs/base/browser/browser';
import { isCancellationError } from 'vs/base/common/errors';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
Expand Down Expand Up @@ -251,7 +251,7 @@ export abstract class TitleControl extends Themable {
this.contextKeyService.bufferChangeEvents(() => {
const activeEditor = this.group.activeEditor;

this.resourceContext.set(withUndefinedAsNull(EditorResourceAccessor.getOriginalUri(activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY })));
this.resourceContext.set(EditorResourceAccessor.getOriginalUri(activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY } ?? null));

this.editorPinnedContext.set(activeEditor ? this.group.isPinned(activeEditor) : false);
this.editorIsFirstContext.set(activeEditor ? this.group.isFirst(activeEditor) : false);
Expand Down Expand Up @@ -360,7 +360,7 @@ export abstract class TitleControl extends Themable {

// Update contexts based on editor picked and remember previous to restore
const currentResourceContext = this.resourceContext.get();
this.resourceContext.set(withUndefinedAsNull(EditorResourceAccessor.getOriginalUri(editor, { supportSideBySide: SideBySideEditor.PRIMARY })));
this.resourceContext.set(EditorResourceAccessor.getOriginalUri(editor, { supportSideBySide: SideBySideEditor.PRIMARY } ?? null));
const currentPinnedContext = !!this.editorPinnedContext.get();
this.editorPinnedContext.set(this.group.isPinned(editor));
const currentEditorIsFirstContext = !!this.editorIsFirstContext.get();
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/common/editor/textEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ILanguageService, ILanguageSelection } from 'vs/editor/common/languages
import { IModelService } from 'vs/editor/common/services/model';
import { MutableDisposable } from 'vs/base/common/lifecycle';
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { ILanguageDetectionService, LanguageDetectionLanguageEventSource } from 'vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
import { ThrottledDelayer } from 'vs/base/common/async';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
Expand Down Expand Up @@ -188,7 +187,7 @@ export class BaseTextEditorModel extends EditorModel implements ITextEditorModel

// lookup language via resource path if the provided language is unspecific
if (!preferredLanguage || preferredLanguage === PLAINTEXT_LANGUAGE_ID) {
return languageService.createByFilepathOrFirstLine(withUndefinedAsNull(resource), firstLineText);
return languageService.createByFilepathOrFirstLine(resource ?? null, firstLineText);
}

// otherwise take the preferred language for granted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { Position } from 'vs/editor/common/core/position';
import { CommentThreadRangeDecorator } from 'vs/workbench/contrib/comments/browser/commentThreadRangeDecorator';
import { ICursorSelectionChangedEvent } from 'vs/editor/common/cursorEvents';
import { CommentsPanel } from 'vs/workbench/contrib/comments/browser/commentsView';
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
import { withNullAsUndefined } from 'vs/base/common/types';

export const ID = 'editor.contrib.review';

Expand Down Expand Up @@ -405,7 +405,7 @@ export class CommentController implements IEditorContribution {
}
this._editorDisposables.push(this.editor.onMouseMove(e => this.onEditorMouseMove(e)));
this._editorDisposables.push(this.editor.onDidChangeCursorPosition(e => this.onEditorChangeCursorPosition(e.position)));
this._editorDisposables.push(this.editor.onDidFocusEditorWidget(() => this.onEditorChangeCursorPosition(withUndefinedAsNull(this.editor?.getPosition()))));
this._editorDisposables.push(this.editor.onDidFocusEditorWidget(() => this.onEditorChangeCursorPosition(this.editor?.getPosition() ?? null)));
this._editorDisposables.push(this.editor.onDidChangeCursorSelection(e => this.onEditorChangeCursorSelection(e)));
this._editorDisposables.push(this.editor.onDidBlurEditorWidget(() => this.onEditorChangeCursorSelection()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { DisposableStore, IDisposable, dispose } from 'vs/base/common/lifecycle';
import * as objects from 'vs/base/common/objects';
import * as resources from 'vs/base/common/resources';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { URI as uri } from 'vs/base/common/uri';
import * as nls from 'vs/nls';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -621,7 +620,7 @@ class Launch extends AbstractLaunch implements ILaunch {
}, ACTIVE_GROUP);

return ({
editor: withUndefinedAsNull(editor),
editor: editor ?? null,
created
});
}
Expand Down Expand Up @@ -681,7 +680,7 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch {
}, ACTIVE_GROUP);

return ({
editor: withUndefinedAsNull(editor),
editor: editor ?? null,
created: false
});
}
Expand Down Expand Up @@ -721,7 +720,7 @@ class UserLaunch extends AbstractLaunch implements ILaunch {
async openConfigFile({ preserveFocus, type, useInitialContent }: { preserveFocus: boolean; type?: string; useInitialContent?: boolean }): Promise<{ editor: IEditorPane | null; created: boolean }> {
const editor = await this.preferencesService.openUserSettings({ jsonEditor: true, preserveFocus, revealSetting: { key: 'launch' } });
return ({
editor: withUndefinedAsNull(editor),
editor: editor ?? null,
created: false
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IWorkspaceFolder, IWorkspace } from 'vs/platform/workspace/common/workspace';
import { ITaskEvent, TaskEventKind, ITaskIdentifier } from 'vs/workbench/contrib/tasks/common/tasks';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
import { IDebugConfiguration } from 'vs/workbench/contrib/debug/common/debug';
import { IViewsService } from 'vs/workbench/common/views';
Expand Down Expand Up @@ -235,7 +234,7 @@ export class DebugTaskRunner {
return inactivePromise;
}

return taskPromise.then(withUndefinedAsNull);
return taskPromise.then(x => x ?? null);
});

return new Promise((c, e) => {
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/contrib/debug/browser/variablesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { RunOnceScheduler, timeout } from 'vs/base/common/async';
import { Codicon } from 'vs/base/common/codicons';
import { createMatches, FuzzyScore } from 'vs/base/common/filters';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { localize } from 'vs/nls';
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IMenuService, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
Expand Down Expand Up @@ -127,7 +126,7 @@ export class VariablesView extends ViewPane {
}
});

this.tree.setInput(withUndefinedAsNull(this.debugService.getViewModel().focusedStackFrame));
this.tree.setInput(this.debugService.getViewModel().focusedStackFrame ?? null);

CONTEXT_VARIABLES_FOCUSED.bindTo(this.tree.contextKeyService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewl
import { IDragAndDropData, DataTransfers } from 'vs/base/browser/dnd';
import { memoize } from 'vs/base/common/decorators';
import { ElementsDragAndDropData, NativeDragAndDropData } from 'vs/base/browser/ui/list/listView';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IWorkingCopy, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopy';
import { AutoSaveMode, IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
Expand Down Expand Up @@ -259,7 +258,7 @@ export class OpenEditorsView extends ViewPane {
const resource = element.getResource();
this.dirtyEditorFocusedContext.set(element.editor.isDirty() && !element.editor.isSaving());
this.readonlyEditorFocusedContext.set(!!element.editor.isReadonly());
this.resourceContext.set(withUndefinedAsNull(resource));
this.resourceContext.set(resource ?? null);
} else if (!!element) {
this.groupFocusedContext.set(true);
}
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/contrib/markers/browser/markersModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { isNonEmptyArray, flatten } from 'vs/base/common/arrays';
import { ResourceMap } from 'vs/base/common/map';
import { Emitter, Event } from 'vs/base/common/event';
import { Hasher } from 'vs/base/common/hash';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { splitLines } from 'vs/base/common/strings';
import { IMatch } from 'vs/base/common/filters';
import { unsupportedSchemas } from 'vs/platform/markers/common/markerService';
Expand Down Expand Up @@ -183,7 +182,7 @@ export class MarkersModel {
}

getResourceMarkers(resource: URI): ResourceMarkers | null {
return withUndefinedAsNull(this.resourcesByUri.get(extUri.getComparisonKey(resource, true)));
return this.resourcesByUri.get(extUri.getComparisonKey(resource, true)) ?? null;
}

setResourceMarkers(resourcesMarkers: [URI, IMarker[]][]): void {
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/contrib/markers/browser/markersView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { StandardKeyboardEvent, IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { ResourceLabels } from 'vs/workbench/browser/labels';
import { IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { MementoObject, Memento } from 'vs/workbench/common/memento';
import { IIdentityProvider, IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
import { KeyCode } from 'vs/base/common/keyCodes';
Expand Down Expand Up @@ -652,7 +651,7 @@ export class MarkersView extends FilterViewPane implements IMarkersView {

private setCurrentActiveEditor(): void {
const activeEditor = this.editorService.activeEditor;
this.currentActiveResource = activeEditor ? withUndefinedAsNull(EditorResourceAccessor.getOriginalUri(activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY })) : null;
this.currentActiveResource = activeEditor ? EditorResourceAccessor.getOriginalUri(activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }) ?? null : null;
}

private onSelected(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Iterable } from 'vs/base/common/iterator';
import { KeyCode } from 'vs/base/common/keyCodes';
import { Disposable, DisposableStore, dispose } from 'vs/base/common/lifecycle';
import * as platform from 'vs/base/common/platform';
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
import { withNullAsUndefined } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import 'vs/css!./media/settingsEditor2';
import { localize } from 'vs/nls';
Expand Down Expand Up @@ -395,7 +395,7 @@ export class SettingsEditor2 extends EditorPane {
this.editorMemento.clearEditorState(this.input, this.group);
}

return withUndefinedAsNull(cachedState);
return cachedState ?? null;
}

override getViewState(): object | undefined {
Expand Down Expand Up @@ -830,7 +830,7 @@ export class SettingsEditor2 extends EditorPane {
}));

this._register(this.tocTree.onDidChangeFocus(e => {
const element: SettingsTreeGroupElement | null = withUndefinedAsNull(e.elements?.[0]);
const element: SettingsTreeGroupElement | null = e.elements?.[0] ?? null;
if (this.tocFocusedElement === element) {
return;
}
Expand Down Expand Up @@ -937,7 +937,7 @@ export class SettingsEditor2 extends EditorPane {
if (classList && classList.contains('monaco-list') && classList.contains('settings-editor-tree')) {
this._currentFocusContext = SettingsFocusContext.SettingTree;
this.settingRowFocused.set(true);
this.treeFocusedElement ??= withUndefinedAsNull(this.settingsTree.firstVisibleElement);
this.treeFocusedElement ??= this.settingsTree.firstVisibleElement ?? null;
if (this.treeFocusedElement) {
this.treeFocusedElement.tabbable = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as arrays from 'vs/base/common/arrays';
import { escapeRegExpCharacters, isFalsyOrWhitespace } from 'vs/base/common/strings';
import { withUndefinedAsNull, isUndefinedOrNull } from 'vs/base/common/types';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { ConfigurationTarget, IConfigurationValue } from 'vs/platform/configuration/common/configuration';
import { SettingsTarget } from 'vs/workbench/contrib/preferences/browser/preferencesWidgets';
Expand Down Expand Up @@ -530,7 +530,7 @@ export class SettingsTreeModel {
}

getElementsByName(name: string): SettingsTreeSettingElement[] | null {
return withUndefinedAsNull(this._treeElementsBySettingName.get(name));
return this._treeElementsBySettingName.get(name) ?? null;
}

updateElementsByName(name: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions, Configur
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IOpenSettingsOptions, IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { withUndefinedAsNull, withNullAsUndefined } from 'vs/base/common/types';
import { withNullAsUndefined } from 'vs/base/common/types';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { ITextModel } from 'vs/editor/common/model';
import { IReference } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -622,7 +622,7 @@ export class ConfigurationEditing {

if (target === EditableConfigurationTarget.WORKSPACE) {
if (workbenchState === WorkbenchState.WORKSPACE) {
return withUndefinedAsNull(workspace.configuration);
return workspace.configuration ?? null;
}
if (workbenchState === WorkbenchState.FOLDER) {
return workspace.folders[0].toResource(relativePath);
Expand Down