Use undefined instead of null

This commit is contained in:
Matt Bierner
2018-12-07 12:32:00 -08:00
parent 3fc69f20ab
commit 98f236872e
6 changed files with 12 additions and 12 deletions

View File

@@ -158,7 +158,7 @@ class TscTaskProvider implements vscode.TaskProvider {
return undefined; return undefined;
} }
private getActiveTypeScriptFile(): string | null { private getActiveTypeScriptFile(): string | undefined {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
if (editor) { if (editor) {
const document = editor.document; const document = editor.document;
@@ -166,7 +166,7 @@ class TscTaskProvider implements vscode.TaskProvider {
return this.client.value.toPath(document.uri); return this.client.value.toPath(document.uri);
} }
} }
return null; return undefined;
} }
private async getTasksForProject(project: TSConfig): Promise<vscode.Task[]> { private async getTasksForProject(project: TSConfig): Promise<vscode.Task[]> {

View File

@@ -63,14 +63,14 @@ export interface ITypeScriptServiceClient {
* *
* Does not try handling case insensitivity. * Does not try handling case insensitivity.
*/ */
normalizedPath(resource: vscode.Uri): string | null; normalizedPath(resource: vscode.Uri): string | undefined;
/** /**
* Map a resource to a normalized path * Map a resource to a normalized path
* *
* This will attempt to handle case insensitivity. * This will attempt to handle case insensitivity.
*/ */
toPath(resource: vscode.Uri): string | null; toPath(resource: vscode.Uri): string | undefined;
/** /**
* Convert a path to a resource. * Convert a path to a resource.

View File

@@ -488,7 +488,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
} }
} }
public normalizedPath(resource: vscode.Uri): string | null { public normalizedPath(resource: vscode.Uri): string | undefined {
if (this._apiVersion.gte(API.v213)) { if (this._apiVersion.gte(API.v213)) {
if (resource.scheme === fileSchemes.walkThroughSnippet || resource.scheme === fileSchemes.untitled) { if (resource.scheme === fileSchemes.walkThroughSnippet || resource.scheme === fileSchemes.untitled) {
const dirName = path.dirname(resource.path); const dirName = path.dirname(resource.path);
@@ -498,19 +498,19 @@ export default class TypeScriptServiceClient extends Disposable implements IType
} }
if (resource.scheme !== fileSchemes.file) { if (resource.scheme !== fileSchemes.file) {
return null; return undefined;
} }
const result = resource.fsPath; const result = resource.fsPath;
if (!result) { if (!result) {
return null; return undefined;
} }
// Both \ and / must be escaped in regular expressions // Both \ and / must be escaped in regular expressions
return result.replace(new RegExp('\\' + this.pathSeparator, 'g'), '/'); return result.replace(new RegExp('\\' + this.pathSeparator, 'g'), '/');
} }
public toPath(resource: vscode.Uri): string | null { public toPath(resource: vscode.Uri): string | undefined {
return this.normalizedPath(resource); return this.normalizedPath(resource);
} }

View File

@@ -17,7 +17,7 @@ export default class ManagedFileContextManager {
private readonly onDidChangeActiveTextEditorSub: vscode.Disposable; private readonly onDidChangeActiveTextEditorSub: vscode.Disposable;
public constructor( public constructor(
private readonly normalizePath: (resource: vscode.Uri) => string | null private readonly normalizePath: (resource: vscode.Uri) => string | undefined
) { ) {
this.onDidChangeActiveTextEditorSub = vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this); this.onDidChangeActiveTextEditorSub = vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this);

View File

@@ -18,7 +18,7 @@ export class ResourceMap<T> {
private readonly _map = new Map<string, { resource: vscode.Uri, value: T }>(); private readonly _map = new Map<string, { resource: vscode.Uri, value: T }>();
constructor( constructor(
private readonly _normalizePath: (resource: vscode.Uri) => string | null = (resource) => resource.fsPath private readonly _normalizePath: (resource: vscode.Uri) => string | undefined = (resource) => resource.fsPath
) { } ) { }
public get size() { public get size() {
@@ -71,7 +71,7 @@ export class ResourceMap<T> {
return this._map.values(); return this._map.values();
} }
private toKey(resource: vscode.Uri): string | null { private toKey(resource: vscode.Uri): string | undefined {
const key = this._normalizePath(resource); const key = this._normalizePath(resource);
if (!key) { if (!key) {
return key; return key;

View File

@@ -12,7 +12,7 @@ export default class VersionStatus {
private readonly _versionBarEntry: vscode.StatusBarItem; private readonly _versionBarEntry: vscode.StatusBarItem;
constructor( constructor(
private readonly _normalizePath: (resource: vscode.Uri) => string | null private readonly _normalizePath: (resource: vscode.Uri) => string | undefined
) { ) {
this._versionBarEntry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 99 /* to the right of editor status (100) */); this._versionBarEntry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 99 /* to the right of editor status (100) */);
this._onChangeEditorSub = vscode.window.onDidChangeActiveTextEditor(this.showHideStatus, this); this._onChangeEditorSub = vscode.window.onDidChangeActiveTextEditor(this.showHideStatus, this);