@@ -24,33 +24,35 @@ export interface IUserHomeProvider {
2424/**
2525 * @deprecated use LabelService instead
2626 */
27- export function getPathLabel ( resource : URI | string , userHomeProvider : IUserHomeProvider , rootProvider ?: IWorkspaceFolderProvider ) : string {
27+ export function getPathLabel ( resource : URI | string , userHomeProvider : IUserHomeProvider , rootProvider ?: IWorkspaceFolderProvider ) : string | undefined {
2828 if ( ! resource ) {
29- return null ;
29+ return undefined ;
3030 }
3131
3232 if ( typeof resource === 'string' ) {
3333 resource = URI . file ( resource ) ;
3434 }
3535
3636 // return early if we can resolve a relative path label from the root
37- const baseResource = rootProvider ? rootProvider . getWorkspaceFolder ( resource ) : null ;
38- if ( baseResource ) {
39- const hasMultipleRoots = rootProvider . getWorkspace ( ) . folders . length > 1 ;
40-
41- let pathLabel : string ;
42- if ( isEqual ( baseResource . uri , resource , ! isLinux ) ) {
43- pathLabel = '' ; // no label if paths are identical
44- } else {
45- pathLabel = normalize ( ltrim ( resource . path . substr ( baseResource . uri . path . length ) , sep ) , true ) ;
46- }
37+ if ( rootProvider ) {
38+ const baseResource = rootProvider . getWorkspaceFolder ( resource ) ;
39+ if ( baseResource ) {
40+ const hasMultipleRoots = rootProvider . getWorkspace ( ) . folders . length > 1 ;
41+
42+ let pathLabel : string ;
43+ if ( isEqual ( baseResource . uri , resource , ! isLinux ) ) {
44+ pathLabel = '' ; // no label if paths are identical
45+ } else {
46+ pathLabel = normalize ( ltrim ( resource . path . substr ( baseResource . uri . path . length ) , sep ) ! , true ) ;
47+ }
4748
48- if ( hasMultipleRoots ) {
49- const rootName = ( baseResource && baseResource . name ) ? baseResource . name : pathsBasename ( baseResource . uri . fsPath ) ;
50- pathLabel = pathLabel ? ( rootName + ' • ' + pathLabel ) : rootName ; // always show root basename if there are multiple
51- }
49+ if ( hasMultipleRoots ) {
50+ const rootName = ( baseResource && baseResource . name ) ? baseResource . name : pathsBasename ( baseResource . uri . fsPath ) ;
51+ pathLabel = pathLabel ? ( rootName + ' • ' + pathLabel ) : rootName ; // always show root basename if there are multiple
52+ }
5253
53- return pathLabel ;
54+ return pathLabel ;
55+ }
5456 }
5557
5658 // 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
7274 return res ;
7375}
7476
75- export function getBaseLabel ( resource : URI | string ) : string {
77+ export function getBaseLabel ( resource : URI | string ) : string | undefined {
7678 if ( ! resource ) {
77- return null ;
79+ return undefined ;
7880 }
7981
8082 if ( typeof resource === 'string' ) {
@@ -92,7 +94,7 @@ export function getBaseLabel(resource: URI | string): string {
9294}
9395
9496function hasDriveLetter ( path : string ) : boolean {
95- return isWindows && path && path [ 1 ] === ':' ;
97+ return ! ! ( isWindows && path && path [ 1 ] === ':' ) ;
9698}
9799
98100export function normalizeDriveLetter ( path : string ) : string {
0 commit comments