提交 3af9e456 编写于 作者: I isidor

labels: strict null checks

上级 3ba32665
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
"./vs/base/common/severity.ts", "./vs/base/common/severity.ts",
"./vs/base/common/stopwatch.ts", "./vs/base/common/stopwatch.ts",
"./vs/base/common/strings.ts", "./vs/base/common/strings.ts",
"./vs/base/common/labels.ts",
"./vs/base/common/types.ts", "./vs/base/common/types.ts",
"./vs/base/common/uri.ts", "./vs/base/common/uri.ts",
"./vs/base/common/uriIpc.ts", "./vs/base/common/uriIpc.ts",
...@@ -134,4 +135,4 @@ ...@@ -134,4 +135,4 @@
"exclude": [ "exclude": [
"./typings/require-monaco.d.ts" "./typings/require-monaco.d.ts"
] ]
} }
\ No newline at end of file
...@@ -24,9 +24,9 @@ export interface IUserHomeProvider { ...@@ -24,9 +24,9 @@ export interface IUserHomeProvider {
/** /**
* @deprecated use LabelService instead * @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) { if (!resource) {
return null; return undefined;
} }
if (typeof resource === 'string') { if (typeof resource === 'string') {
...@@ -34,23 +34,25 @@ export function getPathLabel(resource: URI | string, userHomeProvider: IUserHome ...@@ -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 // return early if we can resolve a relative path label from the root
const baseResource = rootProvider ? rootProvider.getWorkspaceFolder(resource) : null; if (rootProvider) {
if (baseResource) { const baseResource = rootProvider.getWorkspaceFolder(resource);
const hasMultipleRoots = rootProvider.getWorkspace().folders.length > 1; if (baseResource) {
const hasMultipleRoots = rootProvider.getWorkspace().folders.length > 1;
let pathLabel: string;
if (isEqual(baseResource.uri, resource, !isLinux)) { let pathLabel: string;
pathLabel = ''; // no label if paths are identical if (isEqual(baseResource.uri, resource, !isLinux)) {
} else { pathLabel = ''; // no label if paths are identical
pathLabel = normalize(ltrim(resource.path.substr(baseResource.uri.path.length), sep), true); } else {
} pathLabel = normalize(ltrim(resource.path.substr(baseResource.uri.path.length), sep)!, true);
}
if (hasMultipleRoots) { if (hasMultipleRoots) {
const rootName = (baseResource && baseResource.name) ? baseResource.name : pathsBasename(baseResource.uri.fsPath); const rootName = (baseResource && baseResource.name) ? baseResource.name : pathsBasename(baseResource.uri.fsPath);
pathLabel = pathLabel ? (rootName + '' + pathLabel) : rootName; // always show root basename if there are multiple 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 // 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 ...@@ -72,9 +74,9 @@ export function getPathLabel(resource: URI | string, userHomeProvider: IUserHome
return res; return res;
} }
export function getBaseLabel(resource: URI | string): string { export function getBaseLabel(resource: URI | string): string | undefined {
if (!resource) { if (!resource) {
return null; return undefined;
} }
if (typeof resource === 'string') { if (typeof resource === 'string') {
...@@ -92,7 +94,7 @@ export function getBaseLabel(resource: URI | string): string { ...@@ -92,7 +94,7 @@ export function getBaseLabel(resource: URI | string): string {
} }
function hasDriveLetter(path: string): boolean { function hasDriveLetter(path: string): boolean {
return isWindows && path && path[1] === ':'; return !!(isWindows && path && path[1] === ':');
} }
export function normalizeDriveLetter(path: string): string { export function normalizeDriveLetter(path: string): string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册