From 91a5666634aa588a3ada828bbf3294a175762f25 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 3 Aug 2021 12:30:38 -0700 Subject: [PATCH 1/2] Use the appropriate API to find out what terminal is being used --- news/2 Fixes/16577.md | 1 + .../shellDetectors/vscEnvironmentShellDetector.ts | 12 ++++++++---- .../shellDetectors/shellDetectors.unit.test.ts | 14 +++++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 news/2 Fixes/16577.md diff --git a/news/2 Fixes/16577.md b/news/2 Fixes/16577.md new file mode 100644 index 000000000000..a9bffb0fba86 --- /dev/null +++ b/news/2 Fixes/16577.md @@ -0,0 +1 @@ +Use the appropriate API to find out what terminal is being used. diff --git a/src/client/common/terminal/shellDetectors/vscEnvironmentShellDetector.ts b/src/client/common/terminal/shellDetectors/vscEnvironmentShellDetector.ts index 606919869a0d..c4aa5832d64c 100644 --- a/src/client/common/terminal/shellDetectors/vscEnvironmentShellDetector.ts +++ b/src/client/common/terminal/shellDetectors/vscEnvironmentShellDetector.ts @@ -23,13 +23,17 @@ export class VSCEnvironmentShellDetector extends BaseShellDetector { } public identify( telemetryProperties: ShellIdentificationTelemetry, - _terminal?: Terminal, + terminal?: Terminal, ): TerminalShellType | undefined { - if (!this.appEnv.shell) { + const shellPath = + terminal?.creationOptions && 'shellPath' in terminal.creationOptions && terminal.creationOptions.shellPath + ? terminal.creationOptions.shellPath + : this.appEnv.shell; + if (!shellPath) { return; } - const shell = this.identifyShellFromShellPath(this.appEnv.shell); - traceVerbose(`Terminal shell path '${this.appEnv.shell}' identified as shell '${shell}'`); + const shell = this.identifyShellFromShellPath(shellPath); + traceVerbose(`Terminal shell path '${shellPath}' identified as shell '${shell}'`); telemetryProperties.shellIdentificationSource = shell === TerminalShellType.other ? telemetryProperties.shellIdentificationSource : 'vscode'; return shell; diff --git a/src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts b/src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts index 37628cdab34a..087f1e676514 100644 --- a/src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts +++ b/src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts @@ -6,6 +6,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { instance, mock, when } from 'ts-mockito'; +import { Terminal } from 'vscode'; import { ApplicationEnvironment } from '../../../../client/common/application/applicationEnvironment'; import { WorkspaceService } from '../../../../client/common/application/workspace'; import { PlatformService } from '../../../../client/common/platform/platformService'; @@ -91,7 +92,18 @@ suite('Shell Detectors', () => { 'Should be undefined when there is no temrinal', ); }); - test('Identify shell based on VSC Environment', async () => { + test('Identify shell based on custom VSC shell path', async () => { + const shellDetector = new VSCEnvironmentShellDetector(instance(appEnv)); + shellPathsAndIdentification.forEach((shellType, shellPath) => { + when(appEnv.shell).thenReturn('defaultshellPath'); + expect( + shellDetector.identify(telemetryProperties, ({ + creationOptions: { shellPath }, + } as unknown) as Terminal), + ).to.equal(shellType, `Incorrect Shell Type from identifyShellByTerminalName, for path '${shellPath}'`); + }); + }); + test('Identify shell based on VSC API', async () => { const shellDetector = new VSCEnvironmentShellDetector(instance(appEnv)); shellPathsAndIdentification.forEach((shellType, shellPath) => { when(appEnv.shell).thenReturn(shellPath); From 778c4801407f385eee9c86654b3536bd9ee669eb Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 3 Aug 2021 12:31:43 -0700 Subject: [PATCH 2/2] News entry --- news/2 Fixes/16577.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/2 Fixes/16577.md b/news/2 Fixes/16577.md index a9bffb0fba86..350350bb29b3 100644 --- a/news/2 Fixes/16577.md +++ b/news/2 Fixes/16577.md @@ -1 +1 @@ -Use the appropriate API to find out what terminal is being used. +Use the vscode API appropriately to find out what terminal is being used.