Skip to content

Commit 5070d30

Browse files
author
Kartik Raj
authored
Use VSCode API appropriately to find out what terminal is being used (#16858)
* Use the appropriate API to find out what terminal is being used * News entry
1 parent 57d8cf2 commit 5070d30

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

news/2 Fixes/16577.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use the vscode API appropriately to find out what terminal is being used.

src/client/common/terminal/shellDetectors/vscEnvironmentShellDetector.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ export class VSCEnvironmentShellDetector extends BaseShellDetector {
2323
}
2424
public identify(
2525
telemetryProperties: ShellIdentificationTelemetry,
26-
_terminal?: Terminal,
26+
terminal?: Terminal,
2727
): TerminalShellType | undefined {
28-
if (!this.appEnv.shell) {
28+
const shellPath =
29+
terminal?.creationOptions && 'shellPath' in terminal.creationOptions && terminal.creationOptions.shellPath
30+
? terminal.creationOptions.shellPath
31+
: this.appEnv.shell;
32+
if (!shellPath) {
2933
return;
3034
}
31-
const shell = this.identifyShellFromShellPath(this.appEnv.shell);
32-
traceVerbose(`Terminal shell path '${this.appEnv.shell}' identified as shell '${shell}'`);
35+
const shell = this.identifyShellFromShellPath(shellPath);
36+
traceVerbose(`Terminal shell path '${shellPath}' identified as shell '${shell}'`);
3337
telemetryProperties.shellIdentificationSource =
3438
shell === TerminalShellType.other ? telemetryProperties.shellIdentificationSource : 'vscode';
3539
return shell;

src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { expect } from 'chai';
77
import * as sinon from 'sinon';
88
import { instance, mock, when } from 'ts-mockito';
9+
import { Terminal } from 'vscode';
910
import { ApplicationEnvironment } from '../../../../client/common/application/applicationEnvironment';
1011
import { WorkspaceService } from '../../../../client/common/application/workspace';
1112
import { PlatformService } from '../../../../client/common/platform/platformService';
@@ -91,7 +92,18 @@ suite('Shell Detectors', () => {
9192
'Should be undefined when there is no temrinal',
9293
);
9394
});
94-
test('Identify shell based on VSC Environment', async () => {
95+
test('Identify shell based on custom VSC shell path', async () => {
96+
const shellDetector = new VSCEnvironmentShellDetector(instance(appEnv));
97+
shellPathsAndIdentification.forEach((shellType, shellPath) => {
98+
when(appEnv.shell).thenReturn('defaultshellPath');
99+
expect(
100+
shellDetector.identify(telemetryProperties, ({
101+
creationOptions: { shellPath },
102+
} as unknown) as Terminal),
103+
).to.equal(shellType, `Incorrect Shell Type from identifyShellByTerminalName, for path '${shellPath}'`);
104+
});
105+
});
106+
test('Identify shell based on VSC API', async () => {
95107
const shellDetector = new VSCEnvironmentShellDetector(instance(appEnv));
96108
shellPathsAndIdentification.forEach((shellType, shellPath) => {
97109
when(appEnv.shell).thenReturn(shellPath);

0 commit comments

Comments
 (0)