@@ -27,6 +27,7 @@ import { getListStyles } from 'vs/platform/theme/browser/defaultStyles';
27
27
import type { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private' ;
28
28
import { terminalSuggestConfigSection , type ITerminalSuggestConfiguration } from 'vs/workbench/contrib/terminalContrib/suggest/common/terminalSuggestConfiguration' ;
29
29
import { commonPrefixLength } from 'vs/base/common/strings' ;
30
+ import { sep } from 'vs/base/common/path' ;
30
31
31
32
export const enum VSCodeSuggestOscPt {
32
33
Completions = 'Completions' ,
@@ -611,7 +612,7 @@ export function parseCompletionsFromShell(rawCompletions: PwshCompletion | PwshC
611
612
}
612
613
if ( ! Array . isArray ( rawCompletions ) ) {
613
614
return [ rawCompletions ] . map ( e => ( new SimpleCompletionItem ( {
614
- label :e . CompletionText ,
615
+ label :parseCompletionText ( e . CompletionText , e . ResultType ) ,
615
616
icon :pwshTypeToIconMap [ e . ResultType ] ,
616
617
detail :e . ToolTip ,
617
618
isFile :e . ResultType === 3 ,
@@ -622,24 +623,37 @@ export function parseCompletionsFromShell(rawCompletions: PwshCompletion | PwshC
622
623
}
623
624
if ( typeof rawCompletions [ 0 ] === 'string' ) {
624
625
return [ rawCompletions as CompressedPwshCompletion ] . map ( e => ( new SimpleCompletionItem ( {
625
- label :e [ 0 ] ,
626
+ label :parseCompletionText ( e [ 0 ] , e [ 1 ] ) ,
626
627
icon :pwshTypeToIconMap [ e [ 1 ] ] ,
627
628
detail :e [ 2 ] ,
628
629
isFile :e [ 1 ] === 3 ,
629
630
} ) ) ) ;
630
631
}
631
632
if ( Array . isArray ( rawCompletions [ 0 ] ) ) {
632
633
return ( rawCompletions as CompressedPwshCompletion [ ] ) . map ( e => ( new SimpleCompletionItem ( {
633
- label :e [ 0 ] ,
634
+ label :parseCompletionText ( e [ 0 ] , e [ 1 ] ) ,
634
635
icon :pwshTypeToIconMap [ e [ 1 ] ] ,
635
636
detail :e [ 2 ] ,
636
637
isFile :e [ 1 ] === 3 ,
637
638
} ) ) ) ;
638
639
}
639
640
return ( rawCompletions as PwshCompletion [ ] ) . map ( e => ( new SimpleCompletionItem ( {
640
- label :e . CompletionText ,
641
+ label :parseCompletionText ( e . CompletionText , e . ResultType ) ,
641
642
icon :pwshTypeToIconMap [ e . ResultType ] ,
642
643
detail :e . ToolTip ,
643
644
isFile :e . ResultType === 3 ,
644
645
} ) ) ) ;
645
646
}
647
+
648
+ function parseCompletionText ( completionText :string , resultType :number ) :string {
649
+ // HACK: Somewhere along the way from the powershell script to here, the path separator at the
650
+ // end of directories may go missing, likely because `\"` -> `"`. As a result, make sure there
651
+ // is a trailing separator at the end of all directory completions. This should not be done for
652
+ // `.` and `..` entries because they are optimized not for navigating to different directories
653
+ // but for passing as args.
654
+ if ( resultType === 4 && ! completionText . match ( / ^ \. \. ? $ / ) && ! completionText . match ( / [ \\ \/ ] $ / ) ) {
655
+ const separator = completionText . match ( / (?< sep > [ \\ \/ ] ) / ) ?. groups ?. sep ?? sep ;
656
+ return completionText + separator ;
657
+ }
658
+ return completionText ;
659
+ }