diff --git a/src/client/repl/variables/variablesProvider.ts b/src/client/repl/variables/variablesProvider.ts index 03c37188e690..f033451dc80e 100644 --- a/src/client/repl/variables/variablesProvider.ts +++ b/src/client/repl/variables/variablesProvider.ts @@ -38,7 +38,7 @@ export class VariablesProvider implements NotebookVariableProvider { const notebook = this.getNotebookDocument(); if (notebook) { this.executionCount += 1; - if (isEnabled()) { + if (isEnabled(notebook.uri)) { this._onDidChangeVariables.fire(notebook); } } @@ -52,7 +52,12 @@ export class VariablesProvider implements NotebookVariableProvider { token: CancellationToken, ): AsyncIterable { const notebookDocument = this.getNotebookDocument(); - if (!isEnabled() || token.isCancellationRequested || !notebookDocument || notebookDocument !== notebook) { + if ( + !isEnabled(notebook.uri) || + token.isCancellationRequested || + !notebookDocument || + notebookDocument !== notebook + ) { return; } diff --git a/src/test/repl/variableProvider.test.ts b/src/test/repl/variableProvider.test.ts index 1b151d34c096..4f76ba2e1588 100644 --- a/src/test/repl/variableProvider.test.ts +++ b/src/test/repl/variableProvider.test.ts @@ -2,16 +2,29 @@ // Licensed under the MIT License. import { assert } from 'chai'; -import { NotebookDocument, CancellationTokenSource, VariablesResult, Variable, EventEmitter } from 'vscode'; +import sinon from 'sinon'; +import { + NotebookDocument, + CancellationTokenSource, + VariablesResult, + Variable, + EventEmitter, + ConfigurationScope, + WorkspaceConfiguration, +} from 'vscode'; import * as TypeMoq from 'typemoq'; import { IVariableDescription } from '../../client/repl/variables/types'; import { VariablesProvider } from '../../client/repl/variables/variablesProvider'; import { VariableRequester } from '../../client/repl/variables/variableRequester'; +import * as workspaceApis from '../../client/common/vscodeApis/workspaceApis'; -suite('ReplVariablesProvider', () => { +suite.only('ReplVariablesProvider', () => { let provider: VariablesProvider; let varRequester: TypeMoq.IMock; let notebook: TypeMoq.IMock; + let getConfigurationStub: sinon.SinonStub; + let configMock: TypeMoq.IMock; + let enabled: boolean; const executionEventEmitter = new EventEmitter(); const cancellationToken = new CancellationTokenSource().token; @@ -68,9 +81,23 @@ suite('ReplVariablesProvider', () => { } setup(() => { + enabled = true; varRequester = TypeMoq.Mock.ofType(); notebook = TypeMoq.Mock.ofType(); provider = new VariablesProvider(varRequester.object, () => notebook.object, executionEventEmitter.event); + configMock = TypeMoq.Mock.ofType(); + configMock.setup((c) => c.get('REPL.provideVariables')).returns(() => enabled); + getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); + getConfigurationStub.callsFake((section?: string, _scope?: ConfigurationScope | null) => { + if (section === 'python') { + return configMock.object; + } + return undefined; + }); + }); + + teardown(() => { + sinon.restore(); }); test('provideVariables without parent should yield variables', async () => { @@ -84,6 +111,38 @@ suite('ReplVariablesProvider', () => { assert.equal(results[0].variable.expression, 'myObject'); }); + test('No variables are returned when variable provider is disabled', async () => { + enabled = false; + setVariablesForParent(undefined, [objectVariable]); + + const results = await provideVariables(undefined); + + assert.isEmpty(results); + }); + + test('No change event from provider when disabled', async () => { + enabled = false; + let eventFired = false; + provider.onDidChangeVariables(() => { + eventFired = true; + }); + + executionEventEmitter.fire(); + + assert.isFalse(eventFired, 'event should not have fired'); + }); + + test('Variables change event from provider should fire when execution happens', async () => { + let eventFired = false; + provider.onDidChangeVariables(() => { + eventFired = true; + }); + + executionEventEmitter.fire(); + + assert.isTrue(eventFired, 'event should have fired'); + }); + test('provideVariables with a parent should call get children correctly', async () => { const listVariableItems = [0, 1, 2].map(createListItem); setVariablesForParent(undefined, [objectVariable]);