Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/views/live-watch/live-watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/views/live-watch/live-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +30,7 @@ export interface LiveWatchValue {
result: string;
variablesReference: number;
type?: string;
evaluateName?: string;
}

export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWatchNode> {
Expand Down Expand Up @@ -65,7 +66,9 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
parent: element,
value: {
result: child.value,
variablesReference: child.variablesReference
variablesReference: child.variablesReference,
type: child.type,
evaluateName: child.evaluateName
}
})) ?? [];

Expand All @@ -81,7 +84,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
const item = new vscode.TreeItem(element.expression + ' = ');
item.description = element.value.result;
item.contextValue = 'expression';
item.tooltip = element.value.type;
item.tooltip = element.value.type ?? '';
item.collapsibleState = element.value.variablesReference !== 0 ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None;
return item;
}
Expand Down Expand Up @@ -203,7 +206,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
if(!node) {
return;
}
await vscode.env.clipboard.writeText(node.expression);
await vscode.env.clipboard.writeText(node.value.evaluateName ?? node.expression);
}

private async handleAddFromSelectionCommand() {
Expand Down