Skip to content

Commit 487c8c7

Browse files
authored
Show "Open Disassembly View" in gutter context menu (#641)
* Add 'vscode-cmsis-debugger.openDisassemblyView' command which wraps VS Code built-in 'debug.action.openDisassemblyView' command. * Contribute new command to gutter context menu --------- Signed-off-by: Jens Reinecke <[email protected]>
1 parent f45c145 commit 487c8c7

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
]
6666
},
6767
"commands": [
68+
{
69+
"command": "vscode-cmsis-debugger.openDisassemblyView",
70+
"title": "Open Disassembly View",
71+
"category": "Run and Debug",
72+
"when": "inDebugMode"
73+
},
6874
{
6975
"title": "CPU Time",
7076
"shortTitle": "CPU Time",
@@ -143,6 +149,13 @@
143149
"group": "z_commands"
144150
}
145151
],
152+
"editor/lineNumber/context": [
153+
{
154+
"command": "vscode-cmsis-debugger.openDisassemblyView",
155+
"when": "inDebugMode",
156+
"group": "z_commands"
157+
}
158+
],
146159
"debug/variables/context": [
147160
{
148161
"command": "vscode-cmsis-debugger.liveWatch.addToLiveWatchFromVariablesView",
@@ -158,6 +171,10 @@
158171
}
159172
],
160173
"commandPalette": [
174+
{
175+
"command": "vscode-cmsis-debugger.openDisassemblyView",
176+
"when": "false"
177+
},
161178
{
162179
"command": "vscode-cmsis-debugger.showCpuTimeHistory",
163180
"when": "inDebugMode"

src/desktop/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { CpuStatesStatusBarItem } from '../features/cpu-states/cpu-states-status
2323
import { CpuStates } from '../features/cpu-states/cpu-states';
2424
import { CpuStatesCommands } from '../features/cpu-states/cpu-states-commands';
2525
import { LiveWatchTreeDataProvider } from '../views/live-watch/live-watch';
26+
import { GenericCommands } from '../features/generic-commands';
2627

2728
const BUILTIN_TOOLS_PATHS = [
2829
'tools/pyocd/pyocd',
@@ -32,6 +33,7 @@ const BUILTIN_TOOLS_PATHS = [
3233
let liveWatchTreeDataProvider: LiveWatchTreeDataProvider;
3334

3435
export const activate = async (context: vscode.ExtensionContext): Promise<void> => {
36+
const genericCommands = new GenericCommands();
3537
const gdbtargetDebugTracker = new GDBTargetDebugTracker();
3638
const gdbtargetConfigurationProvider = new GDBTargetConfigurationProvider();
3739
const cpuStates = new CpuStates();
@@ -41,6 +43,8 @@ export const activate = async (context: vscode.ExtensionContext): Promise<void>
4143
liveWatchTreeDataProvider = new LiveWatchTreeDataProvider(context);
4244

4345
addToolsToPath(context, BUILTIN_TOOLS_PATHS);
46+
// Activate generic commands
47+
genericCommands.activate(context);
4448
// Activate components
4549
gdbtargetDebugTracker.activate(context);
4650
gdbtargetConfigurationProvider.activate(context);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright 2025 Arm Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as vscode from 'vscode';
18+
import { extensionContextFactory } from '../__test__/vscode.factory';
19+
import { GenericCommands } from './generic-commands';
20+
21+
describe('GenericCommands', () => {
22+
let context: vscode.ExtensionContext;
23+
let genericCommands: GenericCommands;
24+
let registeredCommands: Map<string, () => Promise<void>>;
25+
26+
beforeEach(() => {
27+
context = extensionContextFactory();
28+
genericCommands = new GenericCommands();
29+
registeredCommands = new Map();
30+
(vscode.commands.registerCommand as jest.Mock).mockImplementation(async (command: string, handler: () => Promise<void>) => {
31+
registeredCommands.set(command, handler);
32+
});
33+
(vscode.commands.executeCommand as jest.Mock).mockImplementation(async (command: string) => {
34+
const handler = registeredCommands.get(command);
35+
if (handler) {
36+
await handler();
37+
}
38+
});
39+
});
40+
41+
it('registers expected commands', () => {
42+
genericCommands.activate(context);
43+
expect(vscode.commands.registerCommand as jest.Mock).toHaveBeenCalledWith(GenericCommands.openDisassemblyViewID, expect.any(Function));
44+
});
45+
46+
it('calls \'debug.action.openDisassemblyView\' command', async () => {
47+
genericCommands.activate(context);
48+
await vscode.commands.executeCommand(GenericCommands.openDisassemblyViewID);
49+
expect(vscode.commands.executeCommand as jest.Mock).toHaveBeenCalledWith('debug.action.openDisassemblyView');
50+
});
51+
52+
});

src/features/generic-commands.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright 2025 Arm Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as vscode from 'vscode';
18+
import { EXTENSION_NAME } from '../manifest';
19+
20+
export class GenericCommands {
21+
public static readonly openDisassemblyViewID = `${EXTENSION_NAME}.openDisassemblyView`;
22+
23+
public activate(context: vscode.ExtensionContext): void {
24+
// Register item and command
25+
context.subscriptions.push(
26+
vscode.commands.registerCommand(GenericCommands.openDisassemblyViewID, () => this.handleOpenDisassemblyView()),
27+
);
28+
}
29+
30+
protected async handleOpenDisassemblyView(): Promise<void> {
31+
vscode.commands.executeCommand('debug.action.openDisassemblyView');
32+
}
33+
};

0 commit comments

Comments
 (0)