Skip to content

Commit 72a72fb

Browse files
committed
refactoring and taking reviews into consideration
1 parent 428fbb9 commit 72a72fb

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

__mocks__/vscode.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ const MockTreeItemCollapsibleState = {
3636
Expanded: 2
3737
};
3838

39-
const registerTreeDataProviderMock = jest.fn(() => ({ dispose: jest.fn() }));
40-
4139
class MockTreeItem {
4240
label;
4341
description;
@@ -73,7 +71,7 @@ module.exports = {
7371
warn: jest.fn(),
7472
error: jest.fn(),
7573
})),
76-
registerTreeDataProvider: registerTreeDataProviderMock,
74+
registerTreeDataProvider: jest.fn(() => ({ dispose: jest.fn() })),
7775
showWarningMessage: jest.fn(),
7876
createStatusBarItem: jest.fn(),
7977
showQuickPick: jest.fn(),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"activitybar": [
5252
{
5353
"id": "cmsis-debugger",
54-
"title": "CMSIS Debug",
54+
"title": "Trace and Live View",
5555
"icon": "images/trace-and-live-dark.svg"
5656
}
5757
]

src/debug-session/gdbtarget-debug-session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class GDBTargetDebugSession {
5454
this._cbuildRunParsePromise = undefined;
5555
}
5656

57+
/** Function returns string only in case of failure */
5758
public async evaluateGlobalExpression(expression: string, context = 'hover'): Promise<DebugProtocol.EvaluateResponse['body'] | string> {
5859
try {
5960
const frameId = (vscode.debug.activeStackItem as vscode.DebugStackFrame)?.frameId ?? 0;

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

Lines changed: 2 additions & 2 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 { EvaluateNodeResponse, LiveWatchTreeDataProvider } from './live-watch';
20+
import { LiveWatchValue, LiveWatchTreeDataProvider } 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,7 +31,7 @@ describe('LiveWatchTreeDataProvider', () => {
3131
let debugConfig: GDBTargetConfiguration;
3232

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

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
*/
1616

1717
import * as vscode from 'vscode';
18+
import { DebugProtocol } from '@vscode/debugprotocol';
1819
import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session';
1920

2021
interface LiveWatchNode {
2122
id: number;
2223
expression: string;
2324
parent: LiveWatchNode | undefined; // if undefined, it's a root node
24-
children: LiveWatchNode[]; // keep for future grouping; flat list for now
25-
value: EvaluateNodeResponse
25+
children: LiveWatchNode[];
26+
value: LiveWatchValue
2627
}
2728

28-
export interface EvaluateNodeResponse {
29+
export interface LiveWatchValue {
2930
result: string;
3031
variablesReference: number;
3132
}
@@ -56,31 +57,28 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
5657
}
5758
try {
5859
const children = await this._activeSession?.session.customRequest('variables', { variablesReference: element.value.variablesReference });
59-
const childNodes: LiveWatchNode[] = [];
60-
for(const child of children?.variables || []) {
61-
const childNode: LiveWatchNode = {
62-
id: this.nodeID++,
63-
expression: child.name,
64-
children: [],
65-
parent: element,
66-
value: {
67-
result: child.value,
68-
variablesReference: child.variablesReference
69-
}
70-
};
71-
childNodes.push(childNode);
72-
}
60+
const childNodes = children?.variables.map((child: DebugProtocol.Variable) => ({
61+
id: this.nodeID++,
62+
expression: child.name,
63+
children: [],
64+
parent: element,
65+
value: {
66+
result: child.value,
67+
variablesReference: child.variablesReference
68+
}
69+
})) ?? [];
70+
7371
// We do not store children of nodes in the tree, as they are dynamic
74-
return Promise.resolve(childNodes);
72+
return childNodes;
7573
} catch (error) {
7674
console.error('Error fetching children:', error);
77-
return Promise.resolve([]);
75+
return [];
7876
}
7977
}
8078

8179
public getTreeItem(element: LiveWatchNode): vscode.TreeItem {
8280
const item = new vscode.TreeItem(element.expression + ' = ');
83-
item.description = element.value.result || '';
81+
item.description = element.value.result;
8482
item.contextValue = 'expression';
8583
item.tooltip = element.expression;
8684
item.collapsibleState = element.value.variablesReference !== 0 ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None;
@@ -175,8 +173,8 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
175173
await this.rename(node, expression);
176174
}
177175

178-
private async evaluate(expression: string): Promise<EvaluateNodeResponse> {
179-
const response: EvaluateNodeResponse = { result: '', variablesReference: 0 };
176+
private async evaluate(expression: string): Promise<LiveWatchValue> {
177+
const response: LiveWatchValue = { result: '', variablesReference: 0 };
180178
if (!this._activeSession) {
181179
response.result = 'No active session';
182180
return response;

0 commit comments

Comments
 (0)