Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting showPythonInlineValues #407

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
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,18 @@
"properties": {
"debugpy.debugJustMyCode": {
"default": true,
"description": "%debugpy.debugJustMyCode%",
"description": "%debugpy.debugJustMyCode.description%",
"scope": "resource",
"type": "boolean"
},
"debugpy.showPythonInlineValues": {
"default": false,
"description": "%debugpy.showPythonInlineValues.description%",
"scope": "resource",
"type": "boolean",
"tags": [
"experimental"
]
}
},
"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..description": "When debugging only step through user-written code. Disable this to allow stepping into library code.",
"debugpy.showPythonInlineValues.description": "Whether to display inline values in the editor while debugging."
}
30 changes: 28 additions & 2 deletions src/extension/extensionInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
'use strict';

import {
ConfigurationChangeEvent,
debug,
DebugConfigurationProviderTriggerKind,
DebugTreeItem,
DebugVisualization,
DebugVisualizationContext,
Disposable,
languages,
ThemeIcon,
Uri,
Expand Down Expand Up @@ -200,8 +202,32 @@ export async function registerDebugger(context: IExtensionContext): Promise<IExt
>('inlineHexDecoder', registerHexDebugVisualizationTreeProvider()),
);

context.subscriptions.push(
languages.registerInlineValuesProvider({ language: 'python' }, new PythonInlineValueProvider()),
let registerInlineValuesProviderDisposable: Disposable;

const showInlineValues = getConfiguration('debugpy').get<boolean>('showPythonInlineValues', false);
if (showInlineValues) {
registerInlineValuesProviderDisposable = languages.registerInlineValuesProvider(
{ language: 'python' },
new PythonInlineValueProvider(),
);
context.subscriptions.push(registerInlineValuesProviderDisposable);
}

context.subscriptions.push(
workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
if (event.affectsConfiguration('debugpy')) {
Copy link
Member

Choose a reason for hiding this comment

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

An aside but I have a ConfigValue helper that I've copied between multiple projects that makes this easier :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion Connor, I'll review it and add it as a dev week item.

const showInlineValues = getConfiguration('debugpy').get<boolean>('showPythonInlineValues', false);
if (!showInlineValues) {
registerInlineValuesProviderDisposable.dispose();
} else {
registerInlineValuesProviderDisposable = languages.registerInlineValuesProvider(
{ language: 'python' },
new PythonInlineValueProvider(),
);
context.subscriptions.push(registerInlineValuesProviderDisposable);
}
}
}),
);

context.subscriptions.push(
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
Loading