Skip to content

Commit 36ec556

Browse files
Add setting showPythonInlineValues (#407)
* Add setting showPythonInlineValues * Fix lint * fix tests * fix package.json * Add experimental tag * fix text * update translations * dont register provider if value is false * fix lint
1 parent d259e1d commit 36ec556

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,18 @@
128128
"properties": {
129129
"debugpy.debugJustMyCode": {
130130
"default": true,
131-
"description": "%debugpy.debugJustMyCode%",
131+
"description": "%debugpy.debugJustMyCode.description%",
132132
"scope": "resource",
133133
"type": "boolean"
134+
},
135+
"debugpy.showPythonInlineValues": {
136+
"default": false,
137+
"description": "%debugpy.showPythonInlineValues.description%",
138+
"scope": "resource",
139+
"type": "boolean",
140+
"tags": [
141+
"experimental"
142+
]
134143
}
135144
},
136145
"title": "Python Debugger",

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"debugpy.command.debugUsingLaunchConfig.title": "Python Debugger: Debug using launch.json",
55
"debugpy.command.reportIssue.title": "Report Issue...",
66
"debugpy.command.viewOutput.title": "Show Output",
7-
"debugpy.debugJustMyCode": "When debugging only step through user-written code. Disable this to allow stepping into library code."
7+
"debugpy.debugJustMyCode..description": "When debugging only step through user-written code. Disable this to allow stepping into library code.",
8+
"debugpy.showPythonInlineValues.description": "Whether to display inline values in the editor while debugging."
89
}

src/extension/extensionInit.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
'use strict';
55

66
import {
7+
ConfigurationChangeEvent,
78
debug,
89
DebugConfigurationProviderTriggerKind,
910
DebugTreeItem,
1011
DebugVisualization,
1112
DebugVisualizationContext,
13+
Disposable,
1214
languages,
1315
ThemeIcon,
1416
Uri,
@@ -200,8 +202,32 @@ export async function registerDebugger(context: IExtensionContext): Promise<IExt
200202
>('inlineHexDecoder', registerHexDebugVisualizationTreeProvider()),
201203
);
202204

203-
context.subscriptions.push(
204-
languages.registerInlineValuesProvider({ language: 'python' }, new PythonInlineValueProvider()),
205+
let registerInlineValuesProviderDisposable: Disposable;
206+
207+
const showInlineValues = getConfiguration('debugpy').get<boolean>('showPythonInlineValues', false);
208+
if (showInlineValues) {
209+
registerInlineValuesProviderDisposable = languages.registerInlineValuesProvider(
210+
{ language: 'python' },
211+
new PythonInlineValueProvider(),
212+
);
213+
context.subscriptions.push(registerInlineValuesProviderDisposable);
214+
}
215+
216+
context.subscriptions.push(
217+
workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
218+
if (event.affectsConfiguration('debugpy')) {
219+
const showInlineValues = getConfiguration('debugpy').get<boolean>('showPythonInlineValues', false);
220+
if (!showInlineValues) {
221+
registerInlineValuesProviderDisposable.dispose();
222+
} else {
223+
registerInlineValuesProviderDisposable = languages.registerInlineValuesProvider(
224+
{ language: 'python' },
225+
new PythonInlineValueProvider(),
226+
);
227+
context.subscriptions.push(registerInlineValuesProviderDisposable);
228+
}
229+
}
230+
}),
205231
);
206232

207233
context.subscriptions.push(

src/test/unittest/inlineValue/pythonInlineValueProvider.unit.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
import * as chaiAsPromised from 'chai-as-promised';
77
import * as path from 'path';
8+
import * as TypeMoq from 'typemoq';
89
import * as sinon from 'sinon';
910
import { use, expect } from 'chai';
1011
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants';
1112
import { PythonInlineValueProvider } from '../../../extension/debugger/inlineValue/pythonInlineValueProvider';
12-
import { workspace, Range, InlineValueContext } from 'vscode';
13+
import { workspace, Range, InlineValueContext, WorkspaceConfiguration } from 'vscode';
1314
import * as vscodeapi from '../../../extension/common/vscodeapi';
1415

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

1920
suite('Debugging - pythonInlineProvider', () => {
2021
let customRequestStub: sinon.SinonStub;
22+
let getConfigurationStub: sinon.SinonStub;
2123

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

2731
teardown(async () => {
2832
sinon.restore();
2933
});
3034

35+
function createMoqConfiguration(showPythonInlineValues: boolean) {
36+
const debugpySettings = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
37+
debugpySettings
38+
.setup((p) => p.get<boolean>('showPythonInlineValues', TypeMoq.It.isAny()))
39+
.returns(() => showPythonInlineValues);
40+
return debugpySettings.object;
41+
}
42+
3143
test('ProvideInlineValues function should return all the vars in the python file', async () => {
3244
customRequestStub.withArgs('variables', sinon.match.any).resolves({
3345
variables: [
@@ -331,7 +343,7 @@ suite('Debugging - pythonInlineProvider', () => {
331343
expect(result).to.deep.equal(expected);
332344
});
333345

334-
test.only('ProvideInlineValues function should return all the vars in the python file using Assignment Expressions', async () => {
346+
test('ProvideInlineValues function should return all the vars in the python file using Assignment Expressions', async () => {
335347
customRequestStub.withArgs('variables', sinon.match.any).resolves({
336348
variables: [
337349
{

0 commit comments

Comments
 (0)