diff --git a/src/kernels/variables/JupyterVariableProvider.unit.test.ts b/src/kernels/variables/JupyterVariableProvider.unit.test.ts index 51ae8482e29..3fdb83c3566 100644 --- a/src/kernels/variables/JupyterVariableProvider.unit.test.ts +++ b/src/kernels/variables/JupyterVariableProvider.unit.test.ts @@ -82,6 +82,7 @@ suite('JupyterVariablesProvider', () => { assert.isNotEmpty(results); assert.equal(results.length, 1); assert.equal(results[0].variable.name, 'myObject'); + assert.equal(results[0].variable.expression, 'myObject'); }); test('provideVariables with a parent should call get children correctly', async () => { @@ -98,11 +99,13 @@ suite('JupyterVariablesProvider', () => { const listItems = await provideVariables(listResult!.variable, 2); assert.equal(listResult.variable.name, 'myList'); + assert.equal(listResult.variable.expression, 'myObject.myList'); assert.isNotEmpty(listItems); assert.equal(listItems.length, 3); listItems.forEach((item, index) => { assert.equal(item.variable.name, index.toString()); assert.equal(item.variable.value, `value${index}`); + assert.equal(item.variable.expression, `myObject.myList[${index}]`); }); }); diff --git a/src/kernels/variables/JupyterVariablesProvider.ts b/src/kernels/variables/JupyterVariablesProvider.ts index ddd50571fa0..0b01cf3a753 100644 --- a/src/kernels/variables/JupyterVariablesProvider.ts +++ b/src/kernels/variables/JupyterVariablesProvider.ts @@ -95,6 +95,7 @@ export class JupyterVariablesProvider implements NotebookVariableProvider { const indexedChildrenCount = result.count ?? 0; const variable = { getChildren: (start: number, token: CancellationToken) => this.getChildren(variable, start, kernel, token), + expression: createExpression(result.root, result.propertyChain), ...result } as Variable; return { variable, hasNamedChildren, indexedChildrenCount }; @@ -110,3 +111,15 @@ export class JupyterVariablesProvider implements NotebookVariableProvider { return await this.variables.getAllVariableDiscriptions(kernel, parent, start, token); } } + +function createExpression(root: string, propertyChain: (string | number)[]): string { + let expression = root; + for (const property of propertyChain) { + if (typeof property === 'string') { + expression += `.${property}`; + } else { + expression += `[${property}]`; + } + } + return expression; +}