@@ -230,7 +230,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
230
230
lastWordFolder = lastWordFolder . replaceAll ( '/' , '\\' ) ;
231
231
}
232
232
233
- const lastWordFolderHasDotPrefix = lastWordFolder . match ( / ^ \. \. ? [ \\ \/ ] / ) ;
233
+ const lastWordFolderHasDotPrefix = ! ! lastWordFolder . match ( / ^ \. \. ? [ \\ \/ ] / ) ;
234
234
235
235
const lastWordFolderHasTildePrefix = lastWordFolder . match ( / ^ ~ [ \\ \/ ] / ) ;
236
236
if ( lastWordFolderHasTildePrefix ) {
@@ -330,8 +330,14 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
330
330
// `runOnEnter` is used.
331
331
// - `./src/|` -> `./src/`
332
332
if ( foldersRequested ) {
333
+ let label = '.' ;
334
+
335
+ if ( lastWordFolder . length > 0 ) {
336
+ label = addPathRelativePrefix ( lastWordFolder , resourceRequestConfig , lastWordFolderHasDotPrefix ) ;
337
+ }
338
+
333
339
resourceCompletions . push ( {
334
- label : lastWordFolder . length === 0 ? '.' : lastWordFolder ,
340
+ label,
335
341
provider,
336
342
kind : TerminalCompletionItemKind . Folder ,
337
343
detail : getFriendlyPath ( cwd , resourceRequestConfig . pathSeparator ) ,
@@ -357,14 +363,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
357
363
const isDirectory = kind === TerminalCompletionItemKind . Folder ;
358
364
const resourceName = basename ( stat . resource . fsPath ) ;
359
365
360
- let label = `${ lastWordFolder } ${ resourceName } ` ;
361
-
362
- // Normalize suggestion to add a ./ prefix to the start of the path if there isn't
363
- // one already. We may want to change this behavior in the future to go with
364
- // whatever format the user has
365
- if ( ! lastWordFolderHasDotPrefix ) {
366
- label = `.${ resourceRequestConfig . pathSeparator } ${ label } ` ;
367
- }
366
+ let label = addPathRelativePrefix ( `${ lastWordFolder } ${ resourceName } ` , resourceRequestConfig , lastWordFolderHasDotPrefix ) ;
368
367
369
368
// Ensure directories end with a path separator
370
369
if ( isDirectory && ! label . endsWith ( resourceRequestConfig . pathSeparator ) ) {
@@ -430,9 +429,13 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
430
429
// On Windows, the path seprators are normalized to `\`:
431
430
// - `./src/|` -> `.\src\..\`
432
431
if ( foldersRequested ) {
432
+ let label = `..${ resourceRequestConfig . pathSeparator } ` ;
433
+ if ( lastWordFolder . length > 0 ) {
434
+ label = addPathRelativePrefix ( lastWordFolder + label , resourceRequestConfig , lastWordFolderHasDotPrefix ) ;
435
+ }
433
436
const parentDir = URI . joinPath ( cwd , '..' + resourceRequestConfig . pathSeparator ) ;
434
437
resourceCompletions . push ( {
435
- label : lastWordFolder + '..' + resourceRequestConfig . pathSeparator ,
438
+ label,
436
439
provider,
437
440
kind : TerminalCompletionItemKind . Folder ,
438
441
detail : getFriendlyPath ( parentDir , resourceRequestConfig . pathSeparator ) ,
@@ -459,3 +462,14 @@ function getFriendlyPath(uri: URI, pathSeparator: string, kind?: TerminalComplet
459
462
}
460
463
return path ;
461
464
}
465
+
466
+ /**
467
+ * Normalize suggestion to add a ./ prefix to the start of the path if there isn't one already. We
468
+ * may want to change this behavior in the future to go with whatever format the user has.
469
+ */
470
+ function addPathRelativePrefix ( text : string , resourceRequestConfig : Pick < TerminalResourceRequestConfig , 'pathSeparator' > , lastWordFolderHasDotPrefix : boolean ) : string {
471
+ if ( ! lastWordFolderHasDotPrefix ) {
472
+ return `.${ resourceRequestConfig . pathSeparator } ${ text } ` ;
473
+ }
474
+ return text ;
475
+ }
0 commit comments