6
6
import { Emitter , Event } from 'vs/base/common/event' ;
7
7
import { ParsedPattern , parse as parseGlob } from 'vs/base/common/glob' ;
8
8
import { Disposable } from 'vs/base/common/lifecycle' ;
9
- import { isAbsolute , parse as parsePath , ParsedPath } from 'vs/base/common/path' ;
10
- import { dirname , relativePath as getRelativePath } from 'vs/base/common/resources' ;
9
+ import { isAbsolute , parse as parsePath , ParsedPath , dirname } from 'vs/base/common/path' ;
10
+ import { dirname as resourceDirname , relativePath as getRelativePath } from 'vs/base/common/resources' ;
11
11
import { URI } from 'vs/base/common/uri' ;
12
12
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
13
13
import { InstantiationType , registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
@@ -139,7 +139,7 @@ export class CustomEditorLabelService extends Disposable implements ICustomEdito
139
139
for ( const pattern of this . patterns ) {
140
140
let relevantPath : string ;
141
141
if ( root && ! pattern . isAbsolutePath ) {
142
- relevantPath = relativePath ?? getRelativePath ( dirname ( root . uri ) , resource ) ?? resource . path ;
142
+ relevantPath = relativePath ?? getRelativePath ( resourceDirname ( root . uri ) , resource ) ?? resource . path ;
143
143
} else {
144
144
relevantPath = resource . path ;
145
145
}
@@ -164,7 +164,7 @@ export class CustomEditorLabelService extends Disposable implements ICustomEdito
164
164
return parsedPath . ext . slice ( 1 ) ;
165
165
default : { // dirname and dirname(arg)
166
166
const n = variable === 'dirname' ? 0 : parseInt ( arg ) ;
167
- const nthDir = this . getNthDirname ( relevantPath , parsedPath . name , n ) ;
167
+ const nthDir = this . getNthDirname ( dirname ( relevantPath ) , n ) ;
168
168
if ( nthDir ) {
169
169
return nthDir ;
170
170
}
@@ -175,7 +175,7 @@ export class CustomEditorLabelService extends Disposable implements ICustomEdito
175
175
} ) ;
176
176
}
177
177
178
- private getNthDirname ( path : string , filename : string , n : number ) : string | undefined {
178
+ private getNthDirname ( path : string , n : number ) : string | undefined {
179
179
// grand-parent/parent/filename.ext1.ext2 -> [grand-parent, parent]
180
180
path = path . startsWith ( '/' ) ? path . slice ( 1 ) : path ;
181
181
const pathFragments = path . split ( '/' ) ;
@@ -189,7 +189,7 @@ export class CustomEditorLabelService extends Disposable implements ICustomEdito
189
189
nth = length - 1 - n - 1 ; // -1 for the filename, -1 for 0-based index
190
190
}
191
191
192
- const nthDir = nth === pathFragments . length - 1 ? filename : pathFragments [ nth ] ;
192
+ const nthDir = pathFragments [ nth ] ;
193
193
if ( nthDir === undefined || nthDir === '' ) {
194
194
return undefined ;
195
195
}
0 commit comments