55'use strict' ;
66
77import URI from 'vs/base/common/uri' ;
8- import { nativeSep , normalize , basename as pathsBasename , join , sep } from 'vs/base/common/paths' ;
9- import { endsWith , ltrim , equalsIgnoreCase , startsWithIgnoreCase , rtrim , startsWith } from 'vs/base/common/strings' ;
8+ import { nativeSep , normalize , basename as pathsBasename , sep } from 'vs/base/common/paths' ;
9+ import { endsWith , ltrim , startsWithIgnoreCase , rtrim , startsWith } from 'vs/base/common/strings' ;
1010import { Schemas } from 'vs/base/common/network' ;
1111import { isLinux , isWindows , isMacintosh } from 'vs/base/common/platform' ;
12+ import { isEqual } from 'vs/base/common/resources' ;
1213
1314export interface IWorkspaceFolderProvider {
14- getWorkspaceFolder ( resource : URI ) : { uri : URI } ;
15+ getWorkspaceFolder ( resource : URI ) : { uri : URI , name ?: string } ;
1516 getWorkspace ( ) : {
16- folders : { uri : URI } [ ] ;
17+ folders : { uri : URI , name ?: string } [ ] ;
1718 } ;
1819}
1920
2021export interface IUserHomeProvider {
2122 userHome : string ;
2223}
2324
25+ /**
26+ * @param resource for which to compute the path label
27+ * @param userHomeProvider if a resource has a file schema userHomeProvider is used for tildifiying the label
28+ * @param rootProvider only passed in if the label should be relative to the workspace root
29+ */
2430export function getPathLabel ( resource : URI | string , userHomeProvider : IUserHomeProvider , rootProvider ?: IWorkspaceFolderProvider ) : string {
2531 if ( ! resource ) {
2632 return null ;
@@ -30,31 +36,31 @@ export function getPathLabel(resource: URI | string, userHomeProvider: IUserHome
3036 resource = URI . file ( resource ) ;
3137 }
3238
33- // return early if the resource is neither file:// nor untitled://
34- if ( resource . scheme !== Schemas . file && resource . scheme !== Schemas . untitled ) {
35- return resource . with ( { query : null , fragment : null } ) . toString ( true ) ;
36- }
37-
3839 // return early if we can resolve a relative path label from the root
3940 const baseResource = rootProvider ? rootProvider . getWorkspaceFolder ( resource ) : null ;
4041 if ( baseResource ) {
4142 const hasMultipleRoots = rootProvider . getWorkspace ( ) . folders . length > 1 ;
4243
4344 let pathLabel : string ;
44- if ( isLinux ? baseResource . uri . fsPath === resource . fsPath : equalsIgnoreCase ( baseResource . uri . fsPath , resource . fsPath ) ) {
45- pathLabel = '' ; // no label if pathes are identical
45+ if ( isEqual ( baseResource . uri , resource , ! isLinux ) ) {
46+ pathLabel = '' ; // no label if paths are identical
4647 } else {
47- pathLabel = normalize ( ltrim ( resource . fsPath . substr ( baseResource . uri . fsPath . length ) , nativeSep ) , true ) ;
48+ pathLabel = normalize ( ltrim ( resource . toString ( ) . substr ( baseResource . uri . toString ( ) . length ) , nativeSep ) , true ) ;
4849 }
4950
5051 if ( hasMultipleRoots ) {
51- const rootName = pathsBasename ( baseResource . uri . fsPath ) ;
52- pathLabel = pathLabel ? join ( rootName , pathLabel ) : rootName ; // always show root basename if there are multiple
52+ const rootName = ( baseResource && baseResource . name ) ? baseResource . name : pathsBasename ( baseResource . uri . fsPath ) ;
53+ pathLabel = pathLabel ? ( rootName + ' • ' + pathLabel ) : rootName ; // always show root basename if there are multiple
5354 }
5455
5556 return pathLabel ;
5657 }
5758
59+ // return if the resource is neither file:// nor untitled:// and no baseResource was provided
60+ if ( resource . scheme !== Schemas . file && resource . scheme !== Schemas . untitled ) {
61+ return resource . with ( { query : null , fragment : null } ) . toString ( true ) ;
62+ }
63+
5864 // convert c:\something => C:\something
5965 if ( hasDriveLetter ( resource . fsPath ) ) {
6066 return normalize ( normalizeDriveLetter ( resource . fsPath ) , true ) ;
0 commit comments