Skip to content

Commit

Permalink
Fix no prompt on automatically created vREPLs + duplicate vREPL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
paulober committed Jun 19, 2023
1 parent 2b139df commit 05e3498
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
38 changes: 27 additions & 11 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,28 @@ export default class Activator {
"Please close the new terminal instance!"
);
// would freeze old terminal
newTerminal.dispose();
//focusTerminal(terminalOptions);
//newTerminal.dispose();

// TODO: currently disreagarding if user has unsubmitted input in pty
// send enter for new prompt
newTerminal.sendText("\n");
}
}
})
);

context.subscriptions.push(
vscode.window.onDidCloseTerminal(closedTerminal => {
if (closedTerminal.creationOptions.name === TERMINAL_NAME) {
// close all other vREPL instance as they freeze anyway because the
// close operation does dispose the pty in the background
vscode.window.terminals
.filter(t => t.creationOptions.name === TERMINAL_NAME)
.forEach(t => t.dispose());
}
})
);

// register fs provider as early as possible
this.picoFs = new PicoWFs(this.pyb);
context.subscriptions.push(
Expand All @@ -260,7 +275,7 @@ export default class Activator {
settings.getBoolean(SettingsKey.openOnStart) &&
this.comDevice !== undefined
) {
focusTerminal(terminalOptions);
await focusTerminal(terminalOptions);
}

// [Command] help
Expand Down Expand Up @@ -341,7 +356,7 @@ export default class Activator {
}

let frozen = false;
focusTerminal(terminalOptions);
await focusTerminal(terminalOptions);
const data = await this.pyb.runFile(file, (data: string) => {
// only freeze after operation has started
if (!frozen) {
Expand Down Expand Up @@ -394,14 +409,15 @@ export default class Activator {
}

let frozen = false;
focusTerminal(terminalOptions);
await focusTerminal(terminalOptions);
await this.pyb.executeCommand(
"import uos; " +
"__pico_dir=uos.getcwd(); " +
`uos.chdir('${dirname(file)}'); ` +
"import uos as _pico_uos; " +
"__pico_dir=_pico_uos.getcwd(); " +
`_pico_uos.chdir('${dirname(file)}'); ` +
`execfile('${file}'); ` +
"uos.chdir(__pico_dir); " +
"del __pico_dir",
"_pico_uos.chdir(__pico_dir); " +
"del __pico_dir; " +
"del _pico_uos",
(data: string) => {
// only freeze after operation has started
if (!frozen) {
Expand Down Expand Up @@ -446,7 +462,7 @@ export default class Activator {
return;
} else {
let frozen = false;
focusTerminal();
await focusTerminal(terminalOptions);
const data = await this.pyb.executeCommand(
code,
(data: string) => {
Expand Down
9 changes: 7 additions & 2 deletions src/api.mts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ export async function getTypeshedPicoWStubPath(): Promise<
* @param terminalOptions ExtensionTerminalOptions required to create a
* new terminal if none already exists
*/
export function focusTerminal(
export async function focusTerminal(
terminalOptions?: ExtensionTerminalOptions
): void {
): Promise<void> {
const openTerminals = window.terminals;

const picoRepl = openTerminals.find(
Expand All @@ -203,6 +203,11 @@ export function focusTerminal(
if (terminalOptions) {
const terminal = window.createTerminal(terminalOptions);
terminal.show(false);
// wait for 200ms so the opening message of the terminal can be queued
await ((ms: number): Promise<void> =>
new Promise(resolve => {
setTimeout(resolve, ms);
}))(200);
} else {
void window.showWarningMessage("Pico vREPL not open.");
}
Expand Down

0 comments on commit 05e3498

Please sign in to comment.