@@ -32,6 +32,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
3232 const rExtension = new apiImplementation . RExtensionImplementation ( ) ;
3333
3434
35+ // Register notebook provider
36+ const rNotebook = new RNotebookProvider ( path . join ( context . extensionPath , 'R' , 'notebook.R' ) )
37+ context . subscriptions . push (
38+ vscode . notebook . registerNotebookContentProvider (
39+ 'r-notebook' ,
40+ rNotebook
41+ )
42+ ) ;
43+
3544 // register commands specified in package.json
3645 const commands = {
3746 // create R terminal
@@ -95,8 +104,20 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
95104
96105 // browser controls
97106 'r.browser.refresh' : session . refreshBrowser ,
98- 'r.browser.openExternal' : session . openExternalBrowser
99- } ;
107+ 'r.browser.openExternal' : session . openExternalBrowser ,
108+
109+ // notebook commands
110+ 'r.notebook.restartKernel' : ( ) => {
111+ if ( vscode . window . activeNotebookEditor ) {
112+ const { document } = vscode . window . activeNotebookEditor ;
113+ const notebook = rNotebook . lookupNotebook ( document . uri ) ;
114+ if ( notebook ) {
115+ notebook . restartKernel ( ) ;
116+ }
117+ }
118+ }
119+ }
120+
100121 for ( const key in commands ) {
101122 context . subscriptions . push ( vscode . commands . registerCommand ( key , commands [ key ] ) ) ;
102123 }
@@ -169,12 +190,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
169190 vscode . languages . registerCompletionItemProvider ( 'r' , new completions . LiveCompletionItemProvider ( ) , ...liveTriggerCharacters ) ;
170191 }
171192
172- context . subscriptions . push (
173- vscode . notebook . registerNotebookContentProvider (
174- 'r-notebook' ,
175- new RNotebookProvider ( path . join ( context . extensionPath , 'R' , 'notebook.R' ) ) )
176- )
177- ) ;
193+
178194
179195 return rExtension ;
180196}
0 commit comments