Skip to content

Commit

Permalink
If active editor opened is outside the editor, activate the first wor…
Browse files Browse the repository at this point in the history
…kspace (#22450)

For #22449
  • Loading branch information
Kartik Raj authored Nov 10, 2023
1 parent b68ddee commit a1fac81
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/client/activation/activationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export class ExtensionActivationManager implements IExtensionActivationManager {

@traceDecoratorError('Failed to activate a workspace')
public async activateWorkspace(resource: Resource): Promise<void> {
const folder = this.workspaceService.getWorkspaceFolder(resource);
resource = folder ? folder.uri : undefined;
const key = this.getWorkspaceKey(resource);
if (this.activatedWorkspaces.has(key)) {
return;
Expand Down Expand Up @@ -117,8 +119,7 @@ export class ExtensionActivationManager implements IExtensionActivationManager {
if (this.activatedWorkspaces.has(key)) {
return;
}
const folder = this.workspaceService.getWorkspaceFolder(doc.uri);
this.activateWorkspace(folder ? folder.uri : undefined).ignoreErrors();
this.activateWorkspace(doc.uri).ignoreErrors();
}

protected addHandlers(): void {
Expand Down
4 changes: 3 additions & 1 deletion src/client/interpreter/activation/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
shellInfo.shellType,
interpreter,
);
traceVerbose(`Activation Commands received ${activationCommands} for shell ${shellInfo.shell}`);
traceVerbose(
`Activation Commands received ${activationCommands} for shell ${shellInfo.shell}, resource ${resource?.fsPath} and interpreter ${interpreter?.path}`,
);
if (!activationCommands || !Array.isArray(activationCommands) || activationCommands.length === 0) {
if (interpreter && [EnvironmentType.Venv, EnvironmentType.Pyenv].includes(interpreter?.envType)) {
const key = getSearchPathEnvVarNames()[0];
Expand Down
25 changes: 25 additions & 0 deletions src/test/activation/activationManager.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ suite('Activation Manager', () => {
test('If running in a virtual workspace, do not activate services that do not support it', async () => {
when(workspaceService.isVirtualWorkspace).thenReturn(true);
const resource = Uri.parse('two');
const workspaceFolder = {
index: 0,
name: 'one',
uri: resource,
};
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);

autoSelection
.setup((a) => a.autoSelectInterpreter(resource))
Expand Down Expand Up @@ -112,6 +118,12 @@ suite('Activation Manager', () => {
test('If running in a untrusted workspace, do not activate services that do not support it', async () => {
when(workspaceService.isTrusted).thenReturn(false);
const resource = Uri.parse('two');
const workspaceFolder = {
index: 0,
name: 'one',
uri: resource,
};
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);

autoSelection
.setup((a) => a.autoSelectInterpreter(resource))
Expand Down Expand Up @@ -150,6 +162,13 @@ suite('Activation Manager', () => {
.returns(() => Promise.resolve())
.verifiable(typemoq.Times.once());

const workspaceFolder = {
index: 0,
name: 'one',
uri: resource,
};
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);

await managerTest.activateWorkspace(resource);

autoSelection.verifyAll();
Expand Down Expand Up @@ -289,6 +308,12 @@ suite('Activation Manager', () => {
.setup((a) => a.performPreStartupHealthCheck(resource))
.returns(() => Promise.resolve())
.verifiable(typemoq.Times.once());
const workspaceFolder = {
index: 0,
name: 'one',
uri: resource,
};
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);

await managerTest.activateWorkspace(resource);
await managerTest.activateWorkspace(resource);
Expand Down

0 comments on commit a1fac81

Please sign in to comment.