@@ -3,30 +3,65 @@ import { logMessage } from "./logger";
3
3
import { IJupyterExtensionApi } from "./types" ;
4
4
5
5
export async function registerWithJupyter ( ) {
6
- const jupyter = extensions . getExtension < IJupyterExtensionApi > (
7
- "ms-toolsai.jupyter"
8
- ) ;
9
- if ( ! jupyter ) {
10
- return ;
11
- }
12
- if ( ! jupyter . isActive ) {
13
- await jupyter . activate ( ) ;
14
- }
15
- if ( jupyter . exports . registerNewNotebookContent ) {
16
- jupyter . exports . registerNewNotebookContent ( {
17
- defaultCellLanguage : "typescript" ,
18
- } ) ;
19
- }
6
+ const jupyter = extensions . getExtension < IJupyterExtensionApi > (
7
+ "ms-toolsai.jupyter"
8
+ ) ;
9
+ if ( ! jupyter ) {
10
+ return ;
20
11
}
12
+ if ( ! jupyter . isActive ) {
13
+ await jupyter . activate ( ) ;
14
+ }
15
+ if ( jupyter . exports . registerNewNotebookContent ) {
16
+ jupyter . exports . registerNewNotebookContent ( {
17
+ defaultCellLanguage : "typescript" ,
18
+ } ) ;
19
+ }
20
+ }
21
+
22
+ export async function optIntoNativeNotebooks ( ) {
23
+ const settings = workspace . getConfiguration ( "jupyter" , undefined ) ;
24
+ const optInto = settings . get < string [ ] > ( "experiments.optInto" ) ;
25
+ if (
26
+ ! Array . isArray ( optInto ) ||
27
+ optInto . includes ( "All" ) ||
28
+ optInto . includes ( "__NativeNotebookEditor__" )
29
+ ) {
30
+ logMessage ( "Native Notebook already setup" ) ;
31
+ return ;
32
+ }
33
+ optInto . push ( "__NativeNotebookEditor__" ) ;
34
+ logMessage ( "Setting up Native Notebooks" ) ;
35
+ await settings . update (
36
+ "experiments.optInto" ,
37
+ optInto ,
38
+ ConfigurationTarget . Global
39
+ ) ;
40
+ }
21
41
22
- export async function optIntoNativeNotebooks ( ) {
23
- const settings = workspace . getConfiguration ( 'jupyter' , undefined ) ;
24
- const optInto = settings . get < string [ ] > ( 'experiments.optInto' ) ;
25
- if ( ! Array . isArray ( optInto ) || optInto . includes ( 'All' ) || optInto . includes ( '__NativeNotebookEditor__' ) ) {
26
- logMessage ( 'Native Notebook already setup' ) ;
27
- return ;
28
- }
29
- optInto . push ( '__NativeNotebookEditor__' ) ;
30
- logMessage ( 'Setting up Native Notebooks' ) ;
31
- await settings . update ( 'experiments.optInto' , optInto , ConfigurationTarget . Global ) ;
42
+ type EditorAssociation = {
43
+ viewType : string ;
44
+ filenamePattern : string ;
45
+ } ;
46
+
47
+ export async function configureEditor ( ) {
48
+ const settings = workspace . getConfiguration ( "workbench" , undefined ) ;
49
+ const associations = settings . get < EditorAssociation [ ] > ( "editorAssociations" ) ;
50
+ if (
51
+ ! Array . isArray ( associations ) ||
52
+ associations . find ( ( item ) => item . viewType === "jupyter-notebook" )
53
+ ) {
54
+ logMessage ( "Native Notebook Editor already setup" ) ;
55
+ return ;
56
+ }
57
+ associations . push ( {
58
+ viewType : "jupyter-notebook" ,
59
+ filenamePattern : "*.ipynb" ,
60
+ } ) ;
61
+ logMessage ( "Setting up Native Notebook Editor" ) ;
62
+ await settings . update (
63
+ "editorAssociations" ,
64
+ associations ,
65
+ ConfigurationTarget . Global
66
+ ) ;
32
67
}
0 commit comments