Skip to content

Commit e7f5a0d

Browse files
authored
Pass cell metadata and cell id as metadata for execute_request (#13288)
* Expose cell metadata * pass cell metadata as the metadata for execute request, * add cellId to cell metadata when cell is generated * don't add the metadata, avoids messing up the file * news entry * reword news entry * JSONObject -> Record<string, any>
1 parent 4909821 commit e7f5a0d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

news/1 Enhancements/13252.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cell id and cell metadata are now passed as the metadata field for execute_request messages.
2+
(thanks [stisa](https://github.com/stisa/))

src/client/datascience/jupyter/jupyterNotebook.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,9 @@ export class JupyterNotebookBase implements INotebook {
859859

860860
private generateRequest = (
861861
code: string,
862-
silent?: boolean
862+
silent?: boolean,
863+
// tslint:disable-next-line: no-any
864+
metadata?: Record<string, any>
863865
): Kernel.IShellFuture<KernelMessage.IExecuteRequestMsg, KernelMessage.IExecuteReplyMsg> | undefined => {
864866
//traceInfo(`Executing code in jupyter : ${code}`);
865867
try {
@@ -873,7 +875,8 @@ export class JupyterNotebookBase implements INotebook {
873875
allow_stdin: true, // Allow when silent too in case runStartupCommands asks for a password
874876
store_history: !silent // Silent actually means don't output anything. Store_history is what affects execution_count
875877
},
876-
silent // Dispose only silent futures. Otherwise update_display_data doesn't finda future for a previous cell.
878+
silent, // Dispose only silent futures. Otherwise update_display_data doesn't find a future for a previous cell.
879+
metadata
877880
)
878881
: undefined;
879882
} catch (exc) {
@@ -1098,7 +1101,10 @@ export class JupyterNotebookBase implements INotebook {
10981101
subscriber.error(this.sessionStartTime, exitError);
10991102
subscriber.complete(this.sessionStartTime);
11001103
} else {
1101-
const request = this.generateRequest(concatMultilineStringInput(subscriber.cell.data.source), silent);
1104+
const request = this.generateRequest(concatMultilineStringInput(subscriber.cell.data.source), silent, {
1105+
...subscriber.cell.data.metadata,
1106+
...{ cellId: subscriber.cell.id }
1107+
});
11021108

11031109
// Transition to the busy stage
11041110
subscriber.cell.state = CellState.executing;

0 commit comments

Comments
 (0)