Skip to content

Commit 3be4172

Browse files
author
Kartik Raj
committed
Do not show prompt for cmd
1 parent 30d2882 commit 3be4172

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

src/client/terminals/envCollectionActivation/deactivatePrompt.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
import { inject, injectable } from 'inversify';
55
import { Uri } from 'vscode';
6-
import { IApplicationShell } from '../../common/application/types';
6+
import { IApplicationEnvironment, IApplicationShell } from '../../common/application/types';
77
import { IBrowserService, IDisposableRegistry, IExperimentService, IPersistentStateFactory } from '../../common/types';
88
import { Common, Interpreters } from '../../common/utils/localize';
99
import { IExtensionSingleActivationService } from '../../activation/types';
1010
import { inTerminalEnvVarExperiment } from '../../common/experiments/helpers';
1111
import { IInterpreterService } from '../../interpreter/contracts';
1212
import { PythonEnvType } from '../../pythonEnvironments/base/info';
13+
import { identifyShellFromShellPath } from '../../common/terminal/shellDetectors/baseShellDetector';
14+
import { TerminalShellType } from '../../common/terminal/types';
1315

1416
export const terminalDeactivationPromptKey = 'TERMINAL_DEACTIVATION_PROMPT_KEY';
1517

@@ -23,6 +25,7 @@ export class TerminalDeactivateLimitationPrompt implements IExtensionSingleActiv
2325
@inject(IDisposableRegistry) private readonly disposableRegistry: IDisposableRegistry,
2426
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
2527
@inject(IBrowserService) private readonly browserService: IBrowserService,
28+
@inject(IApplicationEnvironment) private readonly appEnvironment: IApplicationEnvironment,
2629
@inject(IExperimentService) private readonly experimentService: IExperimentService,
2730
) {}
2831

@@ -35,6 +38,10 @@ export class TerminalDeactivateLimitationPrompt implements IExtensionSingleActiv
3538
if (!e.data.includes('deactivate')) {
3639
return;
3740
}
41+
const shellType = identifyShellFromShellPath(this.appEnvironment.shell);
42+
if (shellType === TerminalShellType.commandPrompt) {
43+
return;
44+
}
3845
const { terminal } = e;
3946
const cwd =
4047
'cwd' in terminal.creationOptions && terminal.creationOptions.cwd
@@ -59,12 +66,12 @@ export class TerminalDeactivateLimitationPrompt implements IExtensionSingleActiv
5966
return;
6067
}
6168
const prompts = [Common.seeInstructions, Common.doNotShowAgain];
62-
const selection = await this.appShell.showInformationMessage(Interpreters.terminalDeactivatePrompt, ...prompts);
69+
const selection = await this.appShell.showWarningMessage(Interpreters.terminalDeactivatePrompt, ...prompts);
6370
if (!selection) {
6471
return;
6572
}
6673
if (selection === prompts[0]) {
67-
const url = `https://aka.ms/AA5rjx5`;
74+
const url = `https://aka.ms/AAmx2ft`;
6875
this.browserService.launch(url);
6976
}
7077
if (selection === prompts[1]) {

src/test/terminals/envCollectionActivation/deactivatePrompt.unit.test.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { mock, when, anything, instance, verify, reset } from 'ts-mockito';
77
import { EventEmitter, Terminal, TerminalDataWriteEvent, Uri } from 'vscode';
8-
import { IApplicationShell } from '../../../client/common/application/types';
8+
import { IApplicationEnvironment, IApplicationShell } from '../../../client/common/application/types';
99
import {
1010
IBrowserService,
1111
IExperimentService,
@@ -19,11 +19,13 @@ import { IInterpreterService } from '../../../client/interpreter/contracts';
1919
import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
2020
import { TerminalDeactivateLimitationPrompt } from '../../../client/terminals/envCollectionActivation/deactivatePrompt';
2121
import { PythonEnvType } from '../../../client/pythonEnvironments/base/info';
22+
import { TerminalShellType } from '../../../client/common/terminal/types';
2223

2324
suite('Terminal Deactivation Limitation Prompt', () => {
2425
let shell: IApplicationShell;
2526
let experimentService: IExperimentService;
2627
let persistentStateFactory: IPersistentStateFactory;
28+
let appEnvironment: IApplicationEnvironment;
2729
let deactivatePrompt: TerminalDeactivateLimitationPrompt;
2830
let terminalWriteEvent: EventEmitter<TerminalDataWriteEvent>;
2931
let notificationEnabled: IPersistentState<boolean>;
@@ -37,6 +39,8 @@ suite('Terminal Deactivation Limitation Prompt', () => {
3739
interpreterService = mock<IInterpreterService>();
3840
experimentService = mock<IExperimentService>();
3941
persistentStateFactory = mock<IPersistentStateFactory>();
42+
appEnvironment = mock<IApplicationEnvironment>();
43+
when(appEnvironment.shell).thenReturn('bash');
4044
browserService = mock<IBrowserService>();
4145
notificationEnabled = mock<IPersistentState<boolean>>();
4246
terminalWriteEvent = new EventEmitter<TerminalDataWriteEvent>();
@@ -51,6 +55,7 @@ suite('Terminal Deactivation Limitation Prompt', () => {
5155
[],
5256
instance(interpreterService),
5357
instance(browserService),
58+
instance(appEnvironment),
5459
instance(experimentService),
5560
);
5661
});
@@ -66,13 +71,35 @@ suite('Terminal Deactivation Limitation Prompt', () => {
6671
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
6772
type: PythonEnvType.Virtual,
6873
} as unknown) as PythonEnvironment);
69-
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
74+
when(shell.showWarningMessage(expectedMessage, ...prompts)).thenResolve(undefined);
7075

7176
await deactivatePrompt.activate();
7277
terminalWriteEvent.fire({ data: 'Please deactivate me', terminal });
7378
await sleep(1);
7479

75-
verify(shell.showInformationMessage(expectedMessage, ...prompts)).once();
80+
verify(shell.showWarningMessage(expectedMessage, ...prompts)).once();
81+
});
82+
83+
test('When using cmd, do not show notification for the same', async () => {
84+
const resource = Uri.file('a');
85+
const terminal = ({
86+
creationOptions: {
87+
cwd: resource,
88+
},
89+
} as unknown) as Terminal;
90+
reset(appEnvironment);
91+
when(appEnvironment.shell).thenReturn(TerminalShellType.commandPrompt);
92+
when(notificationEnabled.value).thenReturn(true);
93+
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
94+
type: PythonEnvType.Virtual,
95+
} as unknown) as PythonEnvironment);
96+
when(shell.showWarningMessage(expectedMessage, ...prompts)).thenResolve(undefined);
97+
98+
await deactivatePrompt.activate();
99+
terminalWriteEvent.fire({ data: 'Please deactivate me', terminal });
100+
await sleep(1);
101+
102+
verify(shell.showWarningMessage(expectedMessage, ...prompts)).once();
76103
});
77104

78105
test('When not in experiment, do not show notification for the same', async () => {
@@ -88,13 +115,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
88115
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
89116
type: PythonEnvType.Virtual,
90117
} as unknown) as PythonEnvironment);
91-
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
118+
when(shell.showWarningMessage(expectedMessage, ...prompts)).thenResolve(undefined);
92119

93120
await deactivatePrompt.activate();
94121
terminalWriteEvent.fire({ data: 'Please deactivate me', terminal });
95122
await sleep(1);
96123

97-
verify(shell.showInformationMessage(expectedMessage, ...prompts)).never();
124+
verify(shell.showWarningMessage(expectedMessage, ...prompts)).never();
98125
});
99126

100127
test('Do not show notification if notification is disabled', async () => {
@@ -108,13 +135,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
108135
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
109136
type: PythonEnvType.Virtual,
110137
} as unknown) as PythonEnvironment);
111-
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
138+
when(shell.showWarningMessage(expectedMessage, ...prompts)).thenResolve(undefined);
112139

113140
await deactivatePrompt.activate();
114141
terminalWriteEvent.fire({ data: 'Please deactivate me', terminal });
115142
await sleep(1);
116143

117-
verify(shell.showInformationMessage(expectedMessage, ...prompts)).never();
144+
verify(shell.showWarningMessage(expectedMessage, ...prompts)).never();
118145
});
119146

120147
test('Do not show notification when virtual env is not activated for terminal', async () => {
@@ -128,13 +155,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
128155
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
129156
type: PythonEnvType.Conda,
130157
} as unknown) as PythonEnvironment);
131-
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
158+
when(shell.showWarningMessage(expectedMessage, ...prompts)).thenResolve(undefined);
132159

133160
await deactivatePrompt.activate();
134161
terminalWriteEvent.fire({ data: 'Please deactivate me', terminal });
135162
await sleep(1);
136163

137-
verify(shell.showInformationMessage(expectedMessage, ...prompts)).never();
164+
verify(shell.showWarningMessage(expectedMessage, ...prompts)).never();
138165
});
139166

140167
test("Disable notification if `Don't show again` is clicked", async () => {
@@ -148,9 +175,7 @@ suite('Terminal Deactivation Limitation Prompt', () => {
148175
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
149176
type: PythonEnvType.Virtual,
150177
} as unknown) as PythonEnvironment);
151-
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenReturn(
152-
Promise.resolve(Common.doNotShowAgain),
153-
);
178+
when(shell.showWarningMessage(expectedMessage, ...prompts)).thenReturn(Promise.resolve(Common.doNotShowAgain));
154179

155180
await deactivatePrompt.activate();
156181
terminalWriteEvent.fire({ data: 'Please deactivate me', terminal });
@@ -170,15 +195,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
170195
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
171196
type: PythonEnvType.Virtual,
172197
} as unknown) as PythonEnvironment);
173-
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenReturn(
174-
Promise.resolve(Common.seeInstructions),
175-
);
198+
when(shell.showWarningMessage(expectedMessage, ...prompts)).thenReturn(Promise.resolve(Common.seeInstructions));
176199

177200
await deactivatePrompt.activate();
178201
terminalWriteEvent.fire({ data: 'Please deactivate me', terminal });
179202
await sleep(1);
180203

181-
verify(shell.showInformationMessage(expectedMessage, ...prompts)).once();
204+
verify(shell.showWarningMessage(expectedMessage, ...prompts)).once();
182205
verify(browserService.launch(anything())).once();
183206
});
184207

@@ -193,13 +216,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
193216
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
194217
type: PythonEnvType.Virtual,
195218
} as unknown) as PythonEnvironment);
196-
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
219+
when(shell.showWarningMessage(expectedMessage, ...prompts)).thenResolve(undefined);
197220

198221
await deactivatePrompt.activate();
199222
terminalWriteEvent.fire({ data: 'Please deactivate me', terminal });
200223
await sleep(1);
201224

202-
verify(shell.showInformationMessage(expectedMessage, ...prompts)).once();
225+
verify(shell.showWarningMessage(expectedMessage, ...prompts)).once();
203226
verify(notificationEnabled.updateValue(false)).never();
204227
verify(browserService.launch(anything())).never();
205228
});

0 commit comments

Comments
 (0)