@@ -111,6 +111,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
111
111
private _screen ?: HTMLElement ;
112
112
private _suggestWidget ?: SimpleSuggestWidget ;
113
113
private _enableWidget : boolean = true ;
114
+ private _pathSeparator : string = sep ;
114
115
private _isFilteringDirectories : boolean = false ;
115
116
116
117
private _codeCompletionsRequested : boolean = false ;
@@ -271,7 +272,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
271
272
this . _cursorIndexDelta = this . _currentPromptInputState . cursorIndex - this . _initialPromptInputState . cursorIndex ;
272
273
let leadingLineContent = this . _leadingLineContent + this . _currentPromptInputState . value . substring ( this . _leadingLineContent . length , this . _leadingLineContent . length + this . _cursorIndexDelta ) ;
273
274
if ( this . _isFilteringDirectories ) {
274
- leadingLineContent = leadingLineContent . replaceAll ( '/' , '\\' ) ;
275
+ leadingLineContent = normalizePathSeparator ( leadingLineContent , this . _pathSeparator ) ;
275
276
}
276
277
const lineContext = new LineContext ( leadingLineContent , this . _cursorIndexDelta ) ;
277
278
this . _suggestWidget . setLineContext ( lineContext ) ;
@@ -353,9 +354,11 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
353
354
this . _cursorIndexDelta = 0 ;
354
355
355
356
let leadingLineContent = this . _leadingLineContent + this . _currentPromptInputState . value . substring ( this . _leadingLineContent . length , this . _leadingLineContent . length + this . _cursorIndexDelta ) ;
356
- this . _isFilteringDirectories = completions . every ( e => e . completion . isDirectory || e . completion . isFile ) ;
357
+ this . _isFilteringDirectories = completions . some ( e => e . completion . isDirectory ) && completions . every ( e => e . completion . isDirectory || e . completion . isFile ) ;
357
358
if ( this . _isFilteringDirectories ) {
358
- leadingLineContent = leadingLineContent . replaceAll ( '/' , '\\' ) ;
359
+ const firstDir = completions . find ( e => e . completion . isDirectory ) ;
360
+ this . _pathSeparator = firstDir ?. completion . label . match ( / (?< sep > [ \\ \/ ] ) / ) ?. groups ?. sep ?? sep ;
361
+ leadingLineContent = normalizePathSeparator ( leadingLineContent , this . _pathSeparator ) ;
359
362
}
360
363
const lineContext = new LineContext ( leadingLineContent , this . _cursorIndexDelta ) ;
361
364
const model = new SimpleCompletionModel ( completions , lineContext , replacementIndex , replacementLength ) ;
@@ -726,3 +729,10 @@ function getIcon(resultType: number, tooltip: string): ThemeIcon {
726
729
}
727
730
return pwshTypeToIconMap [ resultType ] ?? Codicon . symbolText ;
728
731
}
732
+
733
+ function normalizePathSeparator ( path : string , sep : string ) : string {
734
+ if ( sep === '/' ) {
735
+ return path . replaceAll ( '\\' , '/' ) ;
736
+ }
737
+ return path . replaceAll ( '/' , '\\' ) ;
738
+ }
0 commit comments