Skip to content

Commit ddd30b0

Browse files
author
Kartik Raj
authored
If an interpreter has been explicitly set to an invalid value, trigger the correct prompt (microsoft#19585)
1 parent 254cc98 commit ddd30b0

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/client/application/diagnostics/checks/pythonInterpreter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DiagnosticSeverity } from 'vscode';
77
import '../../../common/extensions';
88
import * as nls from 'vscode-nls';
99
import * as path from 'path';
10-
import { IDisposableRegistry, Resource } from '../../../common/types';
10+
import { IDisposableRegistry, IInterpreterPathService, Resource } from '../../../common/types';
1111
import { IInterpreterService } from '../../../interpreter/contracts';
1212
import { IServiceContainer } from '../../../ioc/types';
1313
import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
@@ -109,8 +109,10 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService
109109
const workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
110110
const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
111111
const hasInterpreters = await interpreterService.hasInterpreters();
112+
const interpreterPathService = this.serviceContainer.get<IInterpreterPathService>(IInterpreterPathService);
113+
const isInterpreterSetToDefault = interpreterPathService.get(resource) === 'python';
112114

113-
if (!hasInterpreters) {
115+
if (!hasInterpreters && isInterpreterSetToDefault) {
114116
return [
115117
new InvalidPythonInterpreterDiagnostic(
116118
DiagnosticCodes.NoPythonInterpretersDiagnostic,

src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { CommandsWithoutArgs } from '../../../../client/common/application/comma
2828
import { ICommandManager, IWorkspaceService } from '../../../../client/common/application/types';
2929
import { Commands } from '../../../../client/common/constants';
3030
import { IPlatformService } from '../../../../client/common/platform/types';
31-
import { IDisposable, IDisposableRegistry, Resource } from '../../../../client/common/types';
31+
import { IDisposable, IDisposableRegistry, IInterpreterPathService, Resource } from '../../../../client/common/types';
3232
import { Common } from '../../../../client/common/utils/localize';
3333
import { noop } from '../../../../client/common/utils/misc';
3434
import { IInterpreterHelper, IInterpreterService } from '../../../../client/interpreter/contracts';
@@ -46,6 +46,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
4646
let commandManager: typemoq.IMock<ICommandManager>;
4747
let helper: typemoq.IMock<IInterpreterHelper>;
4848
let serviceContainer: typemoq.IMock<IServiceContainer>;
49+
let interpreterPathService: typemoq.IMock<IInterpreterPathService>;
4950
function createContainer() {
5051
serviceContainer = typemoq.Mock.ofType<IServiceContainer>();
5152
workspaceService = typemoq.Mock.ofType<IWorkspaceService>();
@@ -76,6 +77,11 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
7677
serviceContainer
7778
.setup((s) => s.get(typemoq.It.isValue(IPlatformService)))
7879
.returns(() => platformService.object);
80+
interpreterPathService = typemoq.Mock.ofType<IInterpreterPathService>();
81+
interpreterPathService.setup((i) => i.get(typemoq.It.isAny())).returns(() => 'customPython');
82+
serviceContainer
83+
.setup((s) => s.get(typemoq.It.isValue(IInterpreterPathService)))
84+
.returns(() => interpreterPathService.object);
7985
helper = typemoq.Mock.ofType<IInterpreterHelper>();
8086
serviceContainer.setup((s) => s.get(typemoq.It.isValue(IInterpreterHelper))).returns(() => helper.object);
8187
serviceContainer.setup((s) => s.get(typemoq.It.isValue(IDisposableRegistry))).returns(() => []);
@@ -160,7 +166,9 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
160166
expect(diagnostics).to.be.deep.equal([], 'not the same');
161167
});
162168

163-
test('Should return diagnostics if there are no interpreters after double-checking', async () => {
169+
test('Should return diagnostics if there are no interpreters and no interpreter has been explicitly set', async () => {
170+
interpreterPathService.reset();
171+
interpreterPathService.setup((i) => i.get(typemoq.It.isAny())).returns(() => 'python');
164172
interpreterService
165173
.setup((i) => i.hasInterpreters())
166174
.returns(() => Promise.resolve(false))

0 commit comments

Comments
 (0)