Skip to content

Commit 31dccfc

Browse files
authored
Wait for the session to be ready when executing a command without opening the tab (#279)
* Await for the session to be ready * Apply prettier * Fix code diff in README.md * Fix code reference in README.md
1 parent 639bd2a commit 31dccfc

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

kernel-output/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ You can then add the commands to the palette by iterating
195195
on a list:
196196

197197
```ts
198-
// src/index.ts#L100-L103
198+
// src/index.ts#L104-L107
199199

200200
// add items in command palette and menu
201201
[CommandIDs.create, CommandIDs.execute].forEach(command => {
@@ -240,16 +240,12 @@ to be executed by the kernel. Then you will send it to your panel for execution
240240
and display:
241241

242242
```ts
243-
// src/index.ts#L78-L98
243+
// src/index.ts#L78-L102
244244

245245
commands.addCommand(CommandIDs.execute, {
246246
label: trans.__('Contact Kernel and Execute Code'),
247247
caption: trans.__('Contact Kernel and Execute Code'),
248248
execute: async () => {
249-
// Create the panel if it does not exist
250-
if (!panel) {
251-
await createPanel();
252-
}
253249
// Prompt the user about the statement to be executed
254250
const input = await InputDialog.getText({
255251
title: trans.__('Code to execute'),
@@ -259,7 +255,15 @@ commands.addCommand(CommandIDs.execute, {
259255
// Execute the statement
260256
if (input.button.accept) {
261257
const code = input.value || '';
262-
panel.execute(code);
258+
if (!panel) {
259+
// Create the panel if it does not exist
260+
createPanel().then(async panel => {
261+
await panel.session.ready;
262+
panel.execute(code);
263+
});
264+
} else {
265+
panel.execute(code);
266+
}
263267
}
264268
}
265269
});

kernel-output/src/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ function activate(
7979
label: trans.__('Contact Kernel and Execute Code'),
8080
caption: trans.__('Contact Kernel and Execute Code'),
8181
execute: async () => {
82-
// Create the panel if it does not exist
83-
if (!panel) {
84-
await createPanel();
85-
}
8682
// Prompt the user about the statement to be executed
8783
const input = await InputDialog.getText({
8884
title: trans.__('Code to execute'),
@@ -92,7 +88,15 @@ function activate(
9288
// Execute the statement
9389
if (input.button.accept) {
9490
const code = input.value || '';
95-
panel.execute(code);
91+
if (!panel) {
92+
// Create the panel if it does not exist
93+
createPanel().then(async panel => {
94+
await panel.session.ready;
95+
panel.execute(code);
96+
});
97+
} else {
98+
panel.execute(code);
99+
}
96100
}
97101
}
98102
});

0 commit comments

Comments
 (0)