Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { ICommandManager, IWorkspaceService } from '../../../common/application/
import { sendTelemetryEvent } from '../../../telemetry';
import { EventName } from '../../../telemetry/constants';
import { IExtensionSingleActivationService } from '../../../activation/types';
import { cache } from '../../../common/utils/decorators';
import { noop } from '../../../common/utils/misc';

const localize: nls.LocalizeFunc = nls.loadMessageBundle();

Expand Down Expand Up @@ -90,6 +92,12 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService
this.triggerEnvSelectionIfNecessary(resource),
),
);
const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
this.disposableRegistry.push(
interpreterService.onDidChangeInterpreterConfiguration((e) =>
commandManager.executeCommand(Commands.TriggerEnvironmentSelection, e).then(noop, noop),
),
);
}

public async diagnose(resource: Resource): Promise<IDiagnostic[]> {
Expand Down Expand Up @@ -130,6 +138,7 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService
return false;
}

@cache(1000, true) // This is to handle throttling of multiple events.
protected async onHandle(diagnostics: IDiagnostic[]): Promise<void> {
if (diagnostics.length === 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { expect } from 'chai';
import * as typemoq from 'typemoq';
import { EventEmitter, Uri } from 'vscode';
import { IExtensionSingleActivationService } from '../../../../client/activation/types';
import { BaseDiagnosticsService } from '../../../../client/application/diagnostics/base';
import { InvalidLaunchJsonDebuggerDiagnostic } from '../../../../client/application/diagnostics/checks/invalidLaunchJsonDebugger';
Expand Down Expand Up @@ -35,6 +36,7 @@ import { noop } from '../../../../client/common/utils/misc';
import { IInterpreterHelper, IInterpreterService } from '../../../../client/interpreter/contracts';
import { IServiceContainer } from '../../../../client/ioc/types';
import { EnvironmentType, PythonEnvironment } from '../../../../client/pythonEnvironments/info';
import { sleep } from '../../../core';

suite('Application Diagnostics - Checks Python Interpreter', () => {
let diagnosticService: IDiagnosticsService & IExtensionSingleActivationService;
Expand Down Expand Up @@ -117,6 +119,27 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
expect(result2).to.equal(true);
});

test('Changes to interpreter configuration triggers environment prompts', async () => {
commandManager
.setup((c) => c.registerCommand(Commands.TriggerEnvironmentSelection, typemoq.It.isAny()))
.returns(() => typemoq.Mock.ofType<IDisposable>().object);
const interpreterEvent = new EventEmitter<Uri | undefined>();
interpreterService
.setup((i) => i.onDidChangeInterpreterConfiguration)
.returns(() => interpreterEvent.event);
await diagnosticService.activate();

commandManager
.setup((c) => c.executeCommand(Commands.TriggerEnvironmentSelection, undefined))
.returns(() => Promise.resolve())
.verifiable(typemoq.Times.once());

interpreterEvent.fire(undefined);
await sleep(1);

commandManager.verifyAll();
});

test('Can handle InvalidPythonPathInterpreter diagnostics', async () => {
for (const code of [
DiagnosticCodes.NoPythonInterpretersDiagnostic,
Expand Down