Skip to content

Commit c46aec9

Browse files
dont register provider if value is false
1 parent 75967e6 commit c46aec9

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/extension/debugger/inlineValue/pythonInlineValueProvider.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
InlineValueVariableLookup,
1111
InlineValueEvaluatableExpression,
1212
} from 'vscode';
13-
import { customRequest, getConfiguration } from '../../common/vscodeapi';
13+
import { customRequest } from '../../common/vscodeapi';
1414
import { sendTelemetryEvent } from '../../telemetry';
1515
import { EventName } from '../../telemetry/constants';
1616

@@ -20,10 +20,6 @@ export class PythonInlineValueProvider implements InlineValuesProvider {
2020
viewPort: Range,
2121
context: InlineValueContext,
2222
): Promise<InlineValue[]> {
23-
const showInlineValues = getConfiguration('debugpy').get<boolean>('showPythonInlineValues', false);
24-
if (!showInlineValues) {
25-
return [];
26-
}
2723
let scopesRequest = await customRequest('scopes', { frameId: context.frameId });
2824
let variablesRequest = await customRequest('variables', {
2925
variablesReference: scopesRequest.scopes[0].variablesReference,

src/extension/extensionInit.ts

Lines changed: 21 additions & 3 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,9 +202,25 @@ 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-
);
205+
let registerInlineValuesProviderDisposable: Disposable;
206+
207+
const showInlineValues = getConfiguration('debugpy').get<boolean>('showPythonInlineValues', false);
208+
if (showInlineValues) {
209+
registerInlineValuesProviderDisposable = languages.registerInlineValuesProvider({ language: 'python' }, new PythonInlineValueProvider());
210+
context.subscriptions.push(registerInlineValuesProviderDisposable);
211+
}
212+
213+
context.subscriptions.push(workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
214+
if (event.affectsConfiguration('debugpy')) {
215+
const showInlineValues = getConfiguration('debugpy').get<boolean>('showPythonInlineValues', false);
216+
if (!showInlineValues) {
217+
registerInlineValuesProviderDisposable.dispose();
218+
} else {
219+
registerInlineValuesProviderDisposable = languages.registerInlineValuesProvider({ language: 'python' }, new PythonInlineValueProvider());
220+
context.subscriptions.push(registerInlineValuesProviderDisposable);
221+
}
222+
}
223+
}));
206224

207225
context.subscriptions.push(
208226
debug.registerDebugVisualizationProvider('inlineHexDecoder', {

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,4 @@ suite('Debugging - pythonInlineProvider', () => {
514514
];
515515
expect(result).to.deep.equal(expected);
516516
});
517-
518-
test("Provider should return empty array if 'showPythonInlineValues' is false", async () => {
519-
getConfigurationStub.withArgs('debugpy').returns(createMoqConfiguration(false));
520-
const file = path.join(WS_ROOT, 'pythonFiles', 'testAssignmentExp.py');
521-
let document = await workspace.openTextDocument(file);
522-
const viewPort = new Range(0, 0, 6, 0);
523-
const context = { frameId: 0, stoppedLocation: new Range(3, 1, 3, 1) } as InlineValueContext;
524-
const inlineValueProvider = new PythonInlineValueProvider();
525-
526-
const result = await inlineValueProvider.provideInlineValues(document, viewPort, context);
527-
expect(result).to.deep.equal([]);
528-
});
529517
});

0 commit comments

Comments
 (0)