Skip to content

Commit 0ef5ed6

Browse files
authored
Check for hideFromUser before activating current terminal (#12942) (#12956)
* Check for hideFromUser before activating current terminal * Add tests * Tweak logic
1 parent ecc5c8e commit 0ef5ed6

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

news/2 Fixes/11122.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check for hideFromUser before activating current terminal.

src/client/providers/terminalProvider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ export class TerminalProvider implements Disposable {
2424
const configuration = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
2525
const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource());
2626

27-
if (pythonSettings.terminal.activateEnvInCurrentTerminal) {
28-
if (currentTerminal) {
27+
if (currentTerminal && pythonSettings.terminal.activateEnvInCurrentTerminal) {
28+
const hideFromUser =
29+
'hideFromUser' in currentTerminal.creationOptions && currentTerminal.creationOptions.hideFromUser;
30+
if (!hideFromUser) {
2931
const terminalActivator = this.serviceContainer.get<ITerminalActivator>(ITerminalActivator);
3032
await terminalActivator.activateEnvironmentInTerminal(currentTerminal, { preserveFocus: true });
3133
}
3234
sendTelemetryEvent(EventName.ACTIVATE_ENV_IN_CURRENT_TERMINAL, undefined, {
33-
isTerminalVisible: currentTerminal ? true : false
35+
isTerminalVisible: !hideFromUser
3436
});
3537
}
3638
}

src/test/providers/terminal.unit.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ suite('Terminal Provider', () => {
122122
.returns(() => activeResourceService.object);
123123

124124
terminal = TypeMoq.Mock.ofType<Terminal>();
125+
terminal
126+
.setup((c) => c.creationOptions)
127+
.returns(() => {
128+
return { hideFromUser: false };
129+
});
125130
});
126131

127132
test('If terminal.activateCurrentTerminal setting is set, provided terminal should be activated', async () => {
@@ -168,6 +173,34 @@ suite('Terminal Provider', () => {
168173
configService.verifyAll();
169174
});
170175

176+
test('If terminal.activateCurrentTerminal setting is set, but hideFromUser is true, provided terminal should not be activated', async () => {
177+
terminalSettings.setup((t) => t.activateEnvInCurrentTerminal).returns(() => true);
178+
configService
179+
.setup((c) => c.getSettings(resource))
180+
.returns(() => pythonSettings.object)
181+
.verifiable(TypeMoq.Times.once());
182+
activeResourceService
183+
.setup((a) => a.getActiveResource())
184+
.returns(() => resource)
185+
.verifiable(TypeMoq.Times.once());
186+
187+
terminal
188+
.setup((c) => c.creationOptions)
189+
.returns(() => {
190+
return { hideFromUser: true };
191+
});
192+
193+
terminalProvider = new TerminalProvider(serviceContainer.object);
194+
await terminalProvider.initialize(terminal.object);
195+
196+
terminalActivator.verify(
197+
(a) => a.activateEnvironmentInTerminal(TypeMoq.It.isAny(), TypeMoq.It.isAny()),
198+
TypeMoq.Times.never()
199+
);
200+
activeResourceService.verifyAll();
201+
configService.verifyAll();
202+
});
203+
171204
test('terminal.activateCurrentTerminal setting is set but provided terminal is undefined', async () => {
172205
terminalSettings.setup((t) => t.activateEnvInCurrentTerminal).returns(() => true);
173206
configService

0 commit comments

Comments
 (0)