From 3af9e4568d09db59ce66501ad04661f25ae91eb4 Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 11 Oct 2018 17:43:09 +0200 Subject: [PATCH] labels: strict null checks --- src/tsconfig.strictNullChecks.json | 3 ++- src/vs/base/common/labels.ts | 42 ++++++++++++++++-------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index fc6894a77b1..b4161fb4057 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -58,6 +58,7 @@ "./vs/base/common/severity.ts", "./vs/base/common/stopwatch.ts", "./vs/base/common/strings.ts", + "./vs/base/common/labels.ts", "./vs/base/common/types.ts", "./vs/base/common/uri.ts", "./vs/base/common/uriIpc.ts", @@ -134,4 +135,4 @@ "exclude": [ "./typings/require-monaco.d.ts" ] -} \ No newline at end of file +} diff --git a/src/vs/base/common/labels.ts b/src/vs/base/common/labels.ts index 9310456816e..e171497848a 100644 --- a/src/vs/base/common/labels.ts +++ b/src/vs/base/common/labels.ts @@ -24,9 +24,9 @@ export interface IUserHomeProvider { /** * @deprecated use LabelService instead */ -export function getPathLabel(resource: URI | string, userHomeProvider: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string { +export function getPathLabel(resource: URI | string, userHomeProvider: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string | undefined { if (!resource) { - return null; + return undefined; } if (typeof resource === 'string') { @@ -34,23 +34,25 @@ export function getPathLabel(resource: URI | string, userHomeProvider: IUserHome } // return early if we can resolve a relative path label from the root - const baseResource = rootProvider ? rootProvider.getWorkspaceFolder(resource) : null; - if (baseResource) { - const hasMultipleRoots = rootProvider.getWorkspace().folders.length > 1; - - let pathLabel: string; - if (isEqual(baseResource.uri, resource, !isLinux)) { - pathLabel = ''; // no label if paths are identical - } else { - pathLabel = normalize(ltrim(resource.path.substr(baseResource.uri.path.length), sep), true); - } + if (rootProvider) { + const baseResource = rootProvider.getWorkspaceFolder(resource); + if (baseResource) { + const hasMultipleRoots = rootProvider.getWorkspace().folders.length > 1; + + let pathLabel: string; + if (isEqual(baseResource.uri, resource, !isLinux)) { + pathLabel = ''; // no label if paths are identical + } else { + pathLabel = normalize(ltrim(resource.path.substr(baseResource.uri.path.length), sep)!, true); + } - if (hasMultipleRoots) { - const rootName = (baseResource && baseResource.name) ? baseResource.name : pathsBasename(baseResource.uri.fsPath); - pathLabel = pathLabel ? (rootName + ' • ' + pathLabel) : rootName; // always show root basename if there are multiple - } + if (hasMultipleRoots) { + const rootName = (baseResource && baseResource.name) ? baseResource.name : pathsBasename(baseResource.uri.fsPath); + pathLabel = pathLabel ? (rootName + ' • ' + pathLabel) : rootName; // always show root basename if there are multiple + } - return pathLabel; + return pathLabel; + } } // return if the resource is neither file:// nor untitled:// and no baseResource was provided @@ -72,9 +74,9 @@ export function getPathLabel(resource: URI | string, userHomeProvider: IUserHome return res; } -export function getBaseLabel(resource: URI | string): string { +export function getBaseLabel(resource: URI | string): string | undefined { if (!resource) { - return null; + return undefined; } if (typeof resource === 'string') { @@ -92,7 +94,7 @@ export function getBaseLabel(resource: URI | string): string { } function hasDriveLetter(path: string): boolean { - return isWindows && path && path[1] === ':'; + return !!(isWindows && path && path[1] === ':'); } export function normalizeDriveLetter(path: string): string { -- GitLab