Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit c02b07b

Browse files
authored
Adopt the new VSCode Debug API. (#432)
1 parent 7f8150a commit c02b07b

File tree

5 files changed

+105
-156
lines changed

5 files changed

+105
-156
lines changed

package.json

+5-42
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"aiKey": "83dd2c27-6594-41d3-85a9-bdb22070eb42",
88
"preview": true,
99
"engines": {
10-
"vscode": "^1.13.0"
10+
"vscode": "^1.17.0"
1111
},
1212
"icon": "images/arduino.png",
1313
"license": "SEE LICENSE IN LICENSE.txt",
@@ -34,7 +34,6 @@
3434
],
3535
"activationEvents": [
3636
"*",
37-
"onCommand:arduino.debug.startSession",
3837
"onCommand:arduino.verify",
3938
"onCommand:arduino.upload",
4039
"onCommand:arduino.selectSerialPort",
@@ -48,7 +47,8 @@
4847
"onCommand:arduino.showBoardManager",
4948
"onCommand:arduino.showLibraryManager",
5049
"onCommand:arduino.showExamples",
51-
"onCommand:arduino.initialize"
50+
"onCommand:arduino.initialize",
51+
"onDebug"
5252
],
5353
"main": "./out/src/extension",
5454
"contributes": {
@@ -129,7 +129,6 @@
129129
{
130130
"type": "arduino",
131131
"label": "Arduino",
132-
"startSessionCommand": "arduino.debug.startSession",
133132
"enableBreakpointsFor": {
134133
"languageIds": [
135134
"c",
@@ -145,7 +144,7 @@
145144
"type": "arduino",
146145
"request": "launch",
147146
"program": "$${{file}}",
148-
"cwd": "$${{workspaceRoot}}",
147+
"cwd": "$${{workspaceFolder}}",
149148
"MIMode": "gdb",
150149
"targetArchitecture": "arm",
151150
"miDebuggerPath": "",
@@ -176,42 +175,6 @@
176175
}
177176
}
178177
],
179-
"initialConfigurations": [
180-
{
181-
"name": "Arduino",
182-
"type": "arduino",
183-
"request": "launch",
184-
"program": "${file}",
185-
"cwd": "${workspaceRoot}",
186-
"MIMode": "gdb",
187-
"targetArchitecture": "arm",
188-
"miDebuggerPath": "",
189-
"debugServerPath": "",
190-
"debugServerArgs": "",
191-
"customLaunchSetupCommands": [
192-
{
193-
"text": "target remote localhost:3333"
194-
},
195-
{
196-
"text": "file ${file}"
197-
},
198-
{
199-
"text": "load"
200-
},
201-
{
202-
"text": "monitor reset halt"
203-
},
204-
{
205-
"text": "monitor reset init"
206-
}
207-
],
208-
"stopAtEntry": true,
209-
"serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
210-
"launchCompleteCommand": "exec-continue",
211-
"filterStderr": true,
212-
"args": []
213-
}
214-
],
215178
"configurationAttributes": {
216179
"launch": {
217180
"required": [
@@ -221,7 +184,7 @@
221184
"program": {
222185
"type": "string",
223186
"description": "Full path to program executable.",
224-
"default": "${workspaceRoot}/arduino.elf"
187+
"default": "${workspaceFolder}/arduino.elf"
225188
},
226189
"args": {
227190
"type": "array",

src/arduinoContext.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import { ArduinoApp } from "./arduino/arduino";
55
import { BoardManager } from "./arduino/boardManager";
6-
import { DebugConfigurator } from "./debug/configurator";
76
import { DebuggerManager } from "./debug/debuggerManager";
87
import { DeviceContext } from "./deviceContext";
98

@@ -28,26 +27,19 @@ class ArduinoContext {
2827
this._boardManager = value;
2928
}
3029

31-
public get arduinoConfigurator(): DebugConfigurator {
32-
if (this._arduinoConfigurator === null) {
33-
const debuggerManager = new DebuggerManager(
30+
public get debuggerManager(): DebuggerManager {
31+
if (this._debuggerManager === null) {
32+
this._debuggerManager = new DebuggerManager(
3433
DeviceContext.getInstance().extensionPath,
3534
this.arduinoApp.settings,
3635
this.boardManager);
37-
debuggerManager.initialize();
38-
this._arduinoConfigurator = new DebugConfigurator(
39-
this.arduinoApp, this.arduinoApp.settings
40-
, this.boardManager, debuggerManager);
36+
this._debuggerManager.initialize();
4137
}
42-
return this._arduinoConfigurator;
43-
}
44-
45-
public set arduinoConfigurator(value: DebugConfigurator) {
46-
this._arduinoConfigurator = value;
38+
return this._debuggerManager;
4739
}
4840

4941
private _arduinoApp: ArduinoApp = null;
50-
private _arduinoConfigurator: DebugConfigurator = null;
42+
private _debuggerManager: DebuggerManager = null;
5143
private _boardManager: BoardManager = null;
5244
}
5345

src/debug/configurator.ts renamed to src/debug/configurationProvider.ts

+71-65
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,69 @@ import * as path from "path";
55
import * as vscode from "vscode";
66

77
import { ArduinoApp } from "../arduino/arduino";
8-
import { IArduinoSettings } from "../arduino/arduinoSettings";
9-
import { BoardManager } from "../arduino/boardManager";
8+
import ArduinoActivator from "../arduinoActivator";
9+
import ArduinoContext from "../arduinoContext";
10+
1011
import { VscodeSettings } from "../arduino/vscodeSettings";
1112
import * as platform from "../common/platform";
1213
import * as util from "../common/util";
1314
import { DeviceContext } from "../deviceContext";
1415
import * as Logger from "../logger/logger";
15-
import { DebuggerManager } from "./debuggerManager";
16-
17-
/**
18-
* Automatically generate the Arduino board's debug settings.
19-
*/
20-
export class DebugConfigurator {
21-
constructor(
22-
private _arduinoApp: ArduinoApp,
23-
private _arduinoSettings: IArduinoSettings,
24-
private _boardManager: BoardManager,
25-
private _debuggerManager: DebuggerManager,
26-
) {
16+
17+
export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
18+
19+
constructor() { }
20+
21+
public provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken):
22+
vscode.ProviderResult<vscode.DebugConfiguration[]> {
23+
return [{
24+
name: "Arduino",
25+
type: "arduino",
26+
request: "launch",
27+
program: "${file}",
28+
cwd: folder,
29+
MIMode: "gdb",
30+
targetArchitecture: "arm",
31+
miDebuggerPath: "",
32+
debugServerPath: "",
33+
debugServerArgs: "",
34+
customLaunchSetupCommands: [
35+
{
36+
text: "target remote localhost:3333",
37+
},
38+
{
39+
text: "file ${file}",
40+
},
41+
{
42+
text: "load",
43+
},
44+
{
45+
text: "monitor reset halt",
46+
},
47+
{
48+
text: "monitor reset init",
49+
},
50+
],
51+
stopAtEntry: true,
52+
serverStarted: "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
53+
launchCompleteCommand: "exec-continue",
54+
filterStderr: true,
55+
args: [],
56+
}];
2757
}
2858

29-
public async run(config) {
30-
// Default settings:
31-
if (!config.request) {
32-
config = {
33-
name: "Arduino",
34-
type: "arduino",
35-
request: "launch",
36-
program: "${file}",
37-
cwd: "${workspaceRoot}",
38-
MIMode: "gdb",
39-
40-
targetArchitecture: "arm",
41-
customLaunchSetupCommands: [
42-
{
43-
text: "target remote localhost:3333",
44-
},
45-
{
46-
text: "file ${file}",
47-
},
48-
{
49-
text: "load",
50-
},
51-
{
52-
text: "monitor reset halt",
53-
},
54-
{
55-
text: "monitor reset init",
56-
},
57-
],
58-
stopAtEntry: true,
59-
serverStarted: "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
60-
launchCompleteCommand: "exec-continue",
61-
filterStderr: true,
62-
args: [],
63-
};
59+
// Try to add all missing attributes to the debug configuration being launched.
60+
public resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken):
61+
vscode.ProviderResult<vscode.DebugConfiguration> {
62+
if (config && !config.cwd) {
63+
config.cwd = folder;
64+
}
65+
return this.resolveDebugConfigurationAsync(config);
66+
}
67+
68+
private async resolveDebugConfigurationAsync(config: vscode.DebugConfiguration) {
69+
if (!ArduinoContext.initialized) {
70+
await ArduinoActivator.activate();
6471
}
6572

6673
if (VscodeSettings.getInstance().logLevel === "verbose" && !config.logging) {
@@ -71,40 +78,40 @@ export class DebugConfigurator {
7178
};
7279
}
7380

74-
if (!this._boardManager.currentBoard) {
81+
if (!ArduinoContext.boardManager.currentBoard) {
7582
vscode.window.showErrorMessage("Please select a board.");
76-
return;
83+
return undefined;
7784
}
7885

7986
if (!this.resolveOpenOcd(config)) {
80-
return;
87+
return undefined;
8188
}
8289

8390
if (!await this.resolveOpenOcdOptions(config)) {
84-
return;
91+
return undefined;
8592
}
8693

8794
if (!this.resolveDebuggerPath(config)) {
88-
return;
95+
return undefined;
8996
}
9097

9198
if (!await this.resolveProgramPath(config)) {
92-
return;
99+
return undefined;
93100
}
94101

95102
// Use the C++ debugger MIEngine as the real internal debugger
96103
config.type = "cppdbg";
97-
vscode.commands.executeCommand("vscode.startDebug", config);
98104
const dc = DeviceContext.getInstance();
99105
Logger.traceUserData("start-cppdbg", { board: dc.board });
106+
return config;
100107
}
101108

102109
private async resolveProgramPath(config) {
103110
const dc = DeviceContext.getInstance();
104111

105112
if (!config.program || config.program === "${file}") {
106113
// make a unique temp folder because keeping same temp folder will corrupt the build when board is changed
107-
const outputFolder = path.join(dc.output || `.build`, this._boardManager.currentBoard.board);
114+
const outputFolder = path.join(dc.output || `.build`, ArduinoContext.boardManager.currentBoard.board);
108115
util.mkdirRecursivelySync(path.join(vscode.workspace.rootPath, outputFolder));
109116
if (!dc.sketch || !util.fileExistsSync(path.join(vscode.workspace.rootPath, dc.sketch))) {
110117
await dc.resolveMainSketch();
@@ -122,7 +129,7 @@ export class DebugConfigurator {
122129
config.program = path.join(vscode.workspace.rootPath, outputFolder, `${path.basename(dc.sketch)}.elf`);
123130

124131
// always compile elf to make sure debug the right elf
125-
if (!await this._arduinoApp.verify(outputFolder)) {
132+
if (!await ArduinoContext.arduinoApp.verify(outputFolder)) {
126133
vscode.window.showErrorMessage("Failure to verify the program, please check output for details.");
127134
return false;
128135
}
@@ -145,10 +152,10 @@ export class DebugConfigurator {
145152
private resolveDebuggerPath(config) {
146153
if (!config.miDebuggerPath) {
147154
config.miDebuggerPath = platform.findFile(platform.getExecutableFileName("arm-none-eabi-gdb"),
148-
path.join(this._arduinoSettings.packagePath, "packages", this._boardManager.currentBoard.getPackageName()));
155+
path.join(ArduinoContext.arduinoApp.settings.packagePath, "packages", ArduinoContext.boardManager.currentBoard.getPackageName()));
149156
}
150157
if (!util.fileExistsSync(config.miDebuggerPath)) {
151-
config.miDebuggerPath = this._debuggerManager.miDebuggerPath;
158+
config.miDebuggerPath = ArduinoContext.debuggerManager.miDebuggerPath;
152159
}
153160
if (!util.fileExistsSync(config.miDebuggerPath)) {
154161
vscode.window.showErrorMessage("Cannot find the debugger path.");
@@ -160,11 +167,11 @@ export class DebugConfigurator {
160167
private resolveOpenOcd(config) {
161168
if (!config.debugServerPath) {
162169
config.debugServerPath = platform.findFile(platform.getExecutableFileName("openocd"),
163-
path.join(this._arduinoSettings.packagePath, "packages",
164-
this._boardManager.currentBoard.getPackageName()));
170+
path.join(ArduinoContext.arduinoApp.settings.packagePath, "packages",
171+
ArduinoContext.boardManager.currentBoard.getPackageName()));
165172
}
166173
if (!util.fileExistsSync(config.debugServerPath)) {
167-
config.debugServerPath = this._debuggerManager.debugServerPath;
174+
config.debugServerPath = ArduinoContext.debuggerManager.debugServerPath;
168175
}
169176
if (!util.fileExistsSync(config.debugServerPath)) {
170177
vscode.window.showErrorMessage("Cannot find the OpenOCD from the launch.json debugServerPath property." +
@@ -176,10 +183,9 @@ export class DebugConfigurator {
176183
}
177184

178185
private async resolveOpenOcdOptions(config) {
179-
180186
if (config.debugServerPath && !config.debugServerArgs) {
181187
try {
182-
config.debugServerArgs = await this._debuggerManager.resolveOpenOcdOptions(config);
188+
config.debugServerArgs = await ArduinoContext.debuggerManager.resolveOpenOcdOptions(config);
183189
if (!config.debugServerArgs) {
184190
return false;
185191
}

0 commit comments

Comments
 (0)