Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 6e054ca

Browse files
authored
Adding a debugging configuration (#53)
[PBI:30914 - Task:31107] * Adding a debug configuration to the extension * Moving debugger configuration to a class and utilitary methods to utils.ts * Moving strings constants to constants.ts and localization + using 'endQith()' to check the file name * Adding preserveFocus when opening the webview and the output panel : Prevents the debugger to fail trying to find the file on first run + prevent having to click on the code file after clicking on open * Modifying the error message when the file selected to debug isn't properly named
1 parent 19b34d2 commit 6e054ca

File tree

6 files changed

+275
-58
lines changed

6 files changed

+275
-58
lines changed

locales/en/out/constants.i18n.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dialogResponses.help": "I need help",
55
"dialogResponses.tutorials": "Tutorials on Adafruit",
66
"error.noDevice": "No plugged in boards detected. Please double check if your board is connected and/or properly formatted",
7-
"error.noFileToRun": "\n[ERROR] We can't find the .py file to run on simulator. Open up a new .py file, or browse through some examples",
7+
"error.noFileToRun": "\n[ERROR] We can't find the .py file to run on simulator. Open up a new .py file, or browse through some examples\n",
88
"error.stderr": "\n[ERROR] {0} \n",
99
"error.unexpectedMessage": "Webview sent an unexpected message",
1010
"info.deployDevice": "\n[INFO] Deploying code to the device...\n",
@@ -17,4 +17,4 @@
1717
"info.welcomeOutputTab": "Welcome to the Adafruit Simulator output tab !\n\n",
1818
"label.webviewPanel": "Adafruit CPX",
1919
"name": "Adafruit Simulator"
20-
}
20+
}

package.json

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"onCommand:pacifica.openSimulator",
2828
"onCommand:pacifica.runSimulator",
2929
"onCommand:pacifica.newProject",
30-
"onCommand:pacifica.runDevice"
30+
"onCommand:pacifica.runDevice",
31+
"onDebug"
3132
],
3233
"main": "./out/extension.js",
3334
"contributes": {
@@ -98,7 +99,81 @@
9899
"scope": "resource"
99100
}
100101
}
101-
}
102+
},
103+
"breakpoints": [
104+
{
105+
"language": "python"
106+
}
107+
],
108+
"debuggers": [
109+
{
110+
"type": "python",
111+
"label": "Pacifica Simulator Debugger",
112+
"program": "./out/debugAdapter.js",
113+
"runtime": "node",
114+
"configurationAttributes": {
115+
"launch": {
116+
"properties": {
117+
"program": {
118+
"type": "string",
119+
"description": "Absolute path to the code file.",
120+
"default": "${file}"
121+
},
122+
"stopOnEntry": {
123+
"type": "boolean",
124+
"description": "Automatically stop after launch.",
125+
"default": false
126+
},
127+
"justMyCode": {
128+
"type": "boolean",
129+
"default": true
130+
},
131+
"args": {
132+
"type": "array",
133+
"description": "Command line arguments passed to the program.",
134+
"default": [],
135+
"items": {
136+
"type": "string"
137+
}
138+
},
139+
"rules": {
140+
"type": "array",
141+
"description": "Debugger rules.",
142+
"default": [],
143+
"items": {
144+
"path": "string",
145+
"include": "boolean"
146+
}
147+
}
148+
}
149+
}
150+
},
151+
"initialConfigurations": [
152+
{
153+
"type": "python",
154+
"request": "launch",
155+
"name": "Pacifica Simulator Debugger",
156+
"program": "${file}",
157+
"stopOnEntry": false,
158+
"justMyCode": true
159+
}
160+
],
161+
"configurationSnippets": [
162+
{
163+
"label": "Pacifica Simulator Debugger : Launch",
164+
"description": "Pacifica Simulator Debugger - A configuration for debugging a python code file for the Pacifica simulator.",
165+
"body": {
166+
"type": "python",
167+
"request": "launch",
168+
"name": "Pacifica Simulator Debugger",
169+
"program": "${file}",
170+
"stopOnEntry": false,
171+
"justMyCode": true
172+
}
173+
}
174+
]
175+
}
176+
]
102177
},
103178
"scripts": {
104179
"vscode:prepublish": "npm run compile",
@@ -165,4 +240,4 @@
165240
"eslintConfig": {
166241
"extends": "react-app"
167242
}
168-
}
243+
}

src/constants.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ const localize: nls.LocalizeFunc = nls.config({
99
})();
1010

1111
export const CONSTANTS = {
12+
DEBUG_CONFIGURATION_NAME: "Pacifica Simulator Debugger",
1213
ERROR: {
14+
INVALID_FILE_NAME_DEBUG: localize(
15+
"error.invalidFileNameDebug",
16+
'The file you tried to run isn\'t named "code.py" or "main.py". Rename your file if you wish to debug it.'
17+
),
1318
NO_DEVICE: localize(
1419
"error.noDevice",
1520
"No plugged in boards detected. Please double check if your board is connected and/or properly formatted"
1621
),
1722
NO_FILE_TO_RUN: localize(
1823
"error.noFileToRun",
19-
"\n[ERROR] We can't find the .py file to run. Open up a new .py file, or browse through some examples to start with: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples"
24+
"\n[ERROR] We can't find the .py file to run. Open up a new .py file, or browse through some examples to start with: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples\n"
25+
),
26+
NO_PROGRAM_FOUND_DEBUG: localize(
27+
"error.noProgramFoundDebug",
28+
"Cannot find a program to debug."
2029
),
2130
STDERR: (data: string) => {
2231
return localize("error.stderr", `\n[ERROR] ${data} \n`);
@@ -46,7 +55,7 @@ export const CONSTANTS = {
4655
),
4756
FIRST_TIME_WEBVIEW: localize(
4857
"info.firstTimeWebview",
49-
"To reopen the simulator click on the \"Open Simulator\" button on the upper right corner of the text editor, or select the command \"Open Simulator\" from command palette."
58+
'To reopen the simulator click on the "Open Simulator" button on the upper right corner of the text editor, or select the command "Open Simulator" from command palette.'
5059
),
5160
NEW_PROJECT: localize(
5261
"info.newProject",
@@ -112,7 +121,6 @@ export enum WebviewMessages {
112121
PLAY_SIMULATOR = "play-simulator"
113122
}
114123

115-
116124
// tslint:disable-next-line: no-namespace
117125
export namespace DialogResponses {
118126
export const HELP: MessageItem = {
@@ -129,4 +137,9 @@ export namespace DialogResponses {
129137
};
130138
}
131139

132-
export default CONSTANTS;
140+
export const USER_CODE_NAMES = {
141+
CODE_PY: "code.py",
142+
MAIN_PY: "main.py"
143+
};
144+
145+
export default CONSTANTS;

0 commit comments

Comments
 (0)