diff --git a/src/views/live-watch/live-watch.test.ts b/src/views/live-watch/live-watch.test.ts index 6244450f..a1203051 100644 --- a/src/views/live-watch/live-watch.test.ts +++ b/src/views/live-watch/live-watch.test.ts @@ -17,7 +17,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import * as vscode from 'vscode'; import { debugSessionFactory, extensionContextFactory } from '../../__test__/vscode.factory'; -import { LiveWatchValue, LiveWatchTreeDataProvider } from './live-watch'; +import { LiveWatchValue, LiveWatchTreeDataProvider, LiveWatchNode } from './live-watch'; import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session'; import { gdbTargetConfiguration } from '../../debug-configuration/debug-configuration.factory'; import { GDBTargetConfiguration } from '../../debug-configuration'; @@ -31,8 +31,8 @@ describe('LiveWatchTreeDataProvider', () => { let debugConfig: GDBTargetConfiguration; // Helper: create a dummy node - function makeNode(expression = 'x', value: LiveWatchValue = { result: '1', variablesReference: 0 }, id = 1) { - return { id, expression, value, parent: undefined, children: [] }; + function makeNode(expression = 'x', value: LiveWatchValue = { result: '1', variablesReference: 0 }, id = 1, parent?: LiveWatchNode) { + return { id, expression, value, parent: parent, children: [] }; } beforeEach(() => { @@ -193,13 +193,31 @@ describe('LiveWatchTreeDataProvider', () => { expect(node.expression).toBe('node-1-renamed'); }); - it('copy copies node expression to clipboard', async () => { + it('copies node expression to clipboard', async () => { const node = makeNode('node-to-copy', { result: '1', variablesReference: 0 }, 1); (liveWatchTreeDataProvider as any).roots = [node]; await (liveWatchTreeDataProvider as any).handleCopyCommand(node); expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('node-to-copy'); }); + it('copies evaluateName of children to clipboard when present', async () => { + const child = makeNode('childName', { + result: '42', + variablesReference: 0, + evaluateName: 'parent.childName' + }, 2); + (liveWatchTreeDataProvider as any).roots = [child]; + await (liveWatchTreeDataProvider as any).handleCopyCommand(child); + expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('parent.childName'); + }); + + it('copies expression to clipboard when evaluateName not present', async () => { + const node = makeNode('myExpression', { result: '123', variablesReference: 0 }, 1); + (liveWatchTreeDataProvider as any).roots = [node]; + await (liveWatchTreeDataProvider as any).handleCopyCommand(node); + expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('myExpression'); + }); + it('AddFromSelection adds selected text as new live watch expression to roots', async () => { jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue({ result: '5678', variablesReference: 0 }); // Mock the active text editor with a selection whose active position returns a word range diff --git a/src/views/live-watch/live-watch.ts b/src/views/live-watch/live-watch.ts index 7b0f72fe..b242c177 100644 --- a/src/views/live-watch/live-watch.ts +++ b/src/views/live-watch/live-watch.ts @@ -18,7 +18,7 @@ import * as vscode from 'vscode'; import { DebugProtocol } from '@vscode/debugprotocol'; import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session'; -interface LiveWatchNode { +export interface LiveWatchNode { id: number; expression: string; parent: LiveWatchNode | undefined; // if undefined, it's a root node @@ -30,6 +30,7 @@ export interface LiveWatchValue { result: string; variablesReference: number; type?: string; + evaluateName?: string; } export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider { @@ -65,7 +66,9 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider