@@ -40,6 +40,11 @@ import {
4040 ICodeSnippetEditorMetadata ,
4141} from './CodeSnippetEditor' ;
4242import { CodeSnippetService } from './CodeSnippetService' ;
43+ import { NotebookPanel } from '@jupyterlab/notebook' ;
44+ import { DocumentWidget } from '@jupyterlab/docregistry' ;
45+ // import { NotebookPanel } from '@jupyterlab/notebook';
46+ // import { ServerConnection, SettingManager } from '@jupyterlab/services';
47+ // import { URLExt } from '@jupyterlab/coreutils';
4348
4449const CODE_SNIPPET_EXTENSION_ID = 'code-snippet-extension' ;
4550
@@ -178,6 +183,16 @@ function activateCodeSnippet(
178183 isToggled : ( ) => toggled ,
179184 iconClass : 'some-css-icon-class' ,
180185 execute : ( ) => {
186+ let language = '' ;
187+ // get the language of document or notebook
188+ if ( app . shell . currentWidget instanceof NotebookPanel ) {
189+ language = ( app . shell . currentWidget as NotebookPanel ) . sessionContext
190+ . kernelPreference . language ;
191+ } else if ( app . shell . currentWidget instanceof DocumentWidget ) {
192+ language = ( app . shell . currentWidget as DocumentWidget ) . context . model
193+ . defaultKernelLanguage ;
194+ }
195+
181196 const highlightedCode = getSelectedText ( ) ;
182197 if ( highlightedCode === '' ) {
183198 //if user just right-clicks cell(s) to save
@@ -202,12 +217,14 @@ function activateCodeSnippet(
202217 CodeSnippetInputDialog (
203218 codeSnippetWidget ,
204219 resultArray ,
220+ language ,
205221 codeSnippetWidget . codeSnippetManager . snippets . length
206222 ) ;
207223 } else {
208224 CodeSnippetInputDialog (
209225 codeSnippetWidget ,
210226 highlightedCode . split ( '\n' ) ,
227+ language
211228 codeSnippetWidget . codeSnippetManager . snippets . length
212229 ) ;
213230 }
0 commit comments