Skip to content

Commit

Permalink
Merge pull request #63 from paulober/develop
Browse files Browse the repository at this point in the history
v3.0.2 Patch
  • Loading branch information
paulober authored Apr 11, 2023
2 parents bc27761 + e9a44e1 commit b67abd5
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 42 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ All notable changes to the "pico-w-go" extension will be documented in this file
## Known issues
- 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)
- Mounting virtual workspace causes existing vREPLs to freeze so they need to be disposed manually for some reason. (maybe cauaused by vscode)
- `autoConnect` is currently not working

---

## [3.0.2] - 2023-04-11

# Added
- AutoConnect feature, the extension now detects disconnects and auto reconnects

# Changed
- Fixed `globalSettings` command
- Python detection now has a 1sec timeout

## [3.0.1] - 2023-04-11

# Changed
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pico-w-go",
"displayName": "Pico-W-Go",
"description": "Autocompletion, remote Workspace and a REPL console for the Raspberry Pi Pico (W).",
"version": "3.0.1",
"version": "3.0.2",
"publisher": "paulober",
"license": "MPL-2.0",
"homepage": "https://github.com/paulober/Pico-W-Go/blob/main/README.md",
Expand Down Expand Up @@ -424,7 +424,7 @@
"typescript": "^5.0.4"
},
"dependencies": {
"@paulober/pyboard-serial-com": "^1.4.19",
"@paulober/pyboard-serial-com": "^1.4.22",
"fs-extra": "^11.1.1",
"lodash": "^4.17.21",
"uuid": "^9.0.0"
Expand Down
97 changes: 76 additions & 21 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export default class Activator {
private stubs?: Stubs;
private picoFs?: PicoWFs;

private autoConnectTimer?: NodeJS.Timer;
private comDevice?: string;

constructor() {
this.logger = new Logger("Activator");
}
Expand Down Expand Up @@ -110,10 +113,10 @@ export default class Activator {
this.stubs = new Stubs();
await this.stubs.update();

let comDevice = await settings.getComDevice();
this.comDevice = await settings.getComDevice();

if (comDevice === undefined || comDevice === "") {
comDevice = undefined;
if (this.comDevice === undefined || this.comDevice == "") {
this.comDevice = undefined;

vscode.window
.showErrorMessage(
Expand All @@ -131,12 +134,14 @@ export default class Activator {
this.ui.init();

this.pyb = new PyboardRunner(
comDevice ?? "default",
this.comDevice ?? "default",
this.pyboardOnError.bind(this),
this.pyboardOnExit.bind(this),
pyCommand
);

this.setupAutoConnect(settings);

const terminal = new Terminal(async () => {
if (this.pyb?.isPipeConnected()) {
const result = await this.pyb?.executeCommand(
Expand Down Expand Up @@ -239,7 +244,7 @@ export default class Activator {

if (
settings.getBoolean(SettingsKey.openOnStart) &&
comDevice !== undefined
this.comDevice !== undefined
) {
await focusTerminal(terminalOptions);
}
Expand Down Expand Up @@ -273,10 +278,11 @@ export default class Activator {
disposable = vscode.commands.registerCommand(
"picowgo.connect",
async () => {
comDevice = await settings.getComDevice();
if (comDevice !== undefined) {
this.comDevice = await settings.getComDevice();
if (this.comDevice !== undefined) {
await this.ui?.init();
this.pyb?.switchDevice(comDevice);
this.pyb?.switchDevice(this.comDevice);
this.setupAutoConnect(settings);
}
}
);
Expand All @@ -286,6 +292,7 @@ export default class Activator {
disposable = vscode.commands.registerCommand(
"picowgo.disconnect",
async () => {
clearInterval(this.autoConnectTimer);
await this.pyb?.disconnect();
}
);
Expand Down Expand Up @@ -317,7 +324,8 @@ export default class Activator {
const data = await this.pyb.runFile(file, (data: string) => {
// only freeze after operation has started
if (!frozen) {
terminal?.freeze();
commandExecuting = true;
terminal?.clean(true);
terminal?.write("\r\n");
this.ui?.userOperationStarted();
frozen = true;
Expand All @@ -329,6 +337,7 @@ export default class Activator {
const result = data as PyOutCommandResult;
// TODO: reflect result.result somehow
}
commandExecuting = false;
terminal?.melt();
terminal?.write("\r\n");
terminal?.prompt();
Expand Down Expand Up @@ -362,7 +371,8 @@ export default class Activator {
(data: string) => {
// only freeze after operation has started
if (!frozen) {
terminal?.freeze();
commandExecuting = true;
terminal?.clean(true);
terminal?.write("\r\n");
this.ui?.userOperationStarted();
frozen = true;
Expand All @@ -372,6 +382,7 @@ export default class Activator {
true
);
this.ui?.userOperationStopped();
commandExecuting = false;
terminal?.melt();
terminal?.write("\r\n");
terminal?.prompt();
Expand Down Expand Up @@ -401,7 +412,8 @@ export default class Activator {
(data: string) => {
// only freeze after operation has started
if (!frozen) {
terminal?.freeze();
commandExecuting = true;
terminal?.clean(true);
terminal?.write("\r\n");
this.ui?.userOperationStarted();
frozen = true;
Expand All @@ -410,6 +422,7 @@ export default class Activator {
},
true
);
commandExecuting = false;
this.ui?.userOperationStopped();
if (data.type === PyOutType.commandResult) {
const result = data as PyOutCommandResult;
Expand Down Expand Up @@ -627,7 +640,7 @@ export default class Activator {

// [Command] Global settings
disposable = vscode.commands.registerCommand(
"picowgo.globalsettings",
"picowgo.globalSettings",
async () => {
openSettings();
}
Expand All @@ -639,14 +652,16 @@ export default class Activator {
"picowgo.toggleConnect",
async () => {
if (this.pyb?.isPipeConnected()) {
clearInterval(this.autoConnectTimer);
await this.pyb?.disconnect();
} else {
comDevice = await settings.getComDevice();
if (comDevice === undefined) {
this.comDevice = await settings.getComDevice();
if (this.comDevice == undefined) {
vscode.window.showErrorMessage("No COM device found!");
} else {
await this.ui?.init();
this.pyb?.switchDevice(comDevice);
this.pyb?.switchDevice(this.comDevice);
this.setupAutoConnect(settings);
}
}
}
Expand Down Expand Up @@ -772,8 +787,8 @@ export default class Activator {
});

if (port !== undefined) {
comDevice = port;
this.pyb?.switchDevice(comDevice);
this.comDevice = port;
this.pyb?.switchDevice(this.comDevice);
}
}
);
Expand Down Expand Up @@ -856,14 +871,54 @@ export default class Activator {
return this.ui;
}

private setupAutoConnect(settings: Settings): void {
this.autoConnectTimer = setInterval(async () => {
await this.pyb?.checkStatus();
if (this.pyb?.isPipeConnected()) {
this.ui?.refreshState(true);
return;
}
this.ui?.refreshState(false);
const autoPort = settings.getBoolean(SettingsKey.autoConnect);

const ports = await PyboardRunner.getPorts(settings.pythonExecutable);
if (ports.ports.length === 0) {
return;
}

// try to connect to previously connected device first
if (this.comDevice && ports.ports.includes(this.comDevice)) {
// try to reconnect
this.pyb?.switchDevice(this.comDevice);
await new Promise(resolve => setTimeout(resolve, 1000));
if (this.pyb?.isPipeConnected()) {
return;
}
}

if (autoPort) {
const port = ports.ports[0];
this.comDevice = port;
this.pyb?.switchDevice(port);
}
}, 2500);
}

private pyboardOnError(data: Buffer | undefined) {
if (data === undefined) {
this.ui?.refreshState(true);
this.logger.info("Connection to Pico successfully established");
if (
data === undefined &&
this.comDevice !== undefined &&
this.comDevice !== "" &&
this.comDevice !== "default"
) {
//this.ui?.refreshState(true);
this.logger.info("Connection to wrapper successfully established");

return;
} else {
vscode.window.showErrorMessage(data.toString("utf-8"));
if (data) {
vscode.window.showErrorMessage(data.toString("utf-8"));
}
}
}

Expand Down
20 changes: 12 additions & 8 deletions src/osHelper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ export async function getPythonCommand(): Promise<string | undefined> {
const pythonCommand: string | undefined = pythonCommands[currentPlatform];

return new Promise(resolve => {
exec(`${pythonCommand} --version`, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing ${pythonCommand}: ${error.message}`);
resolve(undefined);
} else {
console.debug(`Python version: ${stdout || stderr}`);
resolve(pythonCommand);
exec(
`${pythonCommand} --version`,
{ timeout: 1000 },
(error, stdout, stderr) => {
if (error) {
console.error(`Error executing ${pythonCommand}: ${error.message}`);
resolve(undefined);
} else {
console.debug(`Python version: ${stdout || stderr}`);
resolve(pythonCommand);
}
}
});
);
});
}

Expand Down
7 changes: 6 additions & 1 deletion src/terminal.mts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ export class Terminal implements Pseudoterminal {
public freeze(): void {
this.isForzen = true;

this.clean(false);
}

public clean(waitingForPrompt?: boolean): void {
this.waitingForPrompt! != waitingForPrompt;

// TODO: maybe restore current state
this.buffer = "";
this.multilineMode = false;
this.indentation = 0;
this.waitingForPrompt = false;
this.xCursor = 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/ui.mts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default class UI {

private setButton(name: string, icon: string, text: string): void {
this.items[name].text = `$(${icon}) ${text}`;
this.items[name].show();
}

private setState(connected: boolean): void {
Expand Down

0 comments on commit b67abd5

Please sign in to comment.