@@ -11,12 +11,13 @@ import { IConfigurationService } from '../../../../../platform/configuration/com
11
11
import { IFileService } from '../../../../../platform/files/common/files.js' ;
12
12
import { createDecorator } from '../../../../../platform/instantiation/common/instantiation.js' ;
13
13
import { TerminalCapability , type ITerminalCapabilityStore } from '../../../../../platform/terminal/common/capabilities/capabilities.js' ;
14
- import { GeneralShellType , TerminalShellType } from '../../../../../platform/terminal/common/terminal.js' ;
14
+ import { GeneralShellType , TerminalShellType , WindowsShellType } from '../../../../../platform/terminal/common/terminal.js' ;
15
15
import { TerminalSuggestSettingId } from '../common/terminalSuggestConfiguration.js' ;
16
16
import { TerminalCompletionItemKind , type ITerminalCompletion } from './terminalCompletionItem.js' ;
17
17
import { env as processEnv } from '../../../../../base/common/process.js' ;
18
18
import type { IProcessEnvironment } from '../../../../../base/common/platform.js' ;
19
19
import { timeout } from '../../../../../base/common/async.js' ;
20
+ import { gitBashPathToWindows } from './terminalGitBashHelpers.js' ;
20
21
21
22
export const ITerminalCompletionService = createDecorator < ITerminalCompletionService > ( 'terminalCompletionService' ) ;
22
23
@@ -190,7 +191,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
190
191
return completionItems ;
191
192
}
192
193
if ( completions . resourceRequestConfig ) {
193
- const resourceCompletions = await this . resolveResources ( completions . resourceRequestConfig , promptValue , cursorPosition , provider . id , capabilities ) ;
194
+ const resourceCompletions = await this . resolveResources ( completions . resourceRequestConfig , promptValue , cursorPosition , provider . id , capabilities , shellType ) ;
194
195
if ( resourceCompletions ) {
195
196
completionItems . push ( ...resourceCompletions ) ;
196
197
}
@@ -202,7 +203,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
202
203
return results . filter ( result => ! ! result ) . flat ( ) ;
203
204
}
204
205
205
- async resolveResources ( resourceRequestConfig : TerminalResourceRequestConfig , promptValue : string , cursorPosition : number , provider : string , capabilities : ITerminalCapabilityStore ) : Promise < ITerminalCompletion [ ] | undefined > {
206
+ async resolveResources ( resourceRequestConfig : TerminalResourceRequestConfig , promptValue : string , cursorPosition : number , provider : string , capabilities : ITerminalCapabilityStore , shellType ?: TerminalShellType ) : Promise < ITerminalCompletion [ ] | undefined > {
206
207
const useWindowsStylePath = resourceRequestConfig . pathSeparator === '\\' ;
207
208
if ( useWindowsStylePath ) {
208
209
// for tests, make sure the right path separator is used
@@ -280,7 +281,11 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
280
281
break ;
281
282
}
282
283
case 'absolute' : {
283
- lastWordFolderResource = URI . file ( lastWordFolder . replaceAll ( '\\ ' , ' ' ) ) ;
284
+ if ( shellType === WindowsShellType . GitBash ) {
285
+ lastWordFolderResource = URI . file ( gitBashPathToWindows ( lastWordFolder , this . _processEnv . SystemDrive ) ) ;
286
+ } else {
287
+ lastWordFolderResource = URI . file ( lastWordFolder . replaceAll ( '\\ ' , ' ' ) ) ;
288
+ }
284
289
break ;
285
290
}
286
291
case 'relative' : {
@@ -349,7 +354,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
349
354
label,
350
355
provider,
351
356
kind : TerminalCompletionItemKind . Folder ,
352
- detail : getFriendlyPath ( lastWordFolderResource , resourceRequestConfig . pathSeparator , TerminalCompletionItemKind . Folder ) ,
357
+ detail : getFriendlyPath ( lastWordFolderResource , resourceRequestConfig . pathSeparator , TerminalCompletionItemKind . Folder , shellType ) ,
353
358
replacementIndex : cursorPosition - lastWord . length ,
354
359
replacementLength : lastWord . length
355
360
} ) ;
@@ -394,7 +399,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
394
399
label,
395
400
provider,
396
401
kind,
397
- detail : getFriendlyPath ( child . resource , resourceRequestConfig . pathSeparator , kind ) ,
402
+ detail : getFriendlyPath ( child . resource , resourceRequestConfig . pathSeparator , kind , shellType ) ,
398
403
replacementIndex : cursorPosition - lastWord . length ,
399
404
replacementLength : lastWord . length
400
405
} ) ;
@@ -420,8 +425,8 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
420
425
}
421
426
const useRelative = config === 'relative' ;
422
427
const kind = TerminalCompletionItemKind . Folder ;
423
- const label = useRelative ? basename ( child . resource . fsPath ) : getFriendlyPath ( child . resource , resourceRequestConfig . pathSeparator , kind ) ;
424
- const detail = useRelative ? `CDPATH ${ getFriendlyPath ( child . resource , resourceRequestConfig . pathSeparator , kind ) } ` : `CDPATH` ;
428
+ const label = useRelative ? basename ( child . resource . fsPath ) : getFriendlyPath ( child . resource , resourceRequestConfig . pathSeparator , kind , shellType ) ;
429
+ const detail = useRelative ? `CDPATH ${ getFriendlyPath ( child . resource , resourceRequestConfig . pathSeparator , kind , shellType ) } ` : `CDPATH` ;
425
430
resourceCompletions . push ( {
426
431
label,
427
432
provider,
@@ -453,7 +458,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
453
458
label,
454
459
provider,
455
460
kind : TerminalCompletionItemKind . Folder ,
456
- detail : getFriendlyPath ( parentDir , resourceRequestConfig . pathSeparator , TerminalCompletionItemKind . Folder ) ,
461
+ detail : getFriendlyPath ( parentDir , resourceRequestConfig . pathSeparator , TerminalCompletionItemKind . Folder , shellType ) ,
457
462
replacementIndex : cursorPosition - lastWord . length ,
458
463
replacementLength : lastWord . length
459
464
} ) ;
@@ -478,7 +483,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
478
483
label : '~' ,
479
484
provider,
480
485
kind : TerminalCompletionItemKind . Folder ,
481
- detail : typeof homeResource === 'string' ? homeResource : getFriendlyPath ( homeResource , resourceRequestConfig . pathSeparator , TerminalCompletionItemKind . Folder ) ,
486
+ detail : typeof homeResource === 'string' ? homeResource : getFriendlyPath ( homeResource , resourceRequestConfig . pathSeparator , TerminalCompletionItemKind . Folder , shellType ) ,
482
487
replacementIndex : cursorPosition - lastWord . length ,
483
488
replacementLength : lastWord . length
484
489
} ) ;
@@ -500,14 +505,15 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
500
505
}
501
506
}
502
507
503
- function getFriendlyPath ( uri : URI , pathSeparator : string , kind : TerminalCompletionItemKind ) : string {
508
+ function getFriendlyPath ( uri : URI , pathSeparator : string , kind : TerminalCompletionItemKind , shellType ?: TerminalShellType ) : string {
504
509
let path = uri . fsPath ;
510
+ const sep = shellType === WindowsShellType . GitBash ? '\\' : pathSeparator ;
505
511
// Ensure folders end with the path separator to differentiate presentation from files
506
- if ( kind === TerminalCompletionItemKind . Folder && ! path . endsWith ( pathSeparator ) ) {
507
- path += pathSeparator ;
512
+ if ( kind === TerminalCompletionItemKind . Folder && ! path . endsWith ( sep ) ) {
513
+ path += sep ;
508
514
}
509
515
// Ensure drive is capitalized on Windows
510
- if ( pathSeparator === '\\' && path . match ( / ^ [ a - z A - Z ] : \\ / ) ) {
516
+ if ( sep === '\\' && path . match ( / ^ [ a - z A - Z ] : \\ / ) ) {
511
517
path = `${ path [ 0 ] . toUpperCase ( ) } :${ path . slice ( 2 ) } ` ;
512
518
}
513
519
return path ;
0 commit comments