diff --git a/src/vs/code/electron-browser/issue/issueReporterMain.ts b/src/vs/code/electron-browser/issue/issueReporterMain.ts index 8b829e07707..4bc05d5222d 100644 --- a/src/vs/code/electron-browser/issue/issueReporterMain.ts +++ b/src/vs/code/electron-browser/issue/issueReporterMain.ts @@ -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[]) { diff --git a/src/vs/editor/browser/editorExtensions.ts b/src/vs/editor/browser/editorExtensions.ts index 7406de01ffb..911a76501c2 100644 --- a/src/vs/editor/browser/editorExtensions.ts +++ b/src/vs/editor/browser/editorExtensions.ts @@ -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; @@ -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, diff --git a/src/vs/editor/common/services/languagesRegistry.ts b/src/vs/editor/common/services/languagesRegistry.ts index a57f2096f36..9e5e79223e1 100644 --- a/src/vs/editor/common/services/languagesRegistry.ts +++ b/src/vs/editor/common/services/languagesRegistry.ts @@ -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[] { diff --git a/src/vs/editor/common/services/markerDecorationsServiceImpl.ts b/src/vs/editor/common/services/markerDecorationsServiceImpl.ts index 70748519a41..0b6e25eac99 100644 --- a/src/vs/editor/common/services/markerDecorationsServiceImpl.ts +++ b/src/vs/editor/common/services/markerDecorationsServiceImpl.ts @@ -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][] { diff --git a/src/vs/platform/actions/common/menuService.ts b/src/vs/platform/actions/common/menuService.ts index f39cefee65e..e4b6abea01d 100644 --- a/src/vs/platform/actions/common/menuService.ts +++ b/src/vs/platform/actions/common/menuService.ts @@ -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 = []; 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); } diff --git a/src/vs/platform/configuration/common/configurationModels.ts b/src/vs/platform/configuration/common/configurationModels.ts index 6628e6a8823..942d3d35275 100644 --- a/src/vs/platform/configuration/common/configurationModels.ts +++ b/src/vs/platform/configuration/common/configurationModels.ts @@ -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; diff --git a/src/vs/workbench/browser/parts/panel/panelPart.ts b/src/vs/workbench/browser/parts/panel/panelPart.ts index f6074ff50e0..18970a1611b 100644 --- a/src/vs/workbench/browser/parts/panel/panelPart.ts +++ b/src/vs/workbench/browser/parts/panel/panelPart.ts @@ -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 implements IPanelService { } } - return this.openComposite(id, focus) || null; + return withUndefinedAsNull(this.openComposite(id, focus)); } showActivity(panelId: string, badge: IBadge, clazz?: string): IDisposable { diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 1cae3892523..e96ecc250f8 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -783,7 +783,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry { } getResource(): URI | null { - return this.resource || null; + return types.withUndefinedAsNull(this.resource); } getInput(): IEditorInput | IResourceInput { diff --git a/src/vs/workbench/common/editor/dataUriEditorInput.ts b/src/vs/workbench/common/editor/dataUriEditorInput.ts index 8b6bab4df99..8b3ecd4cbd6 100644 --- a/src/vs/workbench/common/editor/dataUriEditorInput.ts +++ b/src/vs/workbench/common/editor/dataUriEditorInput.ts @@ -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 { diff --git a/src/vs/workbench/contrib/extensions/electron-browser/extensionEditor.ts b/src/vs/workbench/contrib/extensions/electron-browser/extensionEditor.ts index c1c89619d65..a8ee3fe4eba 100644 --- a/src/vs/workbench/contrib/extensions/electron-browser/extensionEditor.ts +++ b/src/vs/workbench/contrib/extensions/electron-browser/extensionEditor.ts @@ -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 { diff --git a/src/vs/workbench/contrib/markers/browser/markersModel.ts b/src/vs/workbench/contrib/markers/browser/markersModel.ts index 41522466990..6f24498a51a 100644 --- a/src/vs/workbench/contrib/markers/browser/markersModel.ts +++ b/src/vs/workbench/contrib/markers/browser/markersModel.ts @@ -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 { diff --git a/src/vs/workbench/contrib/output/browser/outputServices.ts b/src/vs/workbench/contrib/output/browser/outputServices.ts index 15963e4e2e0..64af8aeae43 100644 --- a/src/vs/workbench/contrib/output/browser/outputServices.ts +++ b/src/vs/workbench/contrib/output/browser/outputServices.ts @@ -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[] { diff --git a/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts b/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts index 4e7f56b60d8..4a5c96da7bb 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts @@ -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 { diff --git a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts index f4a1b10e4b4..6af674415aa 100644 --- a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts @@ -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 { diff --git a/src/vs/workbench/contrib/quickopen/browser/gotoSymbolHandler.ts b/src/vs/workbench/contrib/quickopen/browser/gotoSymbolHandler.ts index e53df5f3e76..e81454d8db5 100644 --- a/src/vs/workbench/contrib/quickopen/browser/gotoSymbolHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/gotoSymbolHandler.ts @@ -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 { diff --git a/src/vs/workbench/contrib/quickopen/browser/viewPickerHandler.ts b/src/vs/workbench/contrib/quickopen/browser/viewPickerHandler.ts index b7b48f4f875..281b5a3ed3d 100644 --- a/src/vs/workbench/contrib/quickopen/browser/viewPickerHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/viewPickerHandler.ts @@ -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))); } } diff --git a/src/vs/workbench/contrib/search/browser/openSymbolHandler.ts b/src/vs/workbench/contrib/search/browser/openSymbolHandler.ts index d53e63d5fe6..32f606bb2ca 100644 --- a/src/vs/workbench/contrib/search/browser/openSymbolHandler.ts +++ b/src/vs/workbench/contrib/search/browser/openSymbolHandler.ts @@ -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; @@ -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 { diff --git a/src/vs/workbench/services/configuration/common/configurationEditingService.ts b/src/vs/workbench/services/configuration/common/configurationEditingService.ts index bd135404a37..e1a2f0815b3 100644 --- a/src/vs/workbench/services/configuration/common/configurationEditingService.ts +++ b/src/vs/workbench/services/configuration/common/configurationEditingService.ts @@ -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); diff --git a/src/vs/workbench/services/files/node/fileService.ts b/src/vs/workbench/services/files/node/fileService.ts index 7dbeac6cfc3..f870dade474 100644 --- a/src/vs/workbench/services/files/node/fileService.ts +++ b/src/vs/workbench/services/files/node/fileService.ts @@ -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) => { diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index 1b7f86ba5f3..5fc755ed47e 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -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 {