Skip to content
Merged
Changes from all commits
Commits
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
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