Skip to content

Commit a1fac81

Browse files
author
Kartik Raj
authored
If active editor opened is outside the editor, activate the first workspace (#22450)
For #22449
1 parent b68ddee commit a1fac81

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/client/activation/activationManager.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export class ExtensionActivationManager implements IExtensionActivationManager {
8383

8484
@traceDecoratorError('Failed to activate a workspace')
8585
public async activateWorkspace(resource: Resource): Promise<void> {
86+
const folder = this.workspaceService.getWorkspaceFolder(resource);
87+
resource = folder ? folder.uri : undefined;
8688
const key = this.getWorkspaceKey(resource);
8789
if (this.activatedWorkspaces.has(key)) {
8890
return;
@@ -117,8 +119,7 @@ export class ExtensionActivationManager implements IExtensionActivationManager {
117119
if (this.activatedWorkspaces.has(key)) {
118120
return;
119121
}
120-
const folder = this.workspaceService.getWorkspaceFolder(doc.uri);
121-
this.activateWorkspace(folder ? folder.uri : undefined).ignoreErrors();
122+
this.activateWorkspace(doc.uri).ignoreErrors();
122123
}
123124

124125
protected addHandlers(): void {

src/client/interpreter/activation/service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
259259
shellInfo.shellType,
260260
interpreter,
261261
);
262-
traceVerbose(`Activation Commands received ${activationCommands} for shell ${shellInfo.shell}`);
262+
traceVerbose(
263+
`Activation Commands received ${activationCommands} for shell ${shellInfo.shell}, resource ${resource?.fsPath} and interpreter ${interpreter?.path}`,
264+
);
263265
if (!activationCommands || !Array.isArray(activationCommands) || activationCommands.length === 0) {
264266
if (interpreter && [EnvironmentType.Venv, EnvironmentType.Pyenv].includes(interpreter?.envType)) {
265267
const key = getSearchPathEnvVarNames()[0];

src/test/activation/activationManager.unit.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ suite('Activation Manager', () => {
8282
test('If running in a virtual workspace, do not activate services that do not support it', async () => {
8383
when(workspaceService.isVirtualWorkspace).thenReturn(true);
8484
const resource = Uri.parse('two');
85+
const workspaceFolder = {
86+
index: 0,
87+
name: 'one',
88+
uri: resource,
89+
};
90+
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);
8591

8692
autoSelection
8793
.setup((a) => a.autoSelectInterpreter(resource))
@@ -112,6 +118,12 @@ suite('Activation Manager', () => {
112118
test('If running in a untrusted workspace, do not activate services that do not support it', async () => {
113119
when(workspaceService.isTrusted).thenReturn(false);
114120
const resource = Uri.parse('two');
121+
const workspaceFolder = {
122+
index: 0,
123+
name: 'one',
124+
uri: resource,
125+
};
126+
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);
115127

116128
autoSelection
117129
.setup((a) => a.autoSelectInterpreter(resource))
@@ -150,6 +162,13 @@ suite('Activation Manager', () => {
150162
.returns(() => Promise.resolve())
151163
.verifiable(typemoq.Times.once());
152164

165+
const workspaceFolder = {
166+
index: 0,
167+
name: 'one',
168+
uri: resource,
169+
};
170+
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);
171+
153172
await managerTest.activateWorkspace(resource);
154173

155174
autoSelection.verifyAll();
@@ -289,6 +308,12 @@ suite('Activation Manager', () => {
289308
.setup((a) => a.performPreStartupHealthCheck(resource))
290309
.returns(() => Promise.resolve())
291310
.verifiable(typemoq.Times.once());
311+
const workspaceFolder = {
312+
index: 0,
313+
name: 'one',
314+
uri: resource,
315+
};
316+
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);
292317

293318
await managerTest.activateWorkspace(resource);
294319
await managerTest.activateWorkspace(resource);

0 commit comments

Comments
 (0)