@@ -32,6 +32,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
32
32
const rExtension = new apiImplementation . RExtensionImplementation ( ) ;
33
33
34
34
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
+
35
44
// register commands specified in package.json
36
45
const commands = {
37
46
// create R terminal
@@ -95,8 +104,20 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
95
104
96
105
// browser controls
97
106
'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
+
100
121
for ( const key in commands ) {
101
122
context . subscriptions . push ( vscode . commands . registerCommand ( key , commands [ key ] ) ) ;
102
123
}
@@ -169,12 +190,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
169
190
vscode . languages . registerCompletionItemProvider ( 'r' , new completions . LiveCompletionItemProvider ( ) , ...liveTriggerCharacters ) ;
170
191
}
171
192
172
- context . subscriptions . push (
173
- vscode . notebook . registerNotebookContentProvider (
174
- 'r-notebook' ,
175
- new RNotebookProvider ( path . join ( context . extensionPath , 'R' , 'notebook.R' ) ) )
176
- )
177
- ) ;
193
+
178
194
179
195
return rExtension ;
180
196
}
0 commit comments