5
5
* @module docprovider-extension
6
6
*/
7
7
8
+ import { NotebookCellServerExecutor } from '@jupyter/docprovider' ;
8
9
import {
9
10
JupyterFrontEnd ,
10
11
JupyterFrontEndPlugin
11
12
} 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' ;
16
14
import { INotebookCellExecutor , runCell } from '@jupyterlab/notebook' ;
17
15
18
16
export const notebookCellExecutor : JupyterFrontEndPlugin < INotebookCellExecutor > =
@@ -24,53 +22,10 @@ export const notebookCellExecutor: JupyterFrontEndPlugin<INotebookCellExecutor>
24
22
provides : INotebookCellExecutor ,
25
23
activate : ( app : JupyterFrontEnd ) : INotebookCellExecutor => {
26
24
if ( PageConfig . getOption ( 'serverSideExecution' ) === 'true' ) {
27
- return Object . freeze ( { runCell : runCellServerSide } ) ;
25
+ return new NotebookCellServerExecutor ( {
26
+ serverSettings : app . serviceManager . serverSettings
27
+ } ) ;
28
28
}
29
29
return Object . freeze ( { runCell } ) ;
30
30
}
31
31
} ;
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