Skip to content
Open
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 @@ -158,7 +158,7 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService
];
}

const currentInterpreter = await interpreterService.getActiveInterpreter(resource);
const currentInterpreter = await interpreterService.getActiveInterpreter(resource, { waitForResolution: true });
if (!currentInterpreter) {
if (useEnvExtension()) {
traceWarn(Interpreters.envExtNoActiveEnvironment);
Expand Down Expand Up @@ -188,7 +188,7 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService
return [];
}
const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
const currentInterpreter = await interpreterService.getActiveInterpreter(resource);
const currentInterpreter = await interpreterService.getActiveInterpreter(resource, { waitForResolution: true });
if (currentInterpreter) {
return [];
}
Expand Down
4 changes: 4 additions & 0 deletions src/client/interpreter/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export interface GetActiveInterpreterOptions {
* Resolve the exact resource without using workspace-scoped in-flight or last-known state.
*/
exactResource?: boolean;
/**
* Wait for active interpreter resolution to complete instead of returning early on the timeout budget.
*/
waitForResolution?: boolean;
}

export interface IInterpreterService {
Expand Down
3 changes: 3 additions & 0 deletions src/client/interpreter/interpreterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ export class InterpreterService implements Disposable, IInterpreterService {
// abandoned, so listeners are still notified of the real value once it becomes available:
// the env-extension path reports via the environments API (see getActiveInterpreterLegacy),
// and the native path reports via `_onConfigChanged` once auto-selection completes.
if (options?.waitForResolution) {
return resolution;
}
const result = await Promise.race([
resolution,
sleep(GET_ACTIVE_INTERPRETER_TIMEOUT_MS).then(() => ACTIVE_INTERPRETER_TIMED_OUT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
interpreterService.reset();
interpreterService.setup((i) => i.hasInterpreters()).returns(() => Promise.resolve(true));
interpreterService
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny()))
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny(), typemoq.It.isAny()))
.returns(() => Promise.resolve(({ path: 'interpreterpath' } as unknown) as PythonEnvironment));
const result2 = await triggerFunction!(undefined);
expect(result2).to.equal(true);
Expand Down Expand Up @@ -228,7 +228,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
}
// No interpreter should exist if comspec is incorrectly configured.
interpreterService
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny()))
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny(), typemoq.It.isAny()))
.returns(() => {
return Promise.resolve(undefined);
});
Expand All @@ -252,7 +252,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
}
// No interpreter should exist if execution is failing.
interpreterService
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny()))
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny(), typemoq.It.isAny()))
.returns(() => {
return Promise.resolve(undefined);
});
Expand All @@ -272,7 +272,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
}
// No interpreter should exist if execution is failing.
interpreterService
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny()))
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny(), typemoq.It.isAny()))
.returns(() => {
return Promise.resolve(undefined);
});
Expand All @@ -293,7 +293,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
interpreterService.setup((i) => i.hasInterpreters()).returns(() => Promise.resolve(false));
// No interpreter should exist if execution is failing.
interpreterService
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny()))
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny(), typemoq.It.isAny()))
.returns(() => {
return Promise.resolve(undefined);
});
Expand All @@ -318,7 +318,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
.returns(() => Promise.resolve(true))
.verifiable(typemoq.Times.once());
interpreterService
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny()))
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny(), typemoq.It.isAny()))
.returns(() => {
return Promise.resolve(undefined);
});
Expand All @@ -338,7 +338,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
test('Should return empty diagnostics if there are interpreters and a current interpreter', async () => {
interpreterService.setup((i) => i.hasInterpreters()).returns(() => Promise.resolve(true));
interpreterService
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny()))
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny(), typemoq.It.isAny()))
.returns(() => {
return Promise.resolve({ envType: EnvironmentType.Unknown } as any);
});
Expand All @@ -347,6 +347,23 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
expect(diagnostics).to.be.deep.equal([], 'not the same');
});

test('Should wait for active interpreter resolution in _manualDiagnose', async () => {
interpreterService.setup((i) => i.hasInterpreters()).returns(() => Promise.resolve(true));
interpreterService
.setup((i) =>
i.getActiveInterpreter(
undefined,
typemoq.It.is((opts) => opts?.waitForResolution === true),
),
)
.returns(() => Promise.resolve(({ path: 'interpreterpath' } as unknown) as PythonEnvironment))
.verifiable(typemoq.Times.once());

const diagnostics = await diagnosticService._manualDiagnose(undefined);
expect(diagnostics).to.be.deep.equal([]);
interpreterService.verifyAll();
});

test('Handling comspec diagnostic should launch expected browser link', async () => {
const diagnostic = new DefaultShellDiagnostic(DiagnosticCodes.InvalidComspecDiagnostic, undefined);
const cmd = ({} as any) as IDiagnosticCommand;
Expand Down
11 changes: 11 additions & 0 deletions src/test/interpreters/interpreterService.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,17 @@ suite('Interpreters service', () => {
workspace.verify((w) => w.getWorkspaceFolderIdentifier(TypeMoq.It.isAny()), TypeMoq.Times.never());
expect(workspacePersistedValues.size).to.equal(0);
});

test('waitForResolution waits for slow cold-start resolution instead of timing out', async () => {
const slowEnv = { path: path.join('usr', 'bin', 'slowpy') } as any;
useEnvExtensionStub.returns(true);
sinon.stub(legacyApi, 'getActiveInterpreterLegacy').callsFake(async () => delayed(slowEnv, 200));

const service = new InterpreterService(serviceContainer, pyenvs.object);
const result = await service.getActiveInterpreter(undefined, { waitForResolution: true });

expect(result).to.equal(slowEnv);
});
});

test('A configuration change re-runs the config change handler to report a background selection', async () => {
Expand Down