Skip to content

Commit 0e78035

Browse files
committed
Updating NodeID logic and editing naming of commands
1 parent a633563 commit 0e78035

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"activitybar": [
5151
{
5252
"id": "cmsis-debugger",
53-
"title": "CMSIS-Debug",
53+
"title": "CMSIS Debug",
5454
"icon": "$(rocket)"
5555
}
5656
]
@@ -85,12 +85,12 @@
8585
},
8686
{
8787
"command": "cmsis-debugger.liveWatch.deleteAll",
88-
"title": "Delete All",
88+
"title": "Delete All Expressions",
8989
"icon": "$(close-all)"
9090
},
9191
{
9292
"command": "cmsis-debugger.liveWatch.delete",
93-
"title": "Delete",
93+
"title": "Delete Expression",
9494
"icon": "$(close)"
9595
},
9696
{
@@ -100,7 +100,7 @@
100100
},
101101
{
102102
"command": "cmsis-debugger.liveWatch.modify",
103-
"title": "Modify",
103+
"title": "Modify Expression",
104104
"icon": "$(pencil)"
105105
}
106106
],

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

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,35 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
3232
readonly onDidChangeTreeData: vscode.Event<LiveWatchNode | void> = this._onDidChangeTreeData.event;
3333

3434
private roots: LiveWatchNode[] = [];
35-
private numberOfNodes: number;
35+
private NodeID: number;
3636
private _context: vscode.ExtensionContext;
3737
private activeSession: GDBTargetDebugSession | undefined;
3838

3939
constructor(private readonly context: vscode.ExtensionContext) {
4040
this.roots = this.context.workspaceState.get<LiveWatchNode[]>(this.STORAGE_KEY) ?? [];
4141
this._context = context;
42-
this.numberOfNodes = this.roots.length;
42+
this.NodeID = 0;
43+
for (const node of this.roots) {
44+
node.id = this.NodeID;
45+
this.NodeID++;
46+
}
4347
}
4448

45-
getChildren(element?: LiveWatchNode): Promise<LiveWatchNode[]> {
49+
public getChildren(element?: LiveWatchNode): Promise<LiveWatchNode[]> {
4650
if (!element) {
4751
return Promise.resolve(this.roots);
4852
}
4953
return Promise.resolve(element.children ?? []);
5054
}
5155

52-
getTreeItem(element: LiveWatchNode): vscode.TreeItem {
56+
public getTreeItem(element: LiveWatchNode): vscode.TreeItem {
5357
const item = new vscode.TreeItem(element.expression, vscode.TreeItemCollapsibleState.None);
5458
item.description = element.value || '';
5559
item.contextValue = 'expression';
5660
return item;
5761
}
5862

59-
getNumberOfNodes(): number {
60-
return this.roots.length;
61-
}
62-
63-
async activate(tracker: GDBTargetDebugTracker): Promise<void> {
63+
public async activate(tracker: GDBTargetDebugTracker): Promise<void> {
6464
this.addVSCodeCommands();
6565
const onDidChangeActiveDebugSession = tracker.onDidChangeActiveDebugSession(async (session) => await this.handleOnDidChangeActiveDebugSession(session));
6666
const onWillStartSession = tracker.onWillStartSession(async (session) => await this.handleOnWillStartSession(session));
@@ -78,11 +78,16 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
7878
const onContinued = tracker.onContinued(async () => {
7979
await this.refresh();
8080
});
81-
this._context.subscriptions.push(onContinued, onDidChangeActiveDebugSession, onWillStartSession, onStopped, onStackTrace, onWillStopSession);
81+
this._context.subscriptions.push(onContinued,
82+
onDidChangeActiveDebugSession,
83+
onWillStartSession,
84+
onStopped,
85+
onStackTrace,
86+
onWillStopSession);
8287
}
8388

84-
async deactivate(): Promise<void> {
85-
this.save();
89+
public async deactivate(): Promise<void> {
90+
await this.save();
8691
}
8792

8893
private async handleOnDidChangeActiveDebugSession(session: GDBTargetDebugSession | undefined): Promise<void> {
@@ -104,12 +109,16 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
104109
const deleteCommand = vscode.commands.registerCommand('cmsis-debugger.liveWatch.delete', async (node) => await this.registerDeleteCommand(node));
105110
const refreshCommand = vscode.commands.registerCommand('cmsis-debugger.liveWatch.refresh', async () => await this.refresh());
106111
const modifyCommand = vscode.commands.registerCommand('cmsis-debugger.liveWatch.modify', async (node) => await this.registerRenameCommand(node));
107-
this._context.subscriptions.push(registerLiveWatchView, addCommand, deleteAllCommand, deleteCommand, refreshCommand, modifyCommand);
112+
this._context.subscriptions.push(registerLiveWatchView,
113+
addCommand,
114+
deleteAllCommand, deleteCommand, refreshCommand, modifyCommand);
108115
}
109116

110117
private async registerAddCommand() {
111118
const expression = await vscode.window.showInputBox({ prompt: 'Expression' });
112-
if (!expression) return;
119+
if (!expression) {
120+
return;
121+
}
113122
await this.add(expression);
114123
}
115124

@@ -118,19 +127,24 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
118127
}
119128

120129
private async registerDeleteCommand(node: LiveWatchNode) {
121-
if (!node) return;
130+
if (!node) {
131+
return;
132+
}
122133
await this.delete(node);
123134
}
124135

125136
private async registerRenameCommand(node: LiveWatchNode) {
126-
if (!node) return;
137+
if (!node) {
138+
return;
139+
}
127140
const expression = await vscode.window.showInputBox({ prompt: 'Expression', value: node.expression });
128-
if (!expression) return;
141+
if (!expression) {
142+
return;
143+
}
129144
await this.rename(node, expression);
130145
}
131146

132147
private async evaluate(expression: string): Promise<string> {
133-
console.log('Evaluating expression:', expression);
134148
if (!this.activeSession) {
135149
return 'No active session';
136150
}
@@ -141,7 +155,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
141155
private async add(expression: string, parent?: LiveWatchNode) {
142156
// Create a new node with a unique ID and evaluate its value
143157
const newNode: LiveWatchNode = {
144-
id: this.numberOfNodes + 1,
158+
id: this.NodeID + 1,
145159
expression,
146160
value : await this.evaluate(expression),
147161
parent: parent ?? undefined
@@ -151,7 +165,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
151165
} else {
152166
parent.children?.push(newNode);
153167
}
154-
this.numberOfNodes++;
168+
this.NodeID++;
155169
await this.refresh();
156170
}
157171

0 commit comments

Comments
 (0)