|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import * as vscode from 'vscode'; |
| 18 | +import { DebugProtocol } from '@vscode/debugprotocol'; |
18 | 19 | import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session'; |
19 | 20 |
|
20 | 21 | interface LiveWatchNode { |
21 | 22 | id: number; |
22 | 23 | expression: string; |
23 | 24 | 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 |
26 | 27 | } |
27 | 28 |
|
28 | | -export interface EvaluateNodeResponse { |
| 29 | +export interface LiveWatchValue { |
29 | 30 | result: string; |
30 | 31 | variablesReference: number; |
31 | 32 | } |
@@ -56,31 +57,28 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa |
56 | 57 | } |
57 | 58 | try { |
58 | 59 | 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 | + |
73 | 71 | // We do not store children of nodes in the tree, as they are dynamic |
74 | | - return Promise.resolve(childNodes); |
| 72 | + return childNodes; |
75 | 73 | } catch (error) { |
76 | 74 | console.error('Error fetching children:', error); |
77 | | - return Promise.resolve([]); |
| 75 | + return []; |
78 | 76 | } |
79 | 77 | } |
80 | 78 |
|
81 | 79 | public getTreeItem(element: LiveWatchNode): vscode.TreeItem { |
82 | 80 | const item = new vscode.TreeItem(element.expression + ' = '); |
83 | | - item.description = element.value.result || ''; |
| 81 | + item.description = element.value.result; |
84 | 82 | item.contextValue = 'expression'; |
85 | 83 | item.tooltip = element.expression; |
86 | 84 | item.collapsibleState = element.value.variablesReference !== 0 ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None; |
@@ -175,8 +173,8 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa |
175 | 173 | await this.rename(node, expression); |
176 | 174 | } |
177 | 175 |
|
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 }; |
180 | 178 | if (!this._activeSession) { |
181 | 179 | response.result = 'No active session'; |
182 | 180 | return response; |
|
0 commit comments