55 * @module docprovider-extension
66 */
77
8+ import { NotebookCellServerExecutor } from '@jupyter/docprovider' ;
89import {
910 JupyterFrontEnd ,
1011 JupyterFrontEndPlugin
1112} from '@jupyterlab/application' ;
12- import { PageConfig , URLExt } from '@jupyterlab/coreutils' ;
13- import { ServerConnection } from '@jupyterlab/services' ;
14-
15- import { type MarkdownCell } from '@jupyterlab/cells' ;
13+ import { PageConfig } from '@jupyterlab/coreutils' ;
1614import { INotebookCellExecutor , runCell } from '@jupyterlab/notebook' ;
1715
1816export const notebookCellExecutor : JupyterFrontEndPlugin < INotebookCellExecutor > =
@@ -24,53 +22,10 @@ export const notebookCellExecutor: JupyterFrontEndPlugin<INotebookCellExecutor>
2422 provides : INotebookCellExecutor ,
2523 activate : ( app : JupyterFrontEnd ) : INotebookCellExecutor => {
2624 if ( PageConfig . getOption ( 'serverSideExecution' ) === 'true' ) {
27- return Object . freeze ( { runCell : runCellServerSide } ) ;
25+ return new NotebookCellServerExecutor ( {
26+ serverSettings : app . serviceManager . serverSettings
27+ } ) ;
2828 }
2929 return Object . freeze ( { runCell } ) ;
3030 }
3131 } ;
32-
33- async function runCellServerSide ( {
34- cell,
35- notebook,
36- notebookConfig,
37- onCellExecuted,
38- onCellExecutionScheduled,
39- sessionContext,
40- sessionDialogs,
41- translator
42- } : INotebookCellExecutor . IRunCellOptions ) : Promise < boolean > {
43- switch ( cell . model . type ) {
44- case 'markdown' :
45- ( cell as MarkdownCell ) . rendered = true ;
46- cell . inputHidden = false ;
47- onCellExecuted ( { cell, success : true } ) ;
48- break ;
49- case 'code' : {
50- const kernelId = sessionContext ?. session ?. kernel ?. id ;
51- const settings = ServerConnection . makeSettings ( ) ;
52- const apiURL = URLExt . join (
53- settings . baseUrl ,
54- `api/kernels/${ kernelId } /execute`
55- ) ;
56- const cellId = cell . model . sharedModel . getId ( ) ;
57- const documentId = `json:notebook:${ notebook . sharedModel . getState (
58- 'file_id'
59- ) } `;
60- const body = `{"cell_id":"${ cellId } ","document_id":"${ documentId } "}` ;
61- const init = {
62- method : 'POST' ,
63- body
64- } ;
65- try {
66- await ServerConnection . makeRequest ( apiURL , init , settings ) ;
67- } catch ( error : any ) {
68- throw new ServerConnection . NetworkError ( error ) ;
69- }
70- break ;
71- }
72- default :
73- break ;
74- }
75- return Promise . resolve ( true ) ;
76- }
0 commit comments