Skip to content

Commit b67abd5

Browse files
authored
Merge pull request #63 from paulober/develop
v3.0.2 Patch
2 parents bc27761 + e9a44e1 commit b67abd5

File tree

7 files changed

+115
-42
lines changed

7 files changed

+115
-42
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ All notable changes to the "pico-w-go" extension will be documented in this file
77
## Known issues
88
- Run current file does not include modules that are localy imported and in current workspace, unless you upload the python file containing the module via the upload file or project feature first. (since ever)
99
- Mounting virtual workspace causes existing vREPLs to freeze so they need to be disposed manually for some reason. (maybe cauaused by vscode)
10-
- `autoConnect` is currently not working
1110

1211
---
1312

13+
## [3.0.2] - 2023-04-11
14+
15+
# Added
16+
- AutoConnect feature, the extension now detects disconnects and auto reconnects
17+
18+
# Changed
19+
- Fixed `globalSettings` command
20+
- Python detection now has a 1sec timeout
21+
1422
## [3.0.1] - 2023-04-11
1523

1624
# Changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pico-w-go",
33
"displayName": "Pico-W-Go",
44
"description": "Autocompletion, remote Workspace and a REPL console for the Raspberry Pi Pico (W).",
5-
"version": "3.0.1",
5+
"version": "3.0.2",
66
"publisher": "paulober",
77
"license": "MPL-2.0",
88
"homepage": "https://github.com/paulober/Pico-W-Go/blob/main/README.md",
@@ -424,7 +424,7 @@
424424
"typescript": "^5.0.4"
425425
},
426426
"dependencies": {
427-
"@paulober/pyboard-serial-com": "^1.4.19",
427+
"@paulober/pyboard-serial-com": "^1.4.22",
428428
"fs-extra": "^11.1.1",
429429
"lodash": "^4.17.21",
430430
"uuid": "^9.0.0"

src/activator.mts

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export default class Activator {
3939
private stubs?: Stubs;
4040
private picoFs?: PicoWFs;
4141

42+
private autoConnectTimer?: NodeJS.Timer;
43+
private comDevice?: string;
44+
4245
constructor() {
4346
this.logger = new Logger("Activator");
4447
}
@@ -110,10 +113,10 @@ export default class Activator {
110113
this.stubs = new Stubs();
111114
await this.stubs.update();
112115

113-
let comDevice = await settings.getComDevice();
116+
this.comDevice = await settings.getComDevice();
114117

115-
if (comDevice === undefined || comDevice === "") {
116-
comDevice = undefined;
118+
if (this.comDevice === undefined || this.comDevice == "") {
119+
this.comDevice = undefined;
117120

118121
vscode.window
119122
.showErrorMessage(
@@ -131,12 +134,14 @@ export default class Activator {
131134
this.ui.init();
132135

133136
this.pyb = new PyboardRunner(
134-
comDevice ?? "default",
137+
this.comDevice ?? "default",
135138
this.pyboardOnError.bind(this),
136139
this.pyboardOnExit.bind(this),
137140
pyCommand
138141
);
139142

143+
this.setupAutoConnect(settings);
144+
140145
const terminal = new Terminal(async () => {
141146
if (this.pyb?.isPipeConnected()) {
142147
const result = await this.pyb?.executeCommand(
@@ -239,7 +244,7 @@ export default class Activator {
239244

240245
if (
241246
settings.getBoolean(SettingsKey.openOnStart) &&
242-
comDevice !== undefined
247+
this.comDevice !== undefined
243248
) {
244249
await focusTerminal(terminalOptions);
245250
}
@@ -273,10 +278,11 @@ export default class Activator {
273278
disposable = vscode.commands.registerCommand(
274279
"picowgo.connect",
275280
async () => {
276-
comDevice = await settings.getComDevice();
277-
if (comDevice !== undefined) {
281+
this.comDevice = await settings.getComDevice();
282+
if (this.comDevice !== undefined) {
278283
await this.ui?.init();
279-
this.pyb?.switchDevice(comDevice);
284+
this.pyb?.switchDevice(this.comDevice);
285+
this.setupAutoConnect(settings);
280286
}
281287
}
282288
);
@@ -286,6 +292,7 @@ export default class Activator {
286292
disposable = vscode.commands.registerCommand(
287293
"picowgo.disconnect",
288294
async () => {
295+
clearInterval(this.autoConnectTimer);
289296
await this.pyb?.disconnect();
290297
}
291298
);
@@ -317,7 +324,8 @@ export default class Activator {
317324
const data = await this.pyb.runFile(file, (data: string) => {
318325
// only freeze after operation has started
319326
if (!frozen) {
320-
terminal?.freeze();
327+
commandExecuting = true;
328+
terminal?.clean(true);
321329
terminal?.write("\r\n");
322330
this.ui?.userOperationStarted();
323331
frozen = true;
@@ -329,6 +337,7 @@ export default class Activator {
329337
const result = data as PyOutCommandResult;
330338
// TODO: reflect result.result somehow
331339
}
340+
commandExecuting = false;
332341
terminal?.melt();
333342
terminal?.write("\r\n");
334343
terminal?.prompt();
@@ -362,7 +371,8 @@ export default class Activator {
362371
(data: string) => {
363372
// only freeze after operation has started
364373
if (!frozen) {
365-
terminal?.freeze();
374+
commandExecuting = true;
375+
terminal?.clean(true);
366376
terminal?.write("\r\n");
367377
this.ui?.userOperationStarted();
368378
frozen = true;
@@ -372,6 +382,7 @@ export default class Activator {
372382
true
373383
);
374384
this.ui?.userOperationStopped();
385+
commandExecuting = false;
375386
terminal?.melt();
376387
terminal?.write("\r\n");
377388
terminal?.prompt();
@@ -401,7 +412,8 @@ export default class Activator {
401412
(data: string) => {
402413
// only freeze after operation has started
403414
if (!frozen) {
404-
terminal?.freeze();
415+
commandExecuting = true;
416+
terminal?.clean(true);
405417
terminal?.write("\r\n");
406418
this.ui?.userOperationStarted();
407419
frozen = true;
@@ -410,6 +422,7 @@ export default class Activator {
410422
},
411423
true
412424
);
425+
commandExecuting = false;
413426
this.ui?.userOperationStopped();
414427
if (data.type === PyOutType.commandResult) {
415428
const result = data as PyOutCommandResult;
@@ -627,7 +640,7 @@ export default class Activator {
627640

628641
// [Command] Global settings
629642
disposable = vscode.commands.registerCommand(
630-
"picowgo.globalsettings",
643+
"picowgo.globalSettings",
631644
async () => {
632645
openSettings();
633646
}
@@ -639,14 +652,16 @@ export default class Activator {
639652
"picowgo.toggleConnect",
640653
async () => {
641654
if (this.pyb?.isPipeConnected()) {
655+
clearInterval(this.autoConnectTimer);
642656
await this.pyb?.disconnect();
643657
} else {
644-
comDevice = await settings.getComDevice();
645-
if (comDevice === undefined) {
658+
this.comDevice = await settings.getComDevice();
659+
if (this.comDevice == undefined) {
646660
vscode.window.showErrorMessage("No COM device found!");
647661
} else {
648662
await this.ui?.init();
649-
this.pyb?.switchDevice(comDevice);
663+
this.pyb?.switchDevice(this.comDevice);
664+
this.setupAutoConnect(settings);
650665
}
651666
}
652667
}
@@ -772,8 +787,8 @@ export default class Activator {
772787
});
773788

774789
if (port !== undefined) {
775-
comDevice = port;
776-
this.pyb?.switchDevice(comDevice);
790+
this.comDevice = port;
791+
this.pyb?.switchDevice(this.comDevice);
777792
}
778793
}
779794
);
@@ -856,14 +871,54 @@ export default class Activator {
856871
return this.ui;
857872
}
858873

874+
private setupAutoConnect(settings: Settings): void {
875+
this.autoConnectTimer = setInterval(async () => {
876+
await this.pyb?.checkStatus();
877+
if (this.pyb?.isPipeConnected()) {
878+
this.ui?.refreshState(true);
879+
return;
880+
}
881+
this.ui?.refreshState(false);
882+
const autoPort = settings.getBoolean(SettingsKey.autoConnect);
883+
884+
const ports = await PyboardRunner.getPorts(settings.pythonExecutable);
885+
if (ports.ports.length === 0) {
886+
return;
887+
}
888+
889+
// try to connect to previously connected device first
890+
if (this.comDevice && ports.ports.includes(this.comDevice)) {
891+
// try to reconnect
892+
this.pyb?.switchDevice(this.comDevice);
893+
await new Promise(resolve => setTimeout(resolve, 1000));
894+
if (this.pyb?.isPipeConnected()) {
895+
return;
896+
}
897+
}
898+
899+
if (autoPort) {
900+
const port = ports.ports[0];
901+
this.comDevice = port;
902+
this.pyb?.switchDevice(port);
903+
}
904+
}, 2500);
905+
}
906+
859907
private pyboardOnError(data: Buffer | undefined) {
860-
if (data === undefined) {
861-
this.ui?.refreshState(true);
862-
this.logger.info("Connection to Pico successfully established");
908+
if (
909+
data === undefined &&
910+
this.comDevice !== undefined &&
911+
this.comDevice !== "" &&
912+
this.comDevice !== "default"
913+
) {
914+
//this.ui?.refreshState(true);
915+
this.logger.info("Connection to wrapper successfully established");
863916

864917
return;
865918
} else {
866-
vscode.window.showErrorMessage(data.toString("utf-8"));
919+
if (data) {
920+
vscode.window.showErrorMessage(data.toString("utf-8"));
921+
}
867922
}
868923
}
869924

src/osHelper.mts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ export async function getPythonCommand(): Promise<string | undefined> {
1919
const pythonCommand: string | undefined = pythonCommands[currentPlatform];
2020

2121
return new Promise(resolve => {
22-
exec(`${pythonCommand} --version`, (error, stdout, stderr) => {
23-
if (error) {
24-
console.error(`Error executing ${pythonCommand}: ${error.message}`);
25-
resolve(undefined);
26-
} else {
27-
console.debug(`Python version: ${stdout || stderr}`);
28-
resolve(pythonCommand);
22+
exec(
23+
`${pythonCommand} --version`,
24+
{ timeout: 1000 },
25+
(error, stdout, stderr) => {
26+
if (error) {
27+
console.error(`Error executing ${pythonCommand}: ${error.message}`);
28+
resolve(undefined);
29+
} else {
30+
console.debug(`Python version: ${stdout || stderr}`);
31+
resolve(pythonCommand);
32+
}
2933
}
30-
});
34+
);
3135
});
3236
}
3337

src/terminal.mts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ export class Terminal implements Pseudoterminal {
5858
public freeze(): void {
5959
this.isForzen = true;
6060

61+
this.clean(false);
62+
}
63+
64+
public clean(waitingForPrompt?: boolean): void {
65+
this.waitingForPrompt! != waitingForPrompt;
66+
6167
// TODO: maybe restore current state
6268
this.buffer = "";
6369
this.multilineMode = false;
6470
this.indentation = 0;
65-
this.waitingForPrompt = false;
6671
this.xCursor = 0;
6772
}
6873

src/ui.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export default class UI {
8181

8282
private setButton(name: string, icon: string, text: string): void {
8383
this.items[name].text = `$(${icon}) ${text}`;
84+
this.items[name].show();
8485
}
8586

8687
private setState(connected: boolean): void {

0 commit comments

Comments
 (0)