提交 61c369b5 编写于 作者: M Matt Bierner

Replace some instances of `|| null` with `withUndefinedAsNull`

The latter is more explicit, correctly handles some edge cases, and helps tag places in the code where we should look into replacing null with undefined.
上级 86460b3f
......@@ -39,6 +39,7 @@ import { ILogService, getLogLevel } from 'vs/platform/log/common/log';
import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
import { normalizeGitHubUrl } from 'vs/code/electron-browser/issue/issueReporterUtil';
import { Button } from 'vs/base/browser/ui/button/button';
import { withUndefinedAsNull } from 'vs/base/common/types';
const MAX_URL_LENGTH = platform.isWindows ? 2081 : 5400;
......@@ -211,7 +212,7 @@ export class IssueReporter extends Disposable {
styleTag.innerHTML = content.join('\n');
document.head.appendChild(styleTag);
document.body.style.color = styles.color || null;
document.body.style.color = withUndefinedAsNull(styles.color);
}
private handleExtensionData(extensions: IssueReporterExtensionData[]) {
......
......@@ -20,6 +20,7 @@ import { IConstructorSignature1, ServicesAccessor } from 'vs/platform/instantiat
import { IKeybindings, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { withUndefinedAsNull } from 'vs/base/common/types';
export type ServicesAccessor = ServicesAccessor;
export type IEditorContributionCtor = IConstructorSignature1<ICodeEditor, IEditorContribution>;
......@@ -88,7 +89,7 @@ export abstract class Command {
id: this.id,
handler: (accessor, args) => this.runCommand(accessor, args),
weight: this._kbOpts.weight,
when: kbWhen || null,
when: withUndefinedAsNull(kbWhen),
primary: this._kbOpts.primary,
secondary: this._kbOpts.secondary,
win: this._kbOpts.win,
......
......@@ -15,6 +15,7 @@ import { NULL_LANGUAGE_IDENTIFIER, NULL_MODE_ID } from 'vs/editor/common/modes/n
import { ILanguageExtensionPoint } from 'vs/editor/common/services/modeService';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
import { withUndefinedAsNull } from 'vs/base/common/types';
const hasOwnProperty = Object.prototype.hasOwnProperty;
......@@ -267,7 +268,7 @@ export class LanguagesRegistry extends Disposable {
return null;
}
const language = this._languages[modeId];
return (language.mimetypes[0] || null);
return withUndefinedAsNull(language.mimetypes[0]);
}
public extractModeIds(commaSeparatedMimetypesOrCommaSeparatedIds: string | undefined): string[] {
......
......@@ -16,6 +16,7 @@ import { keys } from 'vs/base/common/map';
import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService';
import { Schemas } from 'vs/base/common/network';
import { Emitter, Event } from 'vs/base/common/event';
import { withUndefinedAsNull } from 'vs/base/common/types';
function MODEL_ID(resource: URI): string {
return resource.toString();
......@@ -80,7 +81,7 @@ export class MarkerDecorationsService extends Disposable implements IMarkerDecor
getMarker(model: ITextModel, decoration: IModelDecoration): IMarker | null {
const markerDecorations = this._markerDecorations.get(MODEL_ID(model.uri));
return markerDecorations ? markerDecorations.getMarker(decoration) || null : null;
return markerDecorations ? withUndefinedAsNull(markerDecorations.getMarker(decoration)) : null;
}
getLiveMarkers(model: ITextModel): [Range, IMarker][] {
......
......@@ -8,6 +8,7 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { IMenu, IMenuActionOptions, IMenuItem, IMenuService, isIMenuItem, ISubmenuItem, MenuId, MenuItemAction, MenuRegistry, SubmenuItemAction } from 'vs/platform/actions/common/actions';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { withUndefinedAsNull } from 'vs/base/common/types';
export class MenuService implements IMenuService {
......@@ -110,7 +111,7 @@ class Menu implements IMenu {
const [id, items] = group;
const activeActions: Array<MenuItemAction | SubmenuItemAction> = [];
for (const item of items) {
if (this._contextKeyService.contextMatchesRules(item.when || null)) {
if (this._contextKeyService.contextMatchesRules(withUndefinedAsNull(item.when))) {
const action = isIMenuItem(item) ? new MenuItemAction(item.command, item.alt, options, this._contextKeyService, this._commandService) : new SubmenuItemAction(item);
activeActions.push(action);
}
......
......@@ -453,7 +453,7 @@ export class Configuration {
if (workspace && resource) {
const root = workspace.getFolder(resource);
if (root) {
return this._folderConfigurations.get(root.uri) || null;
return types.withUndefinedAsNull(this._folderConfigurations.get(root.uri));
}
}
return null;
......
......@@ -30,7 +30,7 @@ import { Dimension, trackFocus } from 'vs/base/browser/dom';
import { localize } from 'vs/nls';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { isUndefinedOrNull, withUndefinedAsNull } from 'vs/base/common/types';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { LayoutPriority } from 'vs/base/browser/ui/grid/gridview';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
......@@ -222,7 +222,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
}
}
return this.openComposite(id, focus) || null;
return withUndefinedAsNull(this.openComposite(id, focus));
}
showActivity(panelId: string, badge: IBadge, clazz?: string): IDisposable {
......
......@@ -783,7 +783,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
}
getResource(): URI | null {
return this.resource || null;
return types.withUndefinedAsNull(this.resource);
}
getInput(): IEditorInput | IResourceInput {
......
......@@ -8,6 +8,7 @@ import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
import { DataUri } from 'vs/base/common/resources';
import { withUndefinedAsNull } from 'vs/base/common/types';
/**
* An editor input to present data URIs in a binary editor. Data URIs have the form of:
......@@ -51,11 +52,11 @@ export class DataUriEditorInput extends EditorInput {
}
getName(): string | null {
return this.name || null;
return withUndefinedAsNull(this.name);
}
getDescription(): string | null {
return this.description || null;
return withUndefinedAsNull(this.description);
}
resolve(): Promise<BinaryEditorModel> {
......
......@@ -51,7 +51,7 @@ import { KeybindingParser } from 'vs/base/common/keybindingParser';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { getDefaultValue } from 'vs/platform/configuration/common/configurationRegistry';
import { isUndefined } from 'vs/base/common/types';
import { isUndefined, withUndefinedAsNull } from 'vs/base/common/types';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
function renderBody(body: string): string {
......@@ -712,7 +712,7 @@ export class ExtensionEditor extends BaseEditor {
constructor(extension: IExtension, parent?: IExtensionData) {
this.extension = extension;
this.parent = parent || null;
this.parent = withUndefinedAsNull(parent);
}
get hasChildren(): boolean {
......
......@@ -12,6 +12,7 @@ import { values } from 'vs/base/common/map';
import { memoize } from 'vs/base/common/decorators';
import { Emitter, Event } from 'vs/base/common/event';
import { Hasher } from 'vs/base/common/hash';
import { withUndefinedAsNull } from 'vs/base/common/types';
function compareUris(a: URI, b: URI) {
const astr = a.toString();
......@@ -138,7 +139,7 @@ export class MarkersModel {
}
getResourceMarkers(resource: URI): ResourceMarkers | null {
return this.resourcesByUri.get(resource.toString()) || null;
return withUndefinedAsNull(this.resourcesByUri.get(resource.toString()));
}
setResourceMarkers(resource: URI, rawMarkers: IMarker[]): void {
......
......@@ -27,6 +27,7 @@ import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IOutputChannelModel, IOutputChannelModelService } from 'vs/workbench/services/output/common/outputChannelModel';
import { withUndefinedAsNull } from 'vs/base/common/types';
const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel';
......@@ -141,7 +142,7 @@ export class OutputService extends Disposable implements IOutputService, ITextMo
}
getChannel(id: string): OutputChannel | null {
return this.channels.get(id) || null;
return withUndefinedAsNull(this.channels.get(id));
}
getChannelDescriptors(): IOutputChannelDescriptor[] {
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as arrays from 'vs/base/common/arrays';
import { isArray } from 'vs/base/common/types';
import { isArray, withUndefinedAsNull } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
......@@ -262,11 +262,11 @@ export class SettingsTreeModel {
}
getElementById(id: string): SettingsTreeElement | null {
return this._treeElementsById.get(id) || null;
return withUndefinedAsNull(this._treeElementsById.get(id));
}
getElementsByName(name: string): SettingsTreeSettingElement[] | null {
return this._treeElementsBySettingName.get(name) || null;
return withUndefinedAsNull(this._treeElementsBySettingName.get(name));
}
updateElementsByName(name: string): void {
......
......@@ -140,7 +140,7 @@ class GotoLineEntry extends EditorQuickOpenEntry {
}
getInput(): IEditorInput | null {
return this.editorService.activeEditor || null;
return types.withUndefinedAsNull(this.editorService.activeEditor);
}
getOptions(pinned?: boolean): ITextEditorOptions {
......
......@@ -289,7 +289,7 @@ class SymbolEntry extends EditorQuickOpenEntryGroup {
}
getInput(): IEditorInput | null {
return this.editorService.activeEditor || null;
return types.withUndefinedAsNull(this.editorService.activeEditor);
}
getOptions(pinned?: boolean): ITextEditorOptions {
......
......@@ -21,6 +21,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { Registry } from 'vs/platform/registry/common/platform';
import { CancellationToken } from 'vs/base/common/cancellation';
import { withUndefinedAsNull } from 'vs/base/common/types';
export const VIEW_PICKER_PREFIX = 'view ';
......@@ -137,7 +138,7 @@ export class ViewPickerHandler extends QuickOpenHandler {
const result: ViewEntry[] = [];
if (views.length) {
for (const view of views) {
if (this.contextKeyService.contextMatchesRules(view.when || null)) {
if (this.contextKeyService.contextMatchesRules(withUndefinedAsNull(view.when))) {
result.push(new ViewEntry(view.name, viewlet.name, () => this.viewsService.openView(view.id, true)));
}
}
......
......@@ -25,6 +25,7 @@ import { ILabelService } from 'vs/platform/label/common/label';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Schemas } from 'vs/base/common/network';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { withUndefinedAsNull } from 'vs/base/common/types';
class SymbolEntry extends EditorQuickOpenEntry {
private bearingResolve: Promise<this | undefined>;
......@@ -58,7 +59,7 @@ class SymbolEntry extends EditorQuickOpenEntry {
return this.labelService.getUriLabel(this.bearing.location.uri, { relative: true });
}
return containerName || null;
return withUndefinedAsNull(containerName);
}
getIcon(): string {
......
......@@ -27,6 +27,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { ITextModel } from 'vs/editor/common/model';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { withUndefinedAsNull } from 'vs/base/common/types';
export const enum ConfigurationEditingErrorCode {
......@@ -504,7 +505,7 @@ export class ConfigurationEditingService {
if (target === ConfigurationTarget.WORKSPACE) {
if (workbenchState === WorkbenchState.WORKSPACE) {
return workspace.configuration || null;
return withUndefinedAsNull(workspace.configuration);
}
if (workbenchState === WorkbenchState.FOLDER) {
return workspace.folders[0].toResource(relativePath);
......
......@@ -42,6 +42,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import product from 'vs/platform/product/node/product';
import { IEncodingOverride, ResourceEncodings } from 'vs/workbench/services/files/node/encoding';
import { createReadableOfSnapshot } from 'vs/workbench/services/files/node/streams';
import { withUndefinedAsNull } from 'vs/base/common/types';
export interface IFileServiceTestOptions {
disableWatcher?: boolean;
......@@ -464,7 +465,7 @@ export class FileService extends Disposable implements ILegacyFileService, IFile
}
};
let currentPosition: number | null = (options && options.position) || null;
let currentPosition: number | null = withUndefinedAsNull(options && options.position);
const readChunk = () => {
fs.read(fd, chunkBuffer, 0, chunkBuffer.length, currentPosition, (err, bytesRead) => {
......
......@@ -9,7 +9,7 @@ import { Event, Emitter } from 'vs/base/common/event';
import { guessMimeTypes } from 'vs/base/common/mime';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { URI } from 'vs/base/common/uri';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { isUndefinedOrNull, withUndefinedAsNull } from 'vs/base/common/types';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorModel, ISaveOptions, ISaveErrorHandler, ISaveParticipant, StateChange, SaveReason, IRawTextContent, ILoadOptions, LoadReason, IResolvedTextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles';
......@@ -492,7 +492,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return Promise.resolve(null);
}
return this.backupFileService.resolveBackupContent(backup).then(backupContent => backupContent || null, error => null /* ignore errors */);
return this.backupFileService.resolveBackupContent(backup).then(withUndefinedAsNull, error => null /* ignore errors */);
}
protected getOrCreateMode(modeService: IModeService, preferredModeIds: string | undefined, firstLineText?: string): ILanguageSelection {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册