Skip to content

Commit 4b36c53

Browse files
authored
Unify terminal contribution descriptions for contributd terminal commands (#1716)
1 parent 5aafc56 commit 4b36c53

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

src/extension/chatSessions/vscode-node/copilotCLITerminalIntegration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class CopilotCLITerminalIntegration extends Disposable implements ICopilo
7070
}
7171

7272
const storageLocation = path.join(globalStorageUri.fsPath, 'copilotCli');
73-
this.terminalService.contributePath('copilot-cli', storageLocation, 'Enables use of the `copilot` command in the terminal.', true);
73+
this.terminalService.contributePath('copilot-cli', storageLocation, { command: COPILOT_CLI_COMMAND }, true);
7474

7575
await fs.mkdir(storageLocation, { recursive: true });
7676

src/extension/onboardDebug/vscode-node/copilotDebugCommandContribution.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ export class CopilotDebugCommandContribution extends Disposable implements vscod
254254
} else if (!previouslyStoredAt) {
255255
// 2. enabling a disabled state
256256
await this.fillStoragePath(storageLocation);
257-
this.terminalService.contributePath('copilot-debug', storageLocation, `Enables use of the \`${COPILOT_DEBUG_COMMAND}\` command in the terminal.`);
257+
this.terminalService.contributePath('copilot-debug', storageLocation, { command: COPILOT_DEBUG_COMMAND });
258258
} else if (previouslyStoredAt.version !== versionNonce) {
259259
// 3. upgrading the worker
260260
await this.fillStoragePath(storageLocation);
261-
this.terminalService.contributePath('copilot-debug', storageLocation, `Enables use of the \`${COPILOT_DEBUG_COMMAND}\` command in the terminal.`);
261+
this.terminalService.contributePath('copilot-debug', storageLocation, { command: COPILOT_DEBUG_COMMAND });
262262
} else if (enabled) {
263263
// 4. already enabled and up to date, just ensure PATH contribution
264-
this.terminalService.contributePath('copilot-debug', storageLocation, `Enables use of the \`${COPILOT_DEBUG_COMMAND}\` command in the terminal.`);
264+
this.terminalService.contributePath('copilot-debug', storageLocation, { command: COPILOT_DEBUG_COMMAND });
265265
}
266266

267267
this.context.globalState.update(WAS_REGISTERED_STORAGE_KEY, enabled ? {

src/platform/terminal/common/terminalService.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ export interface ITerminalService {
5858
* @param pathLocation The path to add to PATH
5959
* @param description Optional description for the PATH contribution
6060
* @param prepend Whether to prepend (true) or append (false) the path. Defaults to false (append).
61-
*/
61+
*/
6262
contributePath(contributor: string, pathLocation: string, description?: string, prepend?: boolean): void;
63+
/**
64+
* Contributes a path to the terminal PATH environment variable.
65+
* @param contributor Unique identifier for the contributor
66+
* @param pathLocation The path to add to PATH
67+
* @param description Optional command thats contributed in the Terminal.
68+
* @param prepend Whether to prepend (true) or append (false) the path. Defaults to false (append).
69+
*/
70+
contributePath(contributor: string, pathLocation: string, description?: { command: string }, prepend?: boolean): void;
6371

6472
/**
6573
* Removes a path contribution from the terminal PATH environment variable.
@@ -150,10 +158,13 @@ export class NullTerminalService extends Disposable implements ITerminalService
150158
return undefined;
151159
}
152160

153-
contributePath(contributor: string, pathLocation: string, description?: string): void {
161+
contributePath(contributor: string, pathLocation: string, description?: string, prepend?: boolean): void;
162+
contributePath(contributor: string, pathLocation: string, description?: { command: string }, prepend?: boolean): void;
163+
contributePath(contributor: unknown, pathLocation: unknown, description?: unknown, prepend?: unknown): void {
154164
// No-op for null service
155165
}
156166

167+
157168
removePathContribution(contributor: string): void {
158169
// No-op for null service
159170
}

src/platform/terminal/vscode/terminalServiceImpl.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
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';
67
import { Event, ExtensionTerminalOptions, Terminal, TerminalExecutedCommand, TerminalOptions, TerminalShellExecutionEndEvent, TerminalShellIntegrationChangeEvent, window, type TerminalDataWriteEvent } from 'vscode';
8+
import { coalesce } from '../../../util/vs/base/common/arrays';
79
import { Disposable } from '../../../util/vs/base/common/lifecycle';
810
import * as path from '../../../util/vs/base/common/path';
911
import { 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.

src/platform/test/node/simulationWorkspaceServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ export class TestingTerminalService extends Disposable implements ITerminalServi
838838
getBufferWithPid(pid: number, maxChars?: number): Promise<string> {
839839
throw new Error('Method not implemented.');
840840
}
841-
contributePath(contributor: string, pathLocation: string, description?: string): void {
841+
contributePath(contributor: string, pathLocation: string, description?: string | { command: string }): void {
842842
// No-op for test service
843843
}
844844
removePathContribution(contributor: string): void {

0 commit comments

Comments
 (0)