33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import * as l10n from '@vscode/l10n' ;
67import { Event , ExtensionTerminalOptions , Terminal , TerminalExecutedCommand , TerminalOptions , TerminalShellExecutionEndEvent , TerminalShellIntegrationChangeEvent , window , type TerminalDataWriteEvent } from 'vscode' ;
8+ import { coalesce } from '../../../util/vs/base/common/arrays' ;
79import { Disposable } from '../../../util/vs/base/common/lifecycle' ;
810import * as path from '../../../util/vs/base/common/path' ;
911import { IVSCodeExtensionContext } from '../../extContext/common/extensionContext' ;
@@ -14,7 +16,7 @@ export class TerminalServiceImpl extends Disposable implements ITerminalService
1416
1517 declare readonly _serviceBrand : undefined ;
1618
17- private readonly pathContributions = new Map < string , { path : string ; description ?: string ; prepend : boolean } > ( ) ;
19+ private readonly pathContributions = new Map < string , { path : string ; description ?: string | { command : string } ; prepend : boolean } > ( ) ;
1820
1921 constructor (
2022 @IVSCodeExtensionContext private readonly context : IVSCodeExtensionContext ,
@@ -91,7 +93,7 @@ export class TerminalServiceImpl extends Disposable implements ITerminalService
9193 return getActiveTerminalShellType ( ) ;
9294 }
9395
94- contributePath ( contributor : string , pathLocation : string , description ?: string , prepend : boolean = false ) : void {
96+ contributePath ( contributor : string , pathLocation : string , description ?: string | { command : string } , prepend : boolean = false ) : void {
9597 this . pathContributions . set ( contributor , { path : pathLocation , description, prepend } ) ;
9698 this . updateEnvironmentPath ( ) ;
9799 }
@@ -113,12 +115,30 @@ export class TerminalServiceImpl extends Disposable implements ITerminalService
113115
114116
115117 // Build combined description
116- const allDescriptions = Array . from ( this . pathContributions . values ( ) )
117- . map ( c => c . description )
118- . filter ( d => d )
119- . join ( ' and ' ) ;
118+ const allDescriptions = coalesce ( Array . from ( this . pathContributions . values ( ) )
119+ . map ( c => c . description && typeof c . description === 'string' ? c . description : undefined )
120+ . filter ( d => d ) ) ;
121+ let descriptions = '' ;
122+ if ( allDescriptions . length === 1 ) {
123+ descriptions = allDescriptions [ 0 ] ;
124+ } else if ( allDescriptions . length > 1 ) {
125+ descriptions = `${ allDescriptions . slice ( 0 , - 1 ) . join ( ', ' ) } ${ l10n . t ( 'and' ) } ${ allDescriptions [ allDescriptions . length - 1 ] } ` ;
126+ }
127+
128+ const allCommands = coalesce ( Array . from ( this . pathContributions . values ( ) )
129+ . map ( c => ( c . description && typeof c . description !== 'string' ) ? `\`${ c . description . command } \`` : undefined )
130+ . filter ( d => d ) ) ;
131+
132+ let commandsDescription = '' ;
133+ if ( allCommands . length === 1 ) {
134+ commandsDescription = l10n . t ( 'Enables use of {0} command in the terminal' , allCommands [ 0 ] ) ;
135+ } else if ( allCommands . length > 1 ) {
136+ const commands = `${ allCommands . slice ( 0 , - 1 ) . join ( ', ' ) } ${ l10n . t ( 'and' ) } ${ allCommands [ allCommands . length - 1 ] } ` ;
137+ commandsDescription = l10n . t ( 'Enables use of {0} commands in the terminal' , commands ) ;
138+ }
120139
121- this . context . environmentVariableCollection . description = allDescriptions || 'Enables additional commands in the terminal.' ;
140+ const description = [ descriptions , commandsDescription ] . filter ( d => d ) . join ( ' and ' ) ;
141+ this . context . environmentVariableCollection . description = description || 'Enables additional commands in the terminal.' ;
122142
123143 // Build combined path from all contributions
124144 // Since we cannot mix and match append/prepend, if there are any prepend paths, then prepend everything.
0 commit comments