Skip to content

Commit

Permalink
Added garbageCollect command + vREPL .gc shortcut + make use of the d…
Browse files Browse the repository at this point in the history
…ynamicWrapping feature for friendlyCommands aka expressions and statements

Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Sep 3, 2024
1 parent 45ae4ca commit 1745af1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
"light": "images/refresh-light.svg"
},
"enablement": "view == micropico-device-wifi"
},
{
"command": "micropico.garbageCollect",
"title": "Trigger garbage collection",
"category": "MicroPico"
}
],
"menus": {
Expand Down Expand Up @@ -633,7 +638,7 @@
"typescript-eslint": "^8.3.0"
},
"dependencies": {
"@paulober/pico-mpy-com": "^1.0.11",
"@paulober/pico-mpy-com": "^1.0.12",
"@vscode/python-extension": "^1.0.5",
"axios": "^1.7.5",
"fs-extra": "^11.2.0",
Expand Down
50 changes: 46 additions & 4 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ export default class Activator {

this.terminal = new Terminal(async () => {
const result = await PicoMpyCom.getInstance().runCommand(
"\rfrom usys import implementation, version; " +
"print(version.split('; ')[1] + '; ' + implementation._machine)"
"\rfrom sys import implementation as _pe_impl, version as _pe_vers\n" +
"print(_pe_vers.split('; ')[1] + '; ' + _pe_impl._machine)\n" +
"del _pe_impl, _pe_vers"
);
if (result.type === OperationResultType.commandResponse) {
return (
Expand Down Expand Up @@ -193,7 +194,8 @@ export default class Activator {
this.terminal?.write(data.toString("utf-8"));
}
},
this.pythonPath
this.pythonPath,
true
);
if (result.type !== OperationResultType.commandResult || !result.result) {
// write red text into terminal
Expand Down Expand Up @@ -565,7 +567,8 @@ export default class Activator {
this.terminal?.write(data.toString("utf-8"));
}
},
this.pythonPath
this.pythonPath,
true
);
commandExecuting = false;
this.ui?.userOperationStopped();
Expand Down Expand Up @@ -1472,6 +1475,45 @@ export default class Activator {
);
context.subscriptions.push(disposable);

disposable = vscode.commands.registerCommand(
commandPrefix + "garbageCollect",
() => {
if (PicoMpyCom.getInstance().isPortDisconnected()) {
void vscode.window.showWarningMessage(
"Please connect to the Pico first."
);

return;
}

vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Running garbage collector...",
cancellable: false,
},
async progress => {
// gc currently not cancelable

const result = await PicoMpyCom.getInstance().garbageCollect();
progress.report({ increment: 100 });
if (
result.type === OperationResultType.commandResult &&
result.result
) {
void vscode.window.showInformationMessage(
"Garbage collection done"
);

return;
}

void vscode.window.showErrorMessage("Garbage collection failed");
}
);
}
);

const packagesWebviewProvider = new PackagesWebviewProvider(
context.extensionUri
);
Expand Down
7 changes: 7 additions & 0 deletions src/terminal.mts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ export class Terminal implements Pseudoterminal {
commands.executeCommand(commandPrefix + "reset.hard.listen");
this.writeEmitter.fire("\r\n");

return;
} else if (input === ".gc") {
commands.executeCommand(commandPrefix + "garbageCollect");
this.writeEmitter.fire("\r\n");
this.prompt();

return;
} else if (input === ".help") {
this.writeEmitter.fire("\r\n");
Expand All @@ -390,6 +396,7 @@ export class Terminal implements Pseudoterminal {
this.writeEmitter.fire(".rtc - get the time form the onboard RTC\r\n");
this.writeEmitter.fire(".sr - soft reset the Pico\r\n");
this.writeEmitter.fire(".hr - hard reset the Pico\r\n");
this.writeEmitter.fire(".gc - trigger garbage collector\r\n");

this.writeEmitter.fire(".help - show this help\r\n");
this.prompt();
Expand Down

0 comments on commit 1745af1

Please sign in to comment.