Skip to content

Commit 73063bf

Browse files
authored
adjusting how children are added to clipboard (#605)
1 parent a75df49 commit 73063bf

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/views/live-watch/live-watch.test.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* eslint-disable @typescript-eslint/no-explicit-any */
1818
import * as vscode from 'vscode';
1919
import { debugSessionFactory, extensionContextFactory } from '../../__test__/vscode.factory';
20-
import { LiveWatchValue, LiveWatchTreeDataProvider } from './live-watch';
20+
import { LiveWatchValue, LiveWatchTreeDataProvider, LiveWatchNode } from './live-watch';
2121
import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session';
2222
import { gdbTargetConfiguration } from '../../debug-configuration/debug-configuration.factory';
2323
import { GDBTargetConfiguration } from '../../debug-configuration';
@@ -31,8 +31,8 @@ describe('LiveWatchTreeDataProvider', () => {
3131
let debugConfig: GDBTargetConfiguration;
3232

3333
// Helper: create a dummy node
34-
function makeNode(expression = 'x', value: LiveWatchValue = { result: '1', variablesReference: 0 }, id = 1) {
35-
return { id, expression, value, parent: undefined, children: [] };
34+
function makeNode(expression = 'x', value: LiveWatchValue = { result: '1', variablesReference: 0 }, id = 1, parent?: LiveWatchNode) {
35+
return { id, expression, value, parent: parent, children: [] };
3636
}
3737

3838
beforeEach(() => {
@@ -193,13 +193,31 @@ describe('LiveWatchTreeDataProvider', () => {
193193
expect(node.expression).toBe('node-1-renamed');
194194
});
195195

196-
it('copy copies node expression to clipboard', async () => {
196+
it('copies node expression to clipboard', async () => {
197197
const node = makeNode('node-to-copy', { result: '1', variablesReference: 0 }, 1);
198198
(liveWatchTreeDataProvider as any).roots = [node];
199199
await (liveWatchTreeDataProvider as any).handleCopyCommand(node);
200200
expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('node-to-copy');
201201
});
202202

203+
it('copies evaluateName of children to clipboard when present', async () => {
204+
const child = makeNode('childName', {
205+
result: '42',
206+
variablesReference: 0,
207+
evaluateName: 'parent.childName'
208+
}, 2);
209+
(liveWatchTreeDataProvider as any).roots = [child];
210+
await (liveWatchTreeDataProvider as any).handleCopyCommand(child);
211+
expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('parent.childName');
212+
});
213+
214+
it('copies expression to clipboard when evaluateName not present', async () => {
215+
const node = makeNode('myExpression', { result: '123', variablesReference: 0 }, 1);
216+
(liveWatchTreeDataProvider as any).roots = [node];
217+
await (liveWatchTreeDataProvider as any).handleCopyCommand(node);
218+
expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('myExpression');
219+
});
220+
203221
it('AddFromSelection adds selected text as new live watch expression to roots', async () => {
204222
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue({ result: '5678', variablesReference: 0 });
205223
// Mock the active text editor with a selection whose active position returns a word range

src/views/live-watch/live-watch.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as vscode from 'vscode';
1818
import { DebugProtocol } from '@vscode/debugprotocol';
1919
import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session';
2020

21-
interface LiveWatchNode {
21+
export interface LiveWatchNode {
2222
id: number;
2323
expression: string;
2424
parent: LiveWatchNode | undefined; // if undefined, it's a root node
@@ -30,6 +30,7 @@ export interface LiveWatchValue {
3030
result: string;
3131
variablesReference: number;
3232
type?: string;
33+
evaluateName?: string;
3334
}
3435

3536
export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWatchNode> {
@@ -65,7 +66,9 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
6566
parent: element,
6667
value: {
6768
result: child.value,
68-
variablesReference: child.variablesReference
69+
variablesReference: child.variablesReference,
70+
type: child.type,
71+
evaluateName: child.evaluateName
6972
}
7073
})) ?? [];
7174

@@ -81,7 +84,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
8184
const item = new vscode.TreeItem(element.expression + ' = ');
8285
item.description = element.value.result;
8386
item.contextValue = 'expression';
84-
item.tooltip = element.value.type;
87+
item.tooltip = element.value.type ?? '';
8588
item.collapsibleState = element.value.variablesReference !== 0 ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None;
8689
return item;
8790
}
@@ -203,7 +206,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
203206
if(!node) {
204207
return;
205208
}
206-
await vscode.env.clipboard.writeText(node.expression);
209+
await vscode.env.clipboard.writeText(node.value.evaluateName ?? node.expression);
207210
}
208211

209212
private async handleAddFromSelectionCommand() {

0 commit comments

Comments
 (0)