Skip to content

Commit 6ed9d33

Browse files
committed
adding add to live watch command in both variables window and watch window
1 parent d86727c commit 6ed9d33

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

package.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,43 @@
116116
"category": "Live Watch"
117117
},
118118
{
119-
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatch",
119+
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatchFromTextEditor",
120+
"title": "Add To Live Watch",
121+
"category": "Live Watch"
122+
},
123+
{
124+
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatchFromWatchWindow",
125+
"title": "Add To Live Watch",
126+
"category": "Live Watch"
127+
},
128+
{
129+
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatchFromVariablesView",
120130
"title": "Add To Live Watch",
121131
"category": "Live Watch"
122132
}
123133
],
124134
"menus": {
125135
"editor/context": [
126136
{
127-
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatch",
137+
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatchFromTextEditor",
128138
"when": "editorTextFocus && resourceScheme == file",
129139
"group": "z_commands"
130140
}
131141
],
142+
"debug/variables/context": [
143+
{
144+
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatchFromVariablesView",
145+
"when": "inDebugMode",
146+
"group": "z_commands"
147+
}
148+
],
149+
"debug/watch/context": [
150+
{
151+
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatchFromWatchWindow",
152+
"when": "inDebugMode",
153+
"group": "z_commands"
154+
}
155+
],
132156
"commandPalette": [
133157
{
134158
"command": "vscode-cmsis-debugger.showCpuTimeHistory",
@@ -163,7 +187,7 @@
163187
"when": "false"
164188
},
165189
{
166-
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatch",
190+
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatchFromTextEditor",
167191
"when": "false"
168192
}
169193
],

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ describe('LiveWatchTreeDataProvider', () => {
277277
'vscode-cmsis-debugger.liveWatch.refresh',
278278
'vscode-cmsis-debugger.liveWatch.modify',
279279
'vscode-cmsis-debugger.liveWatch.copy',
280-
'vscode-cmsis-debugger.liveWatch.addToLiveWatch'
280+
'vscode-cmsis-debugger.liveWatch.addToLiveWatchFromTextEditor',
281+
'vscode-cmsis-debugger.liveWatch.addToLiveWatchFromWatchWindow',
282+
'vscode-cmsis-debugger.liveWatch.addToLiveWatchFromVariablesView'
281283
]));
282284
});
283285

@@ -354,6 +356,43 @@ describe('LiveWatchTreeDataProvider', () => {
354356
await handler();
355357
expect(refreshSpy).toHaveBeenCalled();
356358
});
359+
360+
it('watch window command adds variable name root', async () => {
361+
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue({ result: 'value', variablesReference: 0 });
362+
liveWatchTreeDataProvider.activate(tracker);
363+
const handler = getRegisteredHandler('vscode-cmsis-debugger.liveWatch.addToLiveWatchFromWatchWindow');
364+
expect(handler).toBeDefined();
365+
await handler({ variable: { name: 'myWatchVariable' } });
366+
const roots = (liveWatchTreeDataProvider as any).roots;
367+
expect(roots.length).toBe(1);
368+
expect(roots[0].expression).toBe('myWatchVariable');
369+
});
370+
371+
it('watch window command does nothing with falsy payload', async () => {
372+
liveWatchTreeDataProvider.activate(tracker);
373+
const handler = getRegisteredHandler('vscode-cmsis-debugger.liveWatch.addToLiveWatchFromWatchWindow');
374+
await handler(undefined);
375+
expect((liveWatchTreeDataProvider as any).roots.length).toBe(0);
376+
});
377+
378+
it('variables view command adds variable name root', async () => {
379+
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue({ result: '12345', variablesReference: 0 });
380+
liveWatchTreeDataProvider.activate(tracker);
381+
const handler = getRegisteredHandler('vscode-cmsis-debugger.liveWatch.addToLiveWatchFromVariablesView');
382+
expect(handler).toBeDefined();
383+
const payload = { container: { name: 'local' }, variable: { name: 'localVariable' } };
384+
await handler(payload);
385+
const roots = (liveWatchTreeDataProvider as any).roots;
386+
expect(roots.length).toBe(1);
387+
expect(roots[0].expression).toBe('localVariable');
388+
});
389+
390+
it('variables view command does nothing when variable missing', async () => {
391+
liveWatchTreeDataProvider.activate(tracker);
392+
const handler = getRegisteredHandler('vscode-cmsis-debugger.liveWatch.addToLiveWatchFromVariablesView');
393+
await handler({ container: { name: 'local' } });
394+
expect((liveWatchTreeDataProvider as any).roots.length).toBe(0);
395+
});
357396
});
358397

359398
describe('evaluate', () => {

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

100644100755
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
140140
const refreshCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.refresh', async () => await this.refresh());
141141
const modifyCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.modify', async (node) => await this.registerRenameCommand(node));
142142
const copyCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.copy', async (node) => { await this.registerCopyCommand(node); });
143-
const addToLiveWatchCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.addToLiveWatch', async () => { await this.registerAddFromSelectionCommand(); });
143+
const addToLiveWatchCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.addToLiveWatchFromTextEditor', async () => { await this.registerAddFromSelectionCommand(); });
144+
const addToLiveWatchFromWatchWindowCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.addToLiveWatchFromWatchWindow', async (expression) => { await this.registerAddToLiveWatchFromWatchWindow(expression); });
145+
const addToLiveWatchFromVariablesViewCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.addToLiveWatchFromVariablesView', async (payload: { container: DebugProtocol.Scope; variable: DebugProtocol.Variable;}) => { await this.registerAddToLiveWatchFromVariablesView(payload); });
144146
this._context.subscriptions.push(registerLiveWatchView,
145147
addCommand,
146-
deleteAllCommand, deleteCommand, refreshCommand, modifyCommand, copyCommand, addToLiveWatchCommand);
148+
deleteAllCommand, deleteCommand, refreshCommand, modifyCommand, copyCommand, addToLiveWatchCommand, addToLiveWatchFromWatchWindowCommand, addToLiveWatchFromVariablesViewCommand);
147149
}
148150

149151
private async registerAddCommand() {
@@ -199,6 +201,20 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
199201
await this.addToRoots(selectedText);
200202
}
201203

204+
private async registerAddToLiveWatchFromWatchWindow(expression: any) {
205+
if (!expression) {
206+
return;
207+
}
208+
await this.addToRoots(expression.variable.name);
209+
}
210+
211+
private async registerAddToLiveWatchFromVariablesView(payload: { container: DebugProtocol.Scope; variable: DebugProtocol.Variable;}) {
212+
if (!payload || !payload.variable) {
213+
return;
214+
}
215+
await this.addToRoots(payload.variable.name);
216+
}
217+
202218
private async evaluate(expression: string): Promise<LiveWatchValue> {
203219
const response: LiveWatchValue = { result: '', variablesReference: 0 };
204220
if (!this._activeSession) {

0 commit comments

Comments
 (0)