@@ -559,18 +559,30 @@ async function activateWithInstalledDistribution(
559559 }
560560 )
561561 ) ;
562- // TODO: Remove this and the package.json changes
563- // (Temporary new command to test `cliServer.findLanguage`)
564- ctx . subscriptions . push (
565- commandRunner ( 'codeQL.findLanguage' , async (
566- uri : Uri
567- ) => {
568- const diskWorkspaceFolders = helpers . getOnDiskWorkspaceFolders ( ) ;
569- const queryInfo = await cliServer . resolveQueryByLanguage ( diskWorkspaceFolders , uri || window . activeTextEditor ?. document . uri ) ;
570- const language = ( Object . keys ( queryInfo . byLanguage ) ) [ 0 ] ;
571- void helpers . showAndLogInformationMessage ( language ) ;
572- } )
573- ) ;
562+ /**
563+ * Finds the language that a query targets.
564+ * If it can't be autodetected, prompt the user to specify the language manually.
565+ */
566+ async function findLanguage (
567+ queryUri : Uri
568+ ) : Promise < string > {
569+ let language = '' ;
570+ try {
571+ const queryInfo = await cliServer . resolveQueryByLanguage ( helpers . getOnDiskWorkspaceFolders ( ) , queryUri || window . activeTextEditor ?. document . uri ) ;
572+ language = ( Object . keys ( queryInfo . byLanguage ) ) [ 0 ] ;
573+ } catch ( e ) {
574+ // Add an option to manually specify the language, in case automatic language detection fails.
575+ void logger . log ( 'Could not autodetect query language. Select language manually.' ) ;
576+ language = await window . showQuickPick (
577+ [ 'cpp' , 'csharp' , 'go' , 'java' , 'javascript' , 'ruby' , 'python' ] ,
578+ { placeHolder : 'Select target language for your query' , ignoreFocusOut : true }
579+ ) || '' ;
580+ }
581+ if ( language === '' ) {
582+ throw new Error ( 'Language not found' ) ;
583+ }
584+ return language ;
585+ }
574586 interface DatabaseQuickPickItem extends QuickPickItem {
575587 databaseItem : DatabaseItem ;
576588 }
0 commit comments