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
1 change: 1 addition & 0 deletions news/2 Fixes/14814.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not show "You need to select a Python interpreter before you start debugging" when "python" in debug configuration is invalid.
26 changes: 13 additions & 13 deletions src/client/debugger/extension/configuration/resolvers/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IPlatformService } from '../../../../common/platform/types';
import { IConfigurationService } from '../../../../common/types';
import { DebuggerTypeName } from '../../../constants';
import { DebugOptions, LaunchRequestArguments } from '../../../types';
import { PythonPathSource } from '../../types';
import { BaseConfigurationResolver } from './base';
import { IDebugEnvironmentVariablesService } from './helper';

Expand Down Expand Up @@ -183,18 +184,17 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
debugConfiguration: LaunchRequestArguments
): Promise<boolean> {
const diagnosticService = this.invalidPythonPathInDebuggerService;
return (
diagnosticService.validatePythonPath(debugConfiguration.python, this.pythonPathSource, folder?.uri) &&
Comment thread
karrtikr marked this conversation as resolved.
diagnosticService.validatePythonPath(
debugConfiguration.debugAdapterPython,
this.pythonPathSource,
folder?.uri
) &&
diagnosticService.validatePythonPath(
debugConfiguration.debugLauncherPython,
this.pythonPathSource,
folder?.uri
)
);
for (const executable of [
debugConfiguration.python,
debugConfiguration.debugAdapterPython,
debugConfiguration.debugLauncherPython
]) {
const source =
executable === debugConfiguration.pythonPath ? this.pythonPathSource : PythonPathSource.launchJson;
if (!(await diagnosticService.validatePythonPath(executable, source, folder?.uri))) {
return false;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { OSType } from '../../../../../client/common/utils/platform';
import { DebuggerTypeName } from '../../../../../client/debugger/constants';
import { IDebugEnvironmentVariablesService } from '../../../../../client/debugger/extension/configuration/resolvers/helper';
import { LaunchConfigurationResolver } from '../../../../../client/debugger/extension/configuration/resolvers/launch';
import { PythonPathSource } from '../../../../../client/debugger/extension/types';
import { DebugOptions, LaunchRequestArguments } from '../../../../../client/debugger/types';
import { IInterpreterHelper } from '../../../../../client/interpreter/contracts';
import { getOSType } from '../../../../common';
Expand Down Expand Up @@ -928,6 +929,8 @@ getInfoPerOS().forEach(([osName, osType, path]) => {

test('Test validation of Python Path when launching debugger (with invalid "python")', async () => {
const pythonPath = `PythonPath_${new Date().toString()}`;
const debugLauncherPython = `DebugLauncherPythonPath_${new Date().toString()}`;
const debugAdapterPython = `DebugAdapterPythonPath_${new Date().toString()}`;
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
Expand All @@ -936,23 +939,49 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
diagnosticsService.reset();
diagnosticsService
.setup((h) =>
h.validatePythonPath(TypeMoq.It.isValue(pythonPath), TypeMoq.It.isAny(), TypeMoq.It.isAny())
h.validatePythonPath(
TypeMoq.It.isValue(pythonPath),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
.returns(() => Promise.resolve(false))
.verifiable(TypeMoq.Times.atLeastOnce());
// Invalid
.returns(() => Promise.resolve(false));
diagnosticsService
.setup((h) =>
h.validatePythonPath(
TypeMoq.It.isValue(debugLauncherPython),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
.returns(() => Promise.resolve(true));
diagnosticsService
.setup((h) =>
h.validatePythonPath(
TypeMoq.It.isValue(debugAdapterPython),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
.returns(() => Promise.resolve(true));

const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
...launch,
redirectOutput: false,
python: pythonPath
python: pythonPath,
debugLauncherPython,
debugAdapterPython
});

diagnosticsService.verifyAll();
expect(debugConfig).to.be.equal(undefined, 'Not undefined');
});

test('Test validation of Python Path when launching debugger (with valid "python")', async () => {
test('Test validation of Python Path when launching debugger (with invalid "debugLauncherPython")', async () => {
const pythonPath = `PythonPath_${new Date().toString()}`;
const debugLauncherPython = `DebugLauncherPythonPath_${new Date().toString()}`;
const debugAdapterPython = `DebugAdapterPythonPath_${new Date().toString()}`;
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
Expand All @@ -961,7 +990,111 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
diagnosticsService.reset();
diagnosticsService
.setup((h) =>
h.validatePythonPath(TypeMoq.It.isValue(pythonPath), TypeMoq.It.isAny(), TypeMoq.It.isAny())
h.validatePythonPath(
TypeMoq.It.isValue(pythonPath),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
.returns(() => Promise.resolve(true));
diagnosticsService
.setup((h) =>
h.validatePythonPath(
TypeMoq.It.isValue(debugLauncherPython),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
// Invalid
.returns(() => Promise.resolve(false));
diagnosticsService
.setup((h) =>
h.validatePythonPath(
TypeMoq.It.isValue(debugAdapterPython),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
.returns(() => Promise.resolve(true));

const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
...launch,
redirectOutput: false,
python: pythonPath,
debugLauncherPython,
debugAdapterPython
});

diagnosticsService.verifyAll();
expect(debugConfig).to.be.equal(undefined, 'Not undefined');
});

test('Test validation of Python Path when launching debugger (with invalid "debugAdapterPython")', async () => {
const pythonPath = `PythonPath_${new Date().toString()}`;
const debugLauncherPython = `DebugLauncherPythonPath_${new Date().toString()}`;
const debugAdapterPython = `DebugAdapterPythonPath_${new Date().toString()}`;
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

diagnosticsService.reset();
diagnosticsService
.setup((h) =>
h.validatePythonPath(
TypeMoq.It.isValue(pythonPath),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
.returns(() => Promise.resolve(true));
diagnosticsService
.setup((h) =>
h.validatePythonPath(
TypeMoq.It.isValue(debugLauncherPython),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
.returns(() => Promise.resolve(true));
diagnosticsService
.setup((h) =>
h.validatePythonPath(
TypeMoq.It.isValue(debugAdapterPython),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
// Invalid
.returns(() => Promise.resolve(false));

const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
...launch,
redirectOutput: false,
python: pythonPath,
debugLauncherPython,
debugAdapterPython
});

diagnosticsService.verifyAll();
expect(debugConfig).to.be.equal(undefined, 'Not undefined');
});

test('Test validation of Python Path when launching debugger (with valid "python/debugAdapterPython/debugLauncherPython")', async () => {
const pythonPath = `PythonPath_${new Date().toString()}`;
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

diagnosticsService.reset();
diagnosticsService
.setup((h) =>
h.validatePythonPath(
TypeMoq.It.isValue(pythonPath),
PythonPathSource.launchJson,
TypeMoq.It.isAny()
)
)
.returns(() => Promise.resolve(true))
.verifiable(TypeMoq.Times.atLeastOnce());
Expand Down