Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/16577.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use the vscode API appropriately to find out what terminal is being used.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
terminal?.creationOptions && 'shellPath' in terminal.creationOptions && terminal.creationOptions.shellPath
terminal?.creationOptions && terminal.creationOptions.shellPath

Shouldn't that just work? if a field is not defined on an object, it is just returns undefined.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, atleast not for the type check compiler.

shellPath property doesn't exist on type of terminal.creationOptions (which is Readonly<TerminalOptions | ExtensionTerminalOptions>), so we have to narrow down the type first to Readonly<TerminalOptions> using this.

? 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down