Skip to content

Commit 5ba3d88

Browse files
Kartik Rajwesm
Kartik Raj
authored andcommitted
Do not show inherit env prompt for conda envs when running "remotely" (microsoft/vscode-python#18922)
1 parent 0ae47d2 commit 5ba3d88

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not show inherit env prompt for conda envs when running "remotely".

extensions/positron-python/src/client/common/application/applicationEnvironment.ts

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export class ApplicationEnvironment implements IApplicationEnvironment {
6464
public get machineId(): string {
6565
return vscode.env.machineId;
6666
}
67+
public get remoteName(): string | undefined {
68+
return vscode.env.remoteName;
69+
}
6770
public get extensionName(): string {
6871
return this.packageJson.displayName;
6972
}

extensions/positron-python/src/client/common/application/types.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,16 @@ export interface IApplicationEnvironment {
10721072
* from a desktop application or a web browser.
10731073
*/
10741074
readonly uiKind: UIKind;
1075+
/**
1076+
* The name of a remote. Defined by extensions, popular samples are `wsl` for the Windows
1077+
* Subsystem for Linux or `ssh-remote` for remotes using a secure shell.
1078+
*
1079+
* *Note* that the value is `undefined` when there is no remote extension host but that the
1080+
* value is defined in all extension hosts (local and remote) in case a remote extension host
1081+
* exists. Use {@link Extension.extensionKind} to know if
1082+
* a specific extension runs remote or not.
1083+
*/
1084+
readonly remoteName: string | undefined;
10751085
}
10761086

10771087
export const ILanguageService = Symbol('ILanguageService');

extensions/positron-python/src/client/interpreter/virtualEnvs/condaInheritEnvPrompt.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { inject, injectable, optional } from 'inversify';
55
import { ConfigurationTarget, Uri } from 'vscode';
66
import { IExtensionActivationService } from '../../activation/types';
7-
import { IApplicationShell, IWorkspaceService } from '../../common/application/types';
7+
import { IApplicationEnvironment, IApplicationShell, IWorkspaceService } from '../../common/application/types';
88
import { IPlatformService } from '../../common/platform/types';
99
import { IBrowserService, IPersistentStateFactory } from '../../common/types';
1010
import { Common, Interpreters } from '../../common/utils/localize';
@@ -26,6 +26,7 @@ export class CondaInheritEnvPrompt implements IExtensionActivationService {
2626
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
2727
@inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory,
2828
@inject(IPlatformService) private readonly platformService: IPlatformService,
29+
@inject(IApplicationEnvironment) private readonly appEnvironment: IApplicationEnvironment,
2930
@optional() public hasPromptBeenShownInCurrentSession: boolean = false,
3031
) {}
3132

@@ -76,6 +77,11 @@ export class CondaInheritEnvPrompt implements IExtensionActivationService {
7677
if (this.hasPromptBeenShownInCurrentSession) {
7778
return false;
7879
}
80+
if (this.appEnvironment.remoteName) {
81+
// `terminal.integrated.inheritEnv` is only applicable user scope, so won't apply
82+
// in remote scenarios: https://github.com/microsoft/vscode/issues/147421
83+
return false;
84+
}
7985
if (this.platformService.isWindows) {
8086
return false;
8187
}

extensions/positron-python/src/test/interpreters/virtualEnvs/condaInheritEnvPrompt.unit.test.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import * as sinon from 'sinon';
88
import { instance, mock, verify, when } from 'ts-mockito';
99
import * as TypeMoq from 'typemoq';
1010
import { ConfigurationTarget, Uri, WorkspaceConfiguration } from 'vscode';
11-
import { IApplicationShell, IWorkspaceService } from '../../../client/common/application/types';
11+
import {
12+
IApplicationEnvironment,
13+
IApplicationShell,
14+
IWorkspaceService,
15+
} from '../../../client/common/application/types';
1216
import { PersistentStateFactory } from '../../../client/common/persistentState';
1317
import { IPlatformService } from '../../../client/common/platform/types';
1418
import { IBrowserService, IPersistentState, IPersistentStateFactory } from '../../../client/common/types';
@@ -28,6 +32,7 @@ suite('Conda Inherit Env Prompt', async () => {
2832
let interpreterService: TypeMoq.IMock<IInterpreterService>;
2933
let platformService: TypeMoq.IMock<IPlatformService>;
3034
let browserService: TypeMoq.IMock<IBrowserService>;
35+
let applicationEnvironment: TypeMoq.IMock<IApplicationEnvironment>;
3136
let persistentStateFactory: IPersistentStateFactory;
3237
let notificationPromptEnabled: TypeMoq.IMock<IPersistentState<any>>;
3338
let condaInheritEnvPrompt: CondaInheritEnvPrompt;
@@ -45,13 +50,17 @@ suite('Conda Inherit Env Prompt', async () => {
4550
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
4651
persistentStateFactory = mock(PersistentStateFactory);
4752
platformService = TypeMoq.Mock.ofType<IPlatformService>();
53+
applicationEnvironment = TypeMoq.Mock.ofType<IApplicationEnvironment>();
54+
applicationEnvironment.setup((a) => a.remoteName).returns(() => undefined);
4855
condaInheritEnvPrompt = new CondaInheritEnvPrompt(
4956
interpreterService.object,
5057
workspaceService.object,
5158
browserService.object,
5259
appShell.object,
5360
instance(persistentStateFactory),
61+
5462
platformService.object,
63+
applicationEnvironment.object,
5564
);
5665
});
5766
test('Returns false if prompt has already been shown in the current session', async () => {
@@ -61,7 +70,9 @@ suite('Conda Inherit Env Prompt', async () => {
6170
browserService.object,
6271
appShell.object,
6372
instance(persistentStateFactory),
73+
6474
platformService.object,
75+
applicationEnvironment.object,
6576
true,
6677
);
6778
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
@@ -78,6 +89,14 @@ suite('Conda Inherit Env Prompt', async () => {
7889
expect(condaInheritEnvPrompt.hasPromptBeenShownInCurrentSession).to.equal(true, 'Should be true');
7990
verifyAll();
8091
});
92+
test('Returns false if running on remote', async () => {
93+
applicationEnvironment.reset();
94+
applicationEnvironment.setup((a) => a.remoteName).returns(() => 'ssh');
95+
const result = await condaInheritEnvPrompt.shouldShowPrompt(resource);
96+
expect(result).to.equal(false, 'Prompt should not be shown');
97+
expect(condaInheritEnvPrompt.hasPromptBeenShownInCurrentSession).to.equal(false, 'Should be false');
98+
verifyAll();
99+
});
81100
test('Returns false if on Windows', async () => {
82101
platformService
83102
.setup((ps) => ps.isWindows)
@@ -245,6 +264,8 @@ suite('Conda Inherit Env Prompt', async () => {
245264
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
246265
persistentStateFactory = mock(PersistentStateFactory);
247266
platformService = TypeMoq.Mock.ofType<IPlatformService>();
267+
applicationEnvironment = TypeMoq.Mock.ofType<IApplicationEnvironment>();
268+
applicationEnvironment.setup((a) => a.remoteName).returns(() => undefined);
248269
});
249270

250271
teardown(() => {
@@ -261,7 +282,9 @@ suite('Conda Inherit Env Prompt', async () => {
261282
browserService.object,
262283
appShell.object,
263284
instance(persistentStateFactory),
285+
264286
platformService.object,
287+
applicationEnvironment.object,
265288
);
266289

267290
const promise = condaInheritEnvPrompt.activate(resource);
@@ -285,7 +308,9 @@ suite('Conda Inherit Env Prompt', async () => {
285308
browserService.object,
286309
appShell.object,
287310
instance(persistentStateFactory),
311+
288312
platformService.object,
313+
applicationEnvironment.object,
289314
);
290315
await condaInheritEnvPrompt.activate(resource);
291316
assert.ok(initializeInBackground.calledOnce);
@@ -302,6 +327,8 @@ suite('Conda Inherit Env Prompt', async () => {
302327
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
303328
persistentStateFactory = mock(PersistentStateFactory);
304329
platformService = TypeMoq.Mock.ofType<IPlatformService>();
330+
applicationEnvironment = TypeMoq.Mock.ofType<IApplicationEnvironment>();
331+
applicationEnvironment.setup((a) => a.remoteName).returns(() => undefined);
305332
});
306333

307334
teardown(() => {
@@ -319,7 +346,9 @@ suite('Conda Inherit Env Prompt', async () => {
319346
browserService.object,
320347
appShell.object,
321348
instance(persistentStateFactory),
349+
322350
platformService.object,
351+
applicationEnvironment.object,
323352
);
324353
await condaInheritEnvPrompt.initializeInBackground(resource);
325354
assert.ok(shouldShowPrompt.calledOnce);
@@ -337,7 +366,9 @@ suite('Conda Inherit Env Prompt', async () => {
337366
browserService.object,
338367
appShell.object,
339368
instance(persistentStateFactory),
369+
340370
platformService.object,
371+
applicationEnvironment.object,
341372
);
342373
await condaInheritEnvPrompt.initializeInBackground(resource);
343374
assert.ok(shouldShowPrompt.calledOnce);
@@ -355,6 +386,8 @@ suite('Conda Inherit Env Prompt', async () => {
355386
browserService = TypeMoq.Mock.ofType<IBrowserService>();
356387
notificationPromptEnabled = TypeMoq.Mock.ofType<IPersistentState<any>>();
357388
platformService = TypeMoq.Mock.ofType<IPlatformService>();
389+
applicationEnvironment = TypeMoq.Mock.ofType<IApplicationEnvironment>();
390+
applicationEnvironment.setup((a) => a.remoteName).returns(() => undefined);
358391
when(persistentStateFactory.createGlobalPersistentState(condaInheritEnvPromptKey, true)).thenReturn(
359392
notificationPromptEnabled.object,
360393
);
@@ -364,7 +397,9 @@ suite('Conda Inherit Env Prompt', async () => {
364397
browserService.object,
365398
appShell.object,
366399
instance(persistentStateFactory),
400+
367401
platformService.object,
402+
applicationEnvironment.object,
368403
);
369404
});
370405

0 commit comments

Comments
 (0)