提交 10c0126e 编写于 作者: B Benjamin Pasero

debt - reduce null | undefined usages

上级 eac04831
......@@ -365,7 +365,7 @@ export class InputBox extends Widget {
return !errorMsg;
}
private stylesForType(type: MessageType | undefined): { border: Color | undefined | null; background: Color | undefined | null; foreground: Color | undefined | null } {
private stylesForType(type: MessageType | undefined): { border: Color | undefined; background: Color | undefined; foreground: Color | undefined } {
switch (type) {
case MessageType.INFO: return { border: this.inputValidationInfoBorder, background: this.inputValidationInfoBackground, foreground: this.inputValidationInfoForeground };
case MessageType.WARNING: return { border: this.inputValidationWarningBorder, background: this.inputValidationWarningBackground, foreground: this.inputValidationWarningForeground };
......
......@@ -93,7 +93,6 @@ export function isUndefinedOrNull(obj: any): obj is undefined | null {
return isUndefined(obj) || obj === null;
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
/**
......
......@@ -270,7 +270,7 @@ suite('Arrays', () => {
}
test('coalesce', () => {
let a: Array<number | undefined | null> = arrays.coalesce([null, 1, null, 2, 3]);
let a: Array<number | null> = arrays.coalesce([null, 1, null, 2, 3]);
assert.equal(a.length, 3);
assert.equal(a[0], 1);
assert.equal(a[1], 2);
......@@ -306,7 +306,7 @@ suite('Arrays', () => {
});
test('coalesce - inplace', function () {
let a: Array<number | undefined | null> = [null, 1, null, 2, 3];
let a: Array<number | null> = [null, 1, null, 2, 3];
arrays.coalesceInPlace(a);
assert.equal(a.length, 3);
assert.equal(a[0], 1);
......
......@@ -36,7 +36,7 @@ export interface ITextModelContentProvider {
/**
* Given a resource, return the content of the resource as `ITextModel`.
*/
provideTextContent(resource: URI): Promise<ITextModel | undefined | null> | null | undefined;
provideTextContent(resource: URI): Promise<ITextModel | null> | null;
}
export interface ITextEditorModel extends IEditorModel {
......
......@@ -42,7 +42,7 @@ suite('Files', () => {
assert.strictEqual(true, r1.gotDeleted());
});
function testIsEqual(testMethod: (pA: string | null | undefined, pB: string, ignoreCase: boolean) => boolean): void {
function testIsEqual(testMethod: (pA: string | undefined, pB: string, ignoreCase: boolean) => boolean): void {
// corner cases
assert(testMethod('', '', true));
......
......@@ -41,14 +41,14 @@ export class MainThreadDocumentContentProviders implements MainThreadDocumentCon
$registerTextContentProvider(handle: number, scheme: string): void {
const registration = this._textModelResolverService.registerTextModelContentProvider(scheme, {
provideTextContent: (uri: URI): Promise<ITextModel | undefined> => {
provideTextContent: (uri: URI): Promise<ITextModel | null> => {
return this._proxy.$provideTextDocumentContent(handle, uri).then(value => {
if (typeof value === 'string') {
const firstLineText = value.substr(0, 1 + value.search(/\r?\n/));
const languageSelection = this._modeService.createByFilepathOrFirstLine(uri.fsPath, firstLineText);
return this._modelService.createModel(value, languageSelection, uri);
}
return undefined;
return null;
});
}
});
......
......@@ -234,7 +234,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
const timeout = this._configurationService.getValue<number>('editor.formatOnSaveTimeout', { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() });
return new Promise<TextEdit[] | null | undefined>((resolve, reject) => {
return new Promise<TextEdit[] | null>((resolve, reject) => {
const source = new CancellationTokenSource();
const request = getDocumentFormattingEdits(this._telemetryService, this._editorWorkerService, model, model.getFormattingOptions(), FormatMode.Auto, source.token);
......
......@@ -66,6 +66,7 @@ import * as vscode from 'vscode';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { originalFSPath } from 'vs/base/common/resources';
import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer';
import { withNullAsUndefined } from 'vs/base/common/types';
export interface IExtensionApiFactory {
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
......@@ -535,7 +536,7 @@ export function createApiFactory(
return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
},
findFiles: (include, exclude, maxResults?, token?) => {
return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(exclude), maxResults, extension.identifier, token);
return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(withNullAsUndefined(exclude)), maxResults, extension.identifier, token);
},
findTextInFiles: (query: vscode.TextSearchQuery, optionsOrCallback, callbackOrToken?, token?: vscode.CancellationToken) => {
let options: vscode.FindTextInFilesOptions;
......
......@@ -986,9 +986,9 @@ export namespace TextEditorOptions {
export namespace GlobPattern {
export function from(pattern: vscode.GlobPattern): string | types.RelativePattern;
export function from(pattern: undefined | null): undefined | null;
export function from(pattern: vscode.GlobPattern | undefined | null): string | types.RelativePattern | undefined | null;
export function from(pattern: vscode.GlobPattern | undefined | null): string | types.RelativePattern | undefined | null {
export function from(pattern: undefined): undefined;
export function from(pattern: vscode.GlobPattern | undefined): string | types.RelativePattern | undefined;
export function from(pattern: vscode.GlobPattern | undefined): string | types.RelativePattern | undefined {
if (pattern instanceof types.RelativePattern) {
return pattern;
}
......
......@@ -388,7 +388,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
// --- search ---
findFiles(include: string | RelativePattern | undefined | null, exclude: vscode.GlobPattern | undefined | null, maxResults: number | undefined, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
findFiles(include: string | RelativePattern | undefined, exclude: vscode.GlobPattern | undefined, maxResults: number | undefined, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
this._logService.trace(`extHostWorkspace#findFiles: fileSearch, extension: ${extensionId.value}, entryPoint: findFiles`);
let includePattern: string | undefined;
......
......@@ -28,7 +28,7 @@ export class BinaryResourceDiffEditor extends SideBySideEditor {
super(telemetryService, instantiationService, themeService, storageService);
}
getMetadata(): string | null {
getMetadata(): string | undefined {
const master = this.masterEditor;
const details = this.detailsEditor;
......@@ -36,6 +36,6 @@ export class BinaryResourceDiffEditor extends SideBySideEditor {
return nls.localize('metadataDiff', "{0} ↔ {1}", details.getMetadata(), master.getMetadata());
}
return null;
return undefined;
}
}
......@@ -37,7 +37,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
get onDidOpenInPlace(): Event<void> { return this._onDidOpenInPlace.event; }
private callbacks: IOpenCallbacks;
private metadata: string | null;
private metadata: string | undefined;
private binaryContainer: HTMLElement;
private scrollbar: DomScrollableElement;
private resourceViewerContext: ResourceViewerContext;
......@@ -110,20 +110,20 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
});
}
private handleMetadataChanged(meta: string | null): void {
private handleMetadataChanged(meta: string | undefined): void {
this.metadata = meta;
this._onMetadataChanged.fire();
}
getMetadata() {
getMetadata(): string | undefined {
return this.metadata;
}
clearInput(): void {
// Clear Meta
this.handleMetadataChanged(null);
this.handleMetadataChanged(undefined);
// Clear Resource Viewer
clearNode(this.binaryContainer);
......
......@@ -140,43 +140,35 @@ interface StateDelta {
indentation?: string;
tabFocusMode?: boolean;
screenReaderMode?: boolean;
metadata?: string | null;
metadata?: string | undefined;
}
class State {
private _selectionStatus: string | null | undefined;
get selectionStatus(): string | null | undefined { return this._selectionStatus; }
private _selectionStatus: string | undefined;
get selectionStatus(): string | undefined { return this._selectionStatus; }
private _mode: string | null | undefined;
get mode(): string | null | undefined { return this._mode; }
private _mode: string | undefined;
get mode(): string | undefined { return this._mode; }
private _encoding: string | null | undefined;
get encoding(): string | null | undefined { return this._encoding; }
private _encoding: string | undefined;
get encoding(): string | undefined { return this._encoding; }
private _EOL: string | null | undefined;
get EOL(): string | null | undefined { return this._EOL; }
private _EOL: string | undefined;
get EOL(): string | undefined { return this._EOL; }
private _indentation: string | null | undefined;
get indentation(): string | null | undefined { return this._indentation; }
private _indentation: string | undefined;
get indentation(): string | undefined { return this._indentation; }
private _tabFocusMode: boolean | null | undefined;
get tabFocusMode(): boolean | null | undefined { return this._tabFocusMode; }
private _tabFocusMode: boolean | undefined;
get tabFocusMode(): boolean | undefined { return this._tabFocusMode; }
private _screenReaderMode: boolean | null | undefined;
get screenReaderMode(): boolean | null | undefined { return this._screenReaderMode; }
private _screenReaderMode: boolean | undefined;
get screenReaderMode(): boolean | undefined { return this._screenReaderMode; }
private _metadata: string | null | undefined;
get metadata(): string | null | undefined { return this._metadata; }
private _metadata: string | undefined;
get metadata(): string | undefined { return this._metadata; }
constructor() {
this._selectionStatus = null;
this._mode = null;
this._encoding = null;
this._EOL = null;
this._tabFocusMode = false;
this._screenReaderMode = false;
this._metadata = null;
}
constructor() { }
update(update: StateDelta): StateChange {
const change = new StateChange();
......
......@@ -179,7 +179,7 @@ export class TitlebarPart extends Part implements ITitleService {
}
private updateRepresentedFilename(): void {
const file = toResource(this.editorService.activeEditor || null, { supportSideBySide: true, filter: 'file' });
const file = toResource(this.editorService.activeEditor, { supportSideBySide: true, filter: 'file' });
const path = file ? file.fsPath : '';
// Apply to window
......@@ -282,7 +282,7 @@ export class TitlebarPart extends Part implements ITitleService {
// Compute folder resource
// Single Root Workspace: always the root single workspace in this case
// Otherwise: root folder of the currently active file if any
const folder = this.contextService.getWorkbenchState() === WorkbenchState.FOLDER ? workspace.folders[0] : this.contextService.getWorkspaceFolder(toResource(editor || null, { supportSideBySide: true })!);
const folder = this.contextService.getWorkbenchState() === WorkbenchState.FOLDER ? workspace.folders[0] : this.contextService.getWorkspaceFolder(toResource(editor, { supportSideBySide: true })!);
// Variables
const activeEditorShort = editor ? editor.getTitle(Verbosity.SHORT) : '';
......
......@@ -642,7 +642,7 @@ export class GlobalCompareResourcesAction extends Action {
override: this.editorService.openEditor({
leftResource: activeResource,
rightResource: resource
}).then(() => undefined)
}).then(() => null)
};
}
......@@ -833,7 +833,7 @@ export class ShowActiveFileInExplorer extends Action {
}
public run(): Promise<any> {
const resource = toResource(this.editorService.activeEditor || null, { supportSideBySide: true });
const resource = toResource(this.editorService.activeEditor, { supportSideBySide: true });
if (resource) {
this.commandService.executeCommand(REVEAL_IN_EXPLORER_COMMAND_ID, resource);
} else {
......@@ -905,7 +905,7 @@ export class ShowOpenedFileInNewWindow extends Action {
}
public run(): Promise<any> {
const fileResource = toResource(this.editorService.activeEditor || null, { supportSideBySide: true });
const fileResource = toResource(this.editorService.activeEditor, { supportSideBySide: true });
if (fileResource) {
if (this.fileService.canHandleResource(fileResource)) {
this.windowService.openWindow([{ uri: fileResource, typeHint: 'file' }], { forceNewWindow: true, forceOpenWorkspaceAsFile: true });
......@@ -1008,7 +1008,7 @@ export class CompareWithClipboardAction extends Action {
}
public run(): Promise<any> {
const resource = toResource(this.editorService.activeEditor || null, { supportSideBySide: true });
const resource = toResource(this.editorService.activeEditor, { supportSideBySide: true });
if (resource && (this.fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) {
if (!this.registrationDisposal) {
const provider = this.instantiationService.createInstance(ClipboardContentProvider);
......
......@@ -119,7 +119,7 @@ function save(
let viewStateOfSource: IEditorViewState | null;
const activeTextEditorWidget = getCodeEditor(editorService.activeTextEditorWidget);
if (activeTextEditorWidget) {
const activeResource = toResource(editorService.activeEditor || null, { supportSideBySide: true });
const activeResource = toResource(editorService.activeEditor, { supportSideBySide: true });
if (activeResource && (fileService.canHandleResource(activeResource) || resource.scheme === Schemas.untitled) && activeResource.toString() === resource.toString()) {
viewStateOfSource = activeTextEditorWidget.saveViewState();
}
......
......@@ -72,7 +72,7 @@ class WebviewProtocolProvider extends Disposable {
const appRootUri = URI.file(this._environmentService.appRoot);
registerFileProtocol(contents, WebviewProtocol.CoreResource, this._fileService, null, () => [
registerFileProtocol(contents, WebviewProtocol.CoreResource, this._fileService, undefined, () => [
appRootUri
]);
......
......@@ -30,7 +30,7 @@ export function registerFileProtocol(
contents: Electron.WebContents,
protocol: WebviewProtocol,
fileService: IFileService,
extensionLocation: URI | null | undefined,
extensionLocation: URI | undefined,
getRoots: () => ReadonlyArray<URI>
) {
contents.session.protocol.registerBufferProtocol(protocol, (request, callback: any) => {
......
......@@ -487,7 +487,7 @@ export class ConfigurationEditingService {
return { key, jsonPath, value: config.value, resource: resource || undefined, target };
}
private isWorkspaceConfigurationResource(resource: URI | null | undefined): boolean {
private isWorkspaceConfigurationResource(resource: URI | null): boolean {
const workspace = this.contextService.getWorkspace();
return !!(workspace.configuration && resource && workspace.configuration.fsPath === resource.fsPath);
}
......
......@@ -165,7 +165,7 @@ export class ConfigurationResolverService extends AbstractVariableResolverServic
const [type, name] = variable.split(':', 2);
let result: string | undefined | null;
let result: string | undefined;
switch (type) {
......
......@@ -291,7 +291,7 @@ class DecorationProviderWrapper {
}
}
private _fetchData(uri: URI): IDecorationData | undefined | null {
private _fetchData(uri: URI): IDecorationData | null {
// check for pending request and cancel it
const pendingRequest = this.data.get(uri.toString());
......@@ -319,11 +319,11 @@ class DecorationProviderWrapper {
}));
this.data.set(uri.toString(), request);
return undefined;
return null;
}
}
private _keepItem(uri: URI, data: IDecorationData | null | undefined): IDecorationData | null {
private _keepItem(uri: URI, data: IDecorationData | undefined): IDecorationData | null {
const deco = data ? data : null;
const old = this.data.set(uri.toString(), deco);
if (deco || old) {
......
......@@ -36,7 +36,7 @@ export interface IOpenEditorOverride {
* If defined, will prevent the opening of an editor and replace the resulting
* promise with the provided promise for the openEditor() call.
*/
override?: Promise<IEditor | null | undefined>;
override?: Promise<IEditor | null>;
}
export interface IVisibleEditor extends IEditor {
......
......@@ -446,7 +446,7 @@ export class ExtensionScannerInput {
constructor(
public readonly ourVersion: string,
public readonly commit: string | null | undefined,
public readonly commit: string | undefined,
public readonly locale: string | undefined,
public readonly devMode: boolean,
public readonly absoluteFolderPath: string,
......
......@@ -577,7 +577,7 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
let schemaId = 'vscode://schemas/keybindings';
let commandsSchemas: IJSONSchema[] = [];
let commandsEnum: string[] = [];
let commandsEnumDescriptions: (string | null | undefined)[] = [];
let commandsEnumDescriptions: (string | undefined)[] = [];
let schema: IJSONSchema = {
'id': schemaId,
'type': 'array',
......@@ -636,7 +636,7 @@ function updateSchema() {
commandsEnumDescriptions.length = 0;
const knownCommands = new Set<string>();
const addKnownCommand = (commandId: string, description?: string | null) => {
const addKnownCommand = (commandId: string, description?: string | undefined) => {
if (!/^_/.test(commandId)) {
if (!knownCommands.has(commandId)) {
knownCommands.add(commandId);
......@@ -655,7 +655,7 @@ function updateSchema() {
for (let commandId in allCommands) {
const commandDescription = allCommands[commandId].description;
addKnownCommand(commandId, commandDescription && commandDescription.description);
addKnownCommand(commandId, commandDescription ? commandDescription.description : undefined);
if (!commandDescription || !commandDescription.args || commandDescription.args.length !== 1 || !commandDescription.args[0].schema) {
continue;
......@@ -684,7 +684,6 @@ function updateSchema() {
for (let commandId in menuCommands) {
addKnownCommand(commandId);
}
}
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigExtensions.Configuration);
......
......@@ -104,11 +104,11 @@ class ResourceModelCollection extends ReferenceCollection<Promise<ITextEditorMod
private resolveTextModelContent(key: string): Promise<ITextModel> {
const resource = URI.parse(key);
const providers = this.providers[resource.scheme] || [];
const factories = providers.map(p => () => Promise.resolve<ITextModel | undefined | null>(p.provideTextContent(resource)));
const factories = providers.map(p => () => Promise.resolve(p.provideTextContent(resource)));
return first(factories).then(model => {
if (!model) {
return Promise.reject<any>(new Error('resource is not available'));
return Promise.reject(new Error('resource is not available'));
}
return model;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册