Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Check for hideFromUser before activating current terminal (#12942) (#…
…12956)

* Check for hideFromUser before activating current terminal

* Add tests

* Tweak logic
  • Loading branch information
karthiknadig authored Jul 14, 2020
commit 0ef5ed69d9b65e31efa1f6e276b78fb73429045a
1 change: 1 addition & 0 deletions news/2 Fixes/11122.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check for hideFromUser before activating current terminal.
8 changes: 5 additions & 3 deletions src/client/providers/terminalProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export class TerminalProvider implements Disposable {
const configuration = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource());

if (pythonSettings.terminal.activateEnvInCurrentTerminal) {
if (currentTerminal) {
if (currentTerminal && pythonSettings.terminal.activateEnvInCurrentTerminal) {
const hideFromUser =
'hideFromUser' in currentTerminal.creationOptions && currentTerminal.creationOptions.hideFromUser;
if (!hideFromUser) {
const terminalActivator = this.serviceContainer.get<ITerminalActivator>(ITerminalActivator);
await terminalActivator.activateEnvironmentInTerminal(currentTerminal, { preserveFocus: true });
}
sendTelemetryEvent(EventName.ACTIVATE_ENV_IN_CURRENT_TERMINAL, undefined, {
isTerminalVisible: currentTerminal ? true : false
isTerminalVisible: !hideFromUser
});
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/test/providers/terminal.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ suite('Terminal Provider', () => {
.returns(() => activeResourceService.object);

terminal = TypeMoq.Mock.ofType<Terminal>();
terminal
.setup((c) => c.creationOptions)
.returns(() => {
return { hideFromUser: false };
});
});

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

test('If terminal.activateCurrentTerminal setting is set, but hideFromUser is true, provided terminal should not be activated', async () => {
terminalSettings.setup((t) => t.activateEnvInCurrentTerminal).returns(() => true);
configService
.setup((c) => c.getSettings(resource))
.returns(() => pythonSettings.object)
.verifiable(TypeMoq.Times.once());
activeResourceService
.setup((a) => a.getActiveResource())
.returns(() => resource)
.verifiable(TypeMoq.Times.once());

terminal
.setup((c) => c.creationOptions)
.returns(() => {
return { hideFromUser: true };
});

terminalProvider = new TerminalProvider(serviceContainer.object);
await terminalProvider.initialize(terminal.object);

terminalActivator.verify(
(a) => a.activateEnvironmentInTerminal(TypeMoq.It.isAny(), TypeMoq.It.isAny()),
TypeMoq.Times.never()
);
activeResourceService.verifyAll();
configService.verifyAll();
});

test('terminal.activateCurrentTerminal setting is set but provided terminal is undefined', async () => {
terminalSettings.setup((t) => t.activateEnvInCurrentTerminal).returns(() => true);
configService
Expand Down