44 *--------------------------------------------------------------------------------------------*/
55
66import { URI } from 'vs/base/common/uri' ;
7- import { sep , posix , normalize , win32 } from 'vs/base/common/path' ;
7+ import { posix , normalize , win32 , sep } from 'vs/base/common/path' ;
88import { endsWith , startsWithIgnoreCase , rtrim , startsWith } from 'vs/base/common/strings' ;
99import { Schemas } from 'vs/base/common/network' ;
1010import { isLinux , isWindows , isMacintosh } from 'vs/base/common/platform' ;
@@ -160,7 +160,7 @@ export function untildify(path: string, userHome: string): string {
160160const ellipsis = '\u2026' ;
161161const unc = '\\\\' ;
162162const home = '~' ;
163- export function shorten ( paths : string [ ] ) : string [ ] {
163+ export function shorten ( paths : string [ ] , pathSeparator : string = sep ) : string [ ] {
164164 const shortenedPaths : string [ ] = new Array ( paths . length ) ;
165165
166166 // for every path
@@ -169,7 +169,7 @@ export function shorten(paths: string[]): string[] {
169169 let path = paths [ pathIndex ] ;
170170
171171 if ( path === '' ) {
172- shortenedPaths [ pathIndex ] = `.${ sep } ` ;
172+ shortenedPaths [ pathIndex ] = `.${ pathSeparator } ` ;
173173 continue ;
174174 }
175175
@@ -185,20 +185,20 @@ export function shorten(paths: string[]): string[] {
185185 if ( path . indexOf ( unc ) === 0 ) {
186186 prefix = path . substr ( 0 , path . indexOf ( unc ) + unc . length ) ;
187187 path = path . substr ( path . indexOf ( unc ) + unc . length ) ;
188- } else if ( path . indexOf ( sep ) === 0 ) {
189- prefix = path . substr ( 0 , path . indexOf ( sep ) + sep . length ) ;
190- path = path . substr ( path . indexOf ( sep ) + sep . length ) ;
188+ } else if ( path . indexOf ( pathSeparator ) === 0 ) {
189+ prefix = path . substr ( 0 , path . indexOf ( pathSeparator ) + pathSeparator . length ) ;
190+ path = path . substr ( path . indexOf ( pathSeparator ) + pathSeparator . length ) ;
191191 } else if ( path . indexOf ( home ) === 0 ) {
192192 prefix = path . substr ( 0 , path . indexOf ( home ) + home . length ) ;
193193 path = path . substr ( path . indexOf ( home ) + home . length ) ;
194194 }
195195
196196 // pick the first shortest subpath found
197- const segments : string [ ] = path . split ( sep ) ;
197+ const segments : string [ ] = path . split ( pathSeparator ) ;
198198 for ( let subpathLength = 1 ; match && subpathLength <= segments . length ; subpathLength ++ ) {
199199 for ( let start = segments . length - subpathLength ; match && start >= 0 ; start -- ) {
200200 match = false ;
201- let subpath = segments . slice ( start , start + subpathLength ) . join ( sep ) ;
201+ let subpath = segments . slice ( start , start + subpathLength ) . join ( pathSeparator ) ;
202202
203203 // that is unique to any other path
204204 for ( let otherPathIndex = 0 ; ! match && otherPathIndex < paths . length ; otherPathIndex ++ ) {
@@ -209,7 +209,7 @@ export function shorten(paths: string[]): string[] {
209209
210210 // Adding separator as prefix for subpath, such that 'endsWith(src, trgt)' considers subpath as directory name instead of plain string.
211211 // prefix is not added when either subpath is root directory or path[otherPathIndex] does not have multiple directories.
212- const subpathWithSep : string = ( start > 0 && paths [ otherPathIndex ] . indexOf ( sep ) > - 1 ) ? sep + subpath : subpath ;
212+ const subpathWithSep : string = ( start > 0 && paths [ otherPathIndex ] . indexOf ( pathSeparator ) > - 1 ) ? pathSeparator + subpath : subpath ;
213213 const isOtherPathEnding : boolean = endsWith ( paths [ otherPathIndex ] , subpathWithSep ) ;
214214
215215 match = ! isSubpathEnding || isOtherPathEnding ;
@@ -226,26 +226,26 @@ export function shorten(paths: string[]): string[] {
226226 // extend subpath to include disk drive prefix
227227 start = 0 ;
228228 subpathLength ++ ;
229- subpath = segments [ 0 ] + sep + subpath ;
229+ subpath = segments [ 0 ] + pathSeparator + subpath ;
230230 }
231231
232232 if ( start > 0 ) {
233- result = segments [ 0 ] + sep ;
233+ result = segments [ 0 ] + pathSeparator ;
234234 }
235235
236236 result = prefix + result ;
237237 }
238238
239239 // add ellipsis at the beginning if neeeded
240240 if ( start > 0 ) {
241- result = result + ellipsis + sep ;
241+ result = result + ellipsis + pathSeparator ;
242242 }
243243
244244 result = result + subpath ;
245245
246246 // add ellipsis at the end if needed
247247 if ( start + subpathLength < segments . length ) {
248- result = result + sep + ellipsis ;
248+ result = result + pathSeparator + ellipsis ;
249249 }
250250
251251 shortenedPaths [ pathIndex ] = result ;
0 commit comments