diff --git a/package.json b/package.json index 879e0d25..aac65214 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/package.nls.json b/package.nls.json index 2be4c634..13317eed 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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." } diff --git a/src/extension/extensionInit.ts b/src/extension/extensionInit.ts index 84ce22e0..08db7f16 100644 --- a/src/extension/extensionInit.ts +++ b/src/extension/extensionInit.ts @@ -4,11 +4,13 @@ 'use strict'; import { + ConfigurationChangeEvent, debug, DebugConfigurationProviderTriggerKind, DebugTreeItem, DebugVisualization, DebugVisualizationContext, + Disposable, languages, ThemeIcon, Uri, @@ -200,8 +202,32 @@ export async function registerDebugger(context: IExtensionContext): Promise('inlineHexDecoder', registerHexDebugVisualizationTreeProvider()), ); - context.subscriptions.push( - languages.registerInlineValuesProvider({ language: 'python' }, new PythonInlineValueProvider()), + let registerInlineValuesProviderDisposable: Disposable; + + const showInlineValues = getConfiguration('debugpy').get('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')) { + const showInlineValues = getConfiguration('debugpy').get('showPythonInlineValues', false); + if (!showInlineValues) { + registerInlineValuesProviderDisposable.dispose(); + } else { + registerInlineValuesProviderDisposable = languages.registerInlineValuesProvider( + { language: 'python' }, + new PythonInlineValueProvider(), + ); + context.subscriptions.push(registerInlineValuesProviderDisposable); + } + } + }), ); context.subscriptions.push( diff --git a/src/test/unittest/inlineValue/pythonInlineValueProvider.unit.test.ts b/src/test/unittest/inlineValue/pythonInlineValueProvider.unit.test.ts index 4b3e0c11..9cbdf287 100644 --- a/src/test/unittest/inlineValue/pythonInlineValueProvider.unit.test.ts +++ b/src/test/unittest/inlineValue/pythonInlineValueProvider.unit.test.ts @@ -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); @@ -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(); + debugpySettings + .setup((p) => p.get('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: [ @@ -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: [ {