Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
"description": "%debugpy.debugJustMyCode%",
"scope": "resource",
"type": "boolean"
},
"debugpy.showPythonInlineValues": {
"default": false,
"description": "%debugpy.showPythonInlineValues%",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"description": "%debugpy.showPythonInlineValues%",
"description": "%debugpy.showPythonInlineValues.description%",

"scope": "resource",
"type": "boolean"
Comment thread
paulacamargo25 marked this conversation as resolved.
Outdated
}
},
"title": "Python Debugger",
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"debugpy.command.debugUsingLaunchConfig.title": "Python Debugger: Debug using launch.json",
"debugpy.command.reportIssue.title": "Report Issue...",
"debugpy.command.viewOutput.title": "Show Output",
"debugpy.debugJustMyCode": "When debugging only step through user-written code. Disable this to allow stepping into library code."
"debugpy.debugJustMyCode": "When debugging only step through user-written code. Disable this to allow stepping into library code.",
"debugpy.showPythonInlineValues": "Enable this to see inline values in the editor while debugging."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"debugpy.showPythonInlineValues": "Enable this to see inline values in the editor while debugging."
"debugpy.showPythonInlineValues": "Whether to display inline values in the editor while debugging."

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
InlineValueVariableLookup,
InlineValueEvaluatableExpression,
} from 'vscode';
import { customRequest } from '../../common/vscodeapi';
import { customRequest, getConfiguration } from '../../common/vscodeapi';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';

Expand All @@ -20,6 +20,10 @@ export class PythonInlineValueProvider implements InlineValuesProvider {
viewPort: Range,
context: InlineValueContext,
): Promise<InlineValue[]> {
const showInlineValues = getConfiguration('debugpy').get<boolean>('showPythonInlineValues', false);
if (!showInlineValues) {
return [];
}
let scopesRequest = await customRequest('scopes', { frameId: context.frameId });
let variablesRequest = await customRequest('variables', {
variablesReference: scopesRequest.scopes[0].variablesReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

import * as chaiAsPromised from 'chai-as-promised';
import * as path from 'path';
import * as TypeMoq from 'typemoq';
import * as sinon from 'sinon';
import { use, expect } from 'chai';
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants';
import { PythonInlineValueProvider } from '../../../extension/debugger/inlineValue/pythonInlineValueProvider';
import { workspace, Range, InlineValueContext } from 'vscode';
import { workspace, Range, InlineValueContext, WorkspaceConfiguration } from 'vscode';
import * as vscodeapi from '../../../extension/common/vscodeapi';

use(chaiAsPromised);
Expand All @@ -18,16 +19,27 @@ const WS_ROOT = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test');

suite('Debugging - pythonInlineProvider', () => {
let customRequestStub: sinon.SinonStub;
let getConfigurationStub: sinon.SinonStub;

setup(() => {
customRequestStub = sinon.stub(vscodeapi, 'customRequest');
customRequestStub.withArgs('scopes', sinon.match.any).resolves({ scopes: [{ variablesReference: 0 }] });
getConfigurationStub = sinon.stub(vscodeapi, 'getConfiguration');
getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(true));
});

teardown(async () => {
sinon.restore();
});

function createMoqConfiguration(showPythonInlineValues: boolean) {
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
debugpySettings
.setup((p) => p.get<boolean>('showPythonInlineValues', TypeMoq.It.isAny()))
.returns(() => showPythonInlineValues);
return debugpySettings.object;
}

test('ProvideInlineValues function should return all the vars in the python file', async () => {
customRequestStub.withArgs('variables', sinon.match.any).resolves({
variables: [
Expand Down Expand Up @@ -331,7 +343,7 @@ suite('Debugging - pythonInlineProvider', () => {
expect(result).to.deep.equal(expected);
});

test.only('ProvideInlineValues function should return all the vars in the python file using Assignment Expressions', async () => {
test('ProvideInlineValues function should return all the vars in the python file using Assignment Expressions', async () => {
customRequestStub.withArgs('variables', sinon.match.any).resolves({
variables: [
{
Expand Down Expand Up @@ -502,4 +514,16 @@ suite('Debugging - pythonInlineProvider', () => {
];
expect(result).to.deep.equal(expected);
});

test("Provider should return empty array if 'showPythonInlineValues' is false", async () => {
getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(false));
const file = path.join(WS_ROOT, 'pythonFiles', 'testAssignmentExp.py');
let document = await workspace.openTextDocument(file);
const viewPort = new Range(0, 0, 6, 0);
const context = { frameId: 0, stoppedLocation: new Range(3, 1, 3, 1) } as InlineValueContext;
const inlineValueProvider = new PythonInlineValueProvider();

const result = await inlineValueProvider.provideInlineValues(document, viewPort, context);
expect(result).to.deep.equal([]);
});
});