@@ -14,6 +14,7 @@ import { TerminalCapability, type ITerminalCapabilityStore } from '../../../../.
14
14
import { GeneralShellType , TerminalShellType } from '../../../../../platform/terminal/common/terminal.js' ;
15
15
import { TerminalSuggestSettingId } from '../common/terminalSuggestConfiguration.js' ;
16
16
import { TerminalCompletionItemKind , type ITerminalCompletion } from './terminalCompletionItem.js' ;
17
+ import { env as processEnv } from '../../../../../base/common/process.js' ;
17
18
18
19
export const ITerminalCompletionService = createDecorator < ITerminalCompletionService > ( 'terminalCompletionService' ) ;
19
20
@@ -87,6 +88,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
87
88
88
89
constructor (
89
90
@IConfigurationService private readonly _configurationService : IConfigurationService ,
91
+
90
92
@IFileService private readonly _fileService : IFileService
91
93
) {
92
94
super ( ) ;
@@ -251,13 +253,9 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
251
253
const type = lastWordFolderHasTildePrefix ? 'tilde' : isAbsolutePath ? 'absolute' : 'relative' ;
252
254
switch ( type ) {
253
255
case 'tilde' : {
254
- const env = capabilities . get ( TerminalCapability . ShellEnvDetection ) ?. env ;
255
- if ( env ) {
256
- const home = useWindowsStylePath ? env . get ( 'USERPROFILE' ) : env . get ( 'HOME' ) ;
257
- // TODO: Handle the case where the HOME environment variable is not set
258
- if ( home ) {
259
- lastWordFolderResource = URI . joinPath ( URI . file ( home ) , lastWordFolder . slice ( 1 ) . replaceAll ( '\\ ' , ' ' ) ) ;
260
- }
256
+ const home = getHomeDir ( useWindowsStylePath , capabilities ) ;
257
+ if ( home ) {
258
+ lastWordFolderResource = URI . joinPath ( URI . file ( home ) , lastWordFolder . slice ( 1 ) . replaceAll ( '\\ ' , ' ' ) ) ;
261
259
}
262
260
if ( ! lastWordFolderResource ) {
263
261
// Use less strong wording here as it's not as strong of a concept on Windows
@@ -389,7 +387,7 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
389
387
if ( promptValue . startsWith ( 'cd ' ) ) {
390
388
const config = this . _configurationService . getValue ( TerminalSuggestSettingId . CdPath ) ;
391
389
if ( config === 'absolute' || config === 'relative' ) {
392
- const cdPath = capabilities . get ( TerminalCapability . ShellEnvDetection ) ?. env ?. get ( 'CDPATH' ) ;
390
+ const cdPath = getEnvVar ( 'CDPATH' , capabilities ) ;
393
391
if ( cdPath ) {
394
392
const cdPathEntries = cdPath . split ( useWindowsStylePath ? ';' : ':' ) ;
395
393
for ( const cdPathEntry of cdPathEntries ) {
@@ -446,14 +444,10 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
446
444
//
447
445
// - (relative) `|` -> `~`
448
446
if ( type === 'relative' && ! lastWordFolder . match ( / [ \\ \/ ] / ) ) {
449
- const env = capabilities . get ( TerminalCapability . ShellEnvDetection ) ?. env ;
450
447
let homeResource : URI | string | undefined ;
451
- if ( env ) {
452
- const home = useWindowsStylePath ? env . get ( 'USERPROFILE' ) : env . get ( 'HOME' ) ;
453
- // TODO: Handle the case where the HOME environment variable is not set
454
- if ( home ) {
455
- homeResource = URI . joinPath ( URI . file ( home ) , lastWordFolder . slice ( 1 ) . replaceAll ( '\\ ' , ' ' ) ) ;
456
- }
448
+ const home = getHomeDir ( useWindowsStylePath , capabilities ) ;
449
+ if ( home ) {
450
+ homeResource = URI . joinPath ( URI . file ( home ) , lastWordFolder . slice ( 1 ) . replaceAll ( '\\ ' , ' ' ) ) ;
457
451
}
458
452
if ( ! homeResource ) {
459
453
// Use less strong wording here as it's not as strong of a concept on Windows
@@ -474,6 +468,18 @@ export class TerminalCompletionService extends Disposable implements ITerminalCo
474
468
}
475
469
}
476
470
471
+ function getEnvVar ( key : string , capabilities : ITerminalCapabilityStore ) : string | undefined {
472
+ const env = capabilities . get ( TerminalCapability . ShellEnvDetection ) ?. env ;
473
+ if ( env ) {
474
+ return env . get ( key ) ;
475
+ }
476
+ return processEnv [ key ] ;
477
+ }
478
+
479
+ function getHomeDir ( useWindowsStylePath : boolean , capabilities : ITerminalCapabilityStore ) : string | undefined {
480
+ return useWindowsStylePath ? getEnvVar ( 'USERPROFILE' , capabilities ) : getEnvVar ( 'HOME' , capabilities ) ;
481
+ }
482
+
477
483
function getFriendlyPath ( uri : URI , pathSeparator : string , kind : TerminalCompletionItemKind ) : string {
478
484
let path = uri . fsPath ;
479
485
// Ensure folders end with the path separator to differentiate presentation from files
0 commit comments