Skip to content

Commit

Permalink
Fire active environment change event if selected environment is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Sep 28, 2023
1 parent bd3590d commit 9d1b29c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/client/interpreter/interpreterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export class InterpreterService implements Disposable, IInterpreterService {

private readonly didChangeInterpreterInformation = new EventEmitter<PythonEnvironment>();

private readonly activeInterpreterPaths = new Map<
string,
{ path: string; workspaceFolder: WorkspaceFolder | undefined }
>();

constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(IComponentAdapter) private readonly pyenvs: IComponentAdapter,
Expand All @@ -100,10 +105,12 @@ export class InterpreterService implements Disposable, IInterpreterService {
const workspaceFolder = this.serviceContainer
.get<IWorkspaceService>(IWorkspaceService)
.getWorkspaceFolder(resource);
this.ensureEnvironmentContainsPython(
this.configService.getSettings(resource).pythonPath,
workspaceFolder,
).ignoreErrors();
const path = this.configService.getSettings(resource).pythonPath;
const workspaceKey = this.serviceContainer
.get<IWorkspaceService>(IWorkspaceService)
.getWorkspaceFolderIdentifier(resource);
this.activeInterpreterPaths.set(workspaceKey, { path, workspaceFolder });
this.ensureEnvironmentContainsPython(path, workspaceFolder).ignoreErrors();
}

public initialize(): void {
Expand Down Expand Up @@ -155,6 +162,16 @@ export class InterpreterService implements Disposable, IInterpreterService {
const interpreter = e.old ?? e.new;
if (interpreter) {
this.didChangeInterpreterInformation.fire(interpreter);
for (const { path, workspaceFolder } of this.activeInterpreterPaths.values()) {
if (path === interpreter.path && !e.new) {
// If the active environment got deleted, notify it.
this.didChangeInterpreterEmitter.fire(workspaceFolder?.uri);
reportActiveInterpreterChanged({
path,
resource: workspaceFolder,
});
}
}
}
}),
);
Expand Down Expand Up @@ -246,6 +263,10 @@ export class InterpreterService implements Disposable, IInterpreterService {
path: pySettings.pythonPath,
resource: workspaceFolder,
});
const workspaceKey = this.serviceContainer
.get<IWorkspaceService>(IWorkspaceService)
.getWorkspaceFolderIdentifier(resource);
this.activeInterpreterPaths.set(workspaceKey, { path: pySettings.pythonPath, workspaceFolder });
const interpreterDisplay = this.serviceContainer.get<IInterpreterDisplay>(IInterpreterDisplay);
interpreterDisplay.refresh().catch((ex) => traceError('Python Extension: display.refresh', ex));
await this.ensureEnvironmentContainsPython(this._pythonPathSetting, workspaceFolder);
Expand Down

0 comments on commit 9d1b29c

Please sign in to comment.