Skip to content

Commit c5057f1

Browse files
squash!
1 parent a227b25 commit c5057f1

28 files changed

Lines changed: 297 additions & 195 deletions

Source/debugger/debugAdapter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ export class DebugAdapter implements DebugAdapterTracker {
2323
if (message.command) {
2424
// Only send pertinent debug messages
2525
switch (message.command) {
26-
case DEBUG_COMMANDS.CONTINUE:
26+
case DEBUG_COMMANDS.CONTINUE: {
2727
this.messagingService.sendStartMessage();
2828
break;
29-
case DEBUG_COMMANDS.STACK_TRACE:
29+
}
30+
case DEBUG_COMMANDS.STACK_TRACE: {
3031
this.messagingService.sendPauseMessage();
3132
break;
32-
case DEBUG_COMMANDS.DISCONNECT:
33+
}
34+
case DEBUG_COMMANDS.DISCONNECT: {
3335
// Triggered on stop event for debugger
3436
if (!message.arguments.restart) {
3537
this.debugCommunicationService.handleStopEvent();
3638
}
3739
break;
40+
}
3841
}
3942
}
4043
}

Source/debuggerCommunicationServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class DebuggerCommunicationServer {
3131

3232
constructor(
3333
webviewPanel: WebviewPanel | undefined,
34-
port = SERVER_INFO.DEFAULT_SERVER_PORT,
34+
port,
3535
deviceSelectionService: DeviceSelectionService,
3636
) {
3737
this.port = port;

Source/extension.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ export async function activate(context: vscode.ExtensionContext) {
117117
},
118118
);
119119

120-
const currVersionReleaseName =
121-
"release_note_" + getPackageInfo(context).extensionVersion;
120+
const currVersionReleaseName = `release_note_${
121+
getPackageInfo(context).extensionVersion
122+
}`;
122123
const viewedReleaseNote = context.globalState.get(
123124
currVersionReleaseName,
124125
false,
@@ -130,7 +131,7 @@ export async function activate(context: vscode.ExtensionContext) {
130131
}
131132

132133
const openWebview = () => {
133-
if (currentPanel && currentPanel.webview) {
134+
if (currentPanel?.webview) {
134135
messagingService.setWebview(currentPanel.webview);
135136
currentPanel.webview.html = webviewService.getWebviewContent(
136137
WEBVIEW_TYPES.SIMULATOR,
@@ -191,7 +192,7 @@ export async function activate(context: vscode.ExtensionContext) {
191192
state: message.text,
192193
});
193194
switch (message.command) {
194-
case WEBVIEW_MESSAGES.BUTTON_PRESS:
195+
case WEBVIEW_MESSAGES.BUTTON_PRESS: {
195196
// Send input to the Python process
196197
telemetryHandlerService.handleButtonPressTelemetry(
197198
message.text,
@@ -206,11 +207,12 @@ export async function activate(context: vscode.ExtensionContext) {
206207
.emitInputChanged(messageJson);
207208
} else if (childProcess) {
208209
childProcess.stdin.write(
209-
messageJson + "\n",
210+
`${messageJson}\n`,
210211
);
211212
}
212213
break;
213-
case WEBVIEW_MESSAGES.TOGGLE_PLAY_STOP:
214+
}
215+
case WEBVIEW_MESSAGES.TOGGLE_PLAY_STOP: {
214216
console.log(`Play button ${messageJson} \n`);
215217
if (message.text.state as boolean) {
216218
fileSelectionService.setPathAndSendMessage(
@@ -227,13 +229,14 @@ export async function activate(context: vscode.ExtensionContext) {
227229

228230
if (childProcess) {
229231
childProcess.stdin.write(
230-
messageJson + "\n",
232+
`${messageJson}\n`,
231233
);
232234
}
233235

234236
break;
237+
}
235238
case WEBVIEW_MESSAGES.GESTURE:
236-
case WEBVIEW_MESSAGES.SENSOR_CHANGED:
239+
case WEBVIEW_MESSAGES.SENSOR_CHANGED: {
237240
telemetryHandlerService.handleGestureTelemetry(
238241
message.text,
239242
);
@@ -247,30 +250,35 @@ export async function activate(context: vscode.ExtensionContext) {
247250
.emitInputChanged(messageJson);
248251
} else if (childProcess) {
249252
childProcess.stdin.write(
250-
messageJson + "\n",
253+
`${messageJson}\n`,
251254
);
252255
}
253256
break;
254-
case WEBVIEW_MESSAGES.REFRESH_SIMULATOR:
257+
}
258+
case WEBVIEW_MESSAGES.REFRESH_SIMULATOR: {
255259
console.log("Refresh button");
256260
runSimulatorCommand();
257261
break;
258-
case WEBVIEW_MESSAGES.SLIDER_TELEMETRY:
262+
}
263+
case WEBVIEW_MESSAGES.SLIDER_TELEMETRY: {
259264
telemetryHandlerService.handleSensorTelemetry(
260265
message.text,
261266
);
262267
break;
263-
case WEBVIEW_MESSAGES.SWITCH_DEVICE:
268+
}
269+
case WEBVIEW_MESSAGES.SWITCH_DEVICE: {
264270
deviceSelectionService.setCurrentActiveDevice(
265271
message.text.active_device,
266272
);
267273
killProcessIfRunning();
268274
break;
269-
default:
275+
}
276+
default: {
270277
vscode.window.showInformationMessage(
271278
CONSTANTS.ERROR.UNEXPECTED_MESSAGE,
272279
);
273280
break;
281+
}
274282
}
275283
},
276284
undefined,
@@ -354,8 +362,9 @@ export async function activate(context: vscode.ExtensionContext) {
354362

355363
const openTemplateFile = (template: string) => {
356364
const fileName = template;
357-
const filePath =
358-
__dirname + path.sep + "templates" + path.sep + fileName;
365+
const filePath = `${__dirname + path.sep}templates${
366+
path.sep
367+
}${fileName}`;
359368
const file = fs.readFileSync(filePath, "utf8");
360369
const showNewFilePopup: boolean = vscode.workspace
361370
.getConfiguration()
@@ -613,7 +622,7 @@ export async function activate(context: vscode.ExtensionContext) {
613622
messageToWebview = JSON.parse(message);
614623
// Check the JSON is a state
615624
switch (messageToWebview.type) {
616-
case "state":
625+
case "state": {
617626
const messageData = JSON.parse(
618627
messageToWebview.data,
619628
);
@@ -627,8 +636,9 @@ export async function activate(context: vscode.ExtensionContext) {
627636
);
628637
}
629638
break;
639+
}
630640

631-
case "print":
641+
case "print": {
632642
console.log(
633643
`Process print statement output = ${messageToWebview.data}`,
634644
);
@@ -637,12 +647,14 @@ export async function activate(context: vscode.ExtensionContext) {
637647
`[PRINT] ${messageToWebview.data}`,
638648
);
639649
break;
650+
}
640651

641-
default:
652+
default: {
642653
console.log(
643654
`Non-state JSON output from the process : ${messageToWebview}`,
644655
);
645656
break;
657+
}
646658
}
647659
} catch (err) {
648660
if (err instanceof SyntaxError) {

Source/extension_utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export function padStart(
131131
if (sourceString.length > targetLength) {
132132
return sourceString;
133133
} else {
134-
targetLength = targetLength - sourceString.length;
134+
targetLength -= sourceString.length;
135135
if (targetLength > padString.length) {
136136
padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed
137137
}
@@ -225,7 +225,7 @@ export const createEscapedPath = (...pieces: string[]) => {
225225

226226
// escape all special characters
227227
// https://stackoverflow.com/questions/1779858/how-do-i-escape-a-string-for-a-shell-command-in-node
228-
return `"` + initialPath.replace(/(["'$`\\])/g, "\\$1") + `"`;
228+
return `"${initialPath.replace(/(["'$`\\])/g, "\\$1")}"`;
229229
};
230230

231231
export const getTelemetryState = () => {

Source/serialMonitor.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class SerialMonitor implements vscode.Disposable {
7777
);
7878
this._openPortStatusBar.command =
7979
"deviceSimulatorExpress.common.openSerialMonitor";
80-
this._openPortStatusBar.text = `$(plug)`;
80+
this._openPortStatusBar.text = "$(plug)";
8181
this._openPortStatusBar.tooltip = "Open Serial Monitor";
8282
this._openPortStatusBar.show();
8383

@@ -113,10 +113,7 @@ export class SerialMonitor implements vscode.Disposable {
113113
}
114114
return false;
115115
});
116-
if (
117-
foundPort &&
118-
!(this._serialPortControl && this._serialPortControl.isActive)
119-
) {
116+
if (foundPort && !this._serialPortControl?.isActive) {
120117
this.updatePortListStatus(foundPort.path);
121118
}
122119
} else {
@@ -138,7 +135,7 @@ export class SerialMonitor implements vscode.Disposable {
138135
{ placeHolder: CONSTANTS.MISC.SELECT_PORT_PLACEHOLDER },
139136
);
140137

141-
if (chosen && chosen.label) {
138+
if (chosen?.label) {
142139
this.updatePortListStatus(chosen.label);
143140
}
144141
}
@@ -203,7 +200,7 @@ export class SerialMonitor implements vscode.Disposable {
203200
}
204201

205202
public dispose() {
206-
if (this._serialPortControl && this._serialPortControl.isActive) {
203+
if (this._serialPortControl?.isActive) {
207204
return this._serialPortControl.stop();
208205
}
209206
}
@@ -270,13 +267,13 @@ export class SerialMonitor implements vscode.Disposable {
270267
if (isOpened) {
271268
this._openPortStatusBar.command =
272269
"deviceSimulatorExpress.common.closeSerialMonitor";
273-
this._openPortStatusBar.text = `$(x)`;
270+
this._openPortStatusBar.text = "$(x)";
274271
this._openPortStatusBar.tooltip = "Close Serial Monitor";
275272
this._baudRateStatusBar.show();
276273
} else {
277274
this._openPortStatusBar.command =
278275
"deviceSimulatorExpress.common.openSerialMonitor";
279-
this._openPortStatusBar.text = `$(plug)`;
276+
this._openPortStatusBar.text = "$(plug)";
280277
this._openPortStatusBar.tooltip = "Open Serial Monitor";
281278
this._baudRateStatusBar.hide();
282279
}

Source/serialPortControl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class SerialPortControl {
4848
}
4949

5050
public get isActive(): boolean {
51-
return this._currentSerialPort && this._currentSerialPort.isOpen;
51+
return this._currentSerialPort?.isOpen;
5252
}
5353

5454
public get currentPort(): string {
@@ -61,7 +61,7 @@ export class SerialPortControl {
6161
CONSTANTS.INFO.OPENING_SERIAL_PORT(this._currentPort),
6262
);
6363
return new Promise((resolve, reject) => {
64-
if (this._currentSerialPort && this._currentSerialPort.isOpen) {
64+
if (this._currentSerialPort?.isOpen) {
6565
this._currentSerialPort.close((err: any) => {
6666
if (err) {
6767
return reject(err);
@@ -136,7 +136,7 @@ export class SerialPortControl {
136136
return;
137137
}
138138
this._currentPort = newPort;
139-
if (!this._currentSerialPort || !this.isActive) {
139+
if (!(this._currentSerialPort && this.isActive)) {
140140
resolve();
141141
return;
142142
}
@@ -153,7 +153,7 @@ export class SerialPortControl {
153153

154154
public stop(): Promise<any> {
155155
return new Promise((resolve, reject) => {
156-
if (!this._currentSerialPort || !this.isActive) {
156+
if (!(this._currentSerialPort && this.isActive)) {
157157
resolve(false);
158158
return;
159159
}
@@ -177,7 +177,7 @@ export class SerialPortControl {
177177
public changeBaudRate(newBaudRate: number): Promise<any> {
178178
return new Promise((resolve, reject) => {
179179
this._currentBaudRate = newBaudRate;
180-
if (!this._currentSerialPort || !this.isActive) {
180+
if (!(this._currentSerialPort && this.isActive)) {
181181
resolve();
182182
return;
183183
}

Source/service/fileSelectionService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export class FileSelectionService {
3333
activeTextDocument: vscode.TextEditor | undefined,
3434
) => {
3535
if (
36-
activeTextDocument &&
37-
activeTextDocument.document &&
36+
activeTextDocument?.document &&
3837
activeTextDocument.document.languageId === "python"
3938
) {
4039
this.setPathAndSendMessage(activeTextDocument.document.fileName);

0 commit comments

Comments
 (0)