Skip to content

Commit 6f37e4e

Browse files
authored
Biring debug console to front on debug session start (#70)
* debug tracker + bring console to front on session start * tests --------- Signed-off-by: Jens Reinecke <[email protected]>
1 parent 2d2e897 commit 6f37e4e

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22

33
## Unreleased
4+
- Implemented [#69](https://github.com/Open-CMSIS-Pack/vscode-cmsis-debugger/issues/69): Bring Debug Console to front during connection.
5+
6+
## 0.0.1
47
- Initial release of extension pack on GitHub.
58
- Adds pseudo debugger types `cmsis-debug-pyocd` and `cmsis-debug-jlink`.
69
- Adds debug configuration providers for debugger type `gdbtarget` to resolve settings for pyOCD and Segger J-Link GDB server connections.

__mocks__/vscode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ module.exports = {
5353
},
5454
debug: {
5555
registerDebugConfigurationProvider: jest.fn(),
56+
registerDebugAdapterTrackerFactory: jest.fn(),
5657
},
5758
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 { GDBTargetDebugTracker } from './gdbtarget-debug-tracker';
18+
import { extensionContextFactory } from '../__test__/vscode.factory';
19+
20+
import * as vscode from 'vscode';
21+
22+
describe('GDBTargetDebugTracker', () => {
23+
24+
it('should activate', async () => {
25+
const debugTracker = new GDBTargetDebugTracker();
26+
const contextMock = extensionContextFactory();
27+
28+
debugTracker.activate(contextMock);
29+
30+
expect(contextMock.subscriptions).toHaveLength(1);
31+
expect(vscode.debug.registerDebugAdapterTrackerFactory as jest.Mock).toHaveBeenCalledWith('gdbtarget', expect.objectContaining({ createDebugAdapterTracker: expect.any(Function) }));
32+
});
33+
34+
it('brings the debug console to front \'onWillStartSession\' is called', async () => {
35+
const debugTracker = new GDBTargetDebugTracker();
36+
37+
debugTracker.onWillStartSession();
38+
39+
expect(vscode.commands.executeCommand as jest.Mock).toHaveBeenCalledWith('workbench.debug.action.focusRepl');
40+
});
41+
42+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
19+
const GDB_TARGET_DEBUGGER_TYPE = 'gdbtarget';
20+
21+
export class GDBTargetDebugTracker implements vscode.DebugAdapterTracker {
22+
23+
public activate(context: vscode.ExtensionContext) {
24+
// Use vscode debug tracker
25+
const createDebugAdapterTracker = (_session: vscode.DebugSession): vscode.DebugAdapterTracker => ({
26+
onWillStartSession: () => this.onWillStartSession.apply(this)
27+
});
28+
29+
context.subscriptions.push(
30+
vscode.debug.registerDebugAdapterTrackerFactory(GDB_TARGET_DEBUGGER_TYPE, { createDebugAdapterTracker })
31+
);
32+
}
33+
34+
public onWillStartSession(): void {
35+
// Bring debug console to front, let promise float.
36+
vscode.commands.executeCommand('workbench.debug.action.focusRepl');
37+
}
38+
39+
}

src/desktop/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
*/
1616

1717
import * as vscode from 'vscode';
18+
import { GDBTargetDebugTracker } from '../debug-configuration/gdbtarget-debug-tracker';
1819
import { GDBTargetConfigurationProvider } from '../debug-configuration';
1920
import { logger } from '../logger';
2021

2122
export const activate = async (context: vscode.ExtensionContext): Promise<void> => {
23+
const gdbtargetDebugTracker = new GDBTargetDebugTracker();
2224
const gdbtargetConfigurationProvider = new GDBTargetConfigurationProvider();
2325

2426
// Activate components
27+
gdbtargetDebugTracker.activate(context);
2528
gdbtargetConfigurationProvider.activate(context);
2629

2730
logger.debug('Extension Pack activated');

0 commit comments

Comments
 (0)