@@ -8,7 +8,7 @@ import { Readable } from 'stream';
88import { StringDecoder } from 'string_decoder' ;
99import * as tk from 'tree-kill' ;
1010import { promisify } from 'util' ;
11- import { CancellationToken , Disposable , Uri , window } from 'vscode' ;
11+ import { CancellationToken , Disposable , Uri } from 'vscode' ;
1212
1313import { BQRSInfo , DecodedBqrsChunk } from './pure/bqrs-cli-types' ;
1414import { CliConfig } from './config' ;
@@ -43,6 +43,16 @@ export interface QuerySetup {
4343 compilationCache ?: string ;
4444}
4545
46+ /**
47+ * The expected output of `codeql resolve queries --format bylanguage`.
48+ */
49+ export interface QueryInfoByLanguage {
50+ // What should the value of these objects be? I've only ever seen it as an empty object.
51+ byLanguage : Record < string , Record < string , unknown > > ;
52+ noDeclaredLanguage : Record < string , unknown > ;
53+ multipleDeclaredLanguages : Record < string , unknown > ;
54+ }
55+
4656/**
4757 * The expected output of `codeql resolve database`.
4858 */
@@ -486,30 +496,14 @@ export class CodeQLCliServer implements Disposable {
486496 * Finds the language that a query is analyzing.
487497 * @param queryUri The URI of the query
488498 */
489- async findLanguage ( workspaces : string [ ] , queryUri ?: Uri ) : Promise < string > {
490- let language = '' ;
491- if ( queryUri ) {
492- const subcommandArgs = [
493- '--format' , 'bylanguage' ,
494- queryUri . fsPath ,
495- '--additional-packs' ,
496- workspaces . join ( path . delimiter )
497- ] ;
498- try {
499- const JSONResults = await this . runCodeQlCliCommand ( [ 'resolve' , 'queries' ] , subcommandArgs , 'Finding query language' ) ;
500-
501- // This corresponds to `codeql resolve queries <query> --format bylanguage | jq -r '.byLanguage | keys[]'`
502- language = Object . keys ( JSON . parse ( JSONResults ) . byLanguage ) [ 0 ] ;
503- }
504- catch ( e ) {
505- // Add an option to manually specify the language, in case automatic language detection fails.
506- void this . logger . log ( 'Failed to detect language. Using manual prompt instead.' ) ;
507- language = await window . showQuickPick (
508- [ 'cpp' , 'csharp' , 'go' , 'java' , 'javascript' , 'python' ] , { placeHolder : 'Select language' }
509- ) || '' ;
510- }
511- }
512- return language ;
499+ async resolveQueryByLanguage ( workspaces : string [ ] , queryUri : Uri ) : Promise < QueryInfoByLanguage > {
500+ const subcommandArgs = [
501+ '--format' , 'bylanguage' ,
502+ queryUri . fsPath ,
503+ '--additional-packs' ,
504+ workspaces . join ( path . delimiter )
505+ ] ;
506+ return JSON . parse ( await this . runCodeQlCliCommand ( [ 'resolve' , 'queries' ] , subcommandArgs , 'Resolving query by language' ) ) ;
513507 }
514508
515509 /**
0 commit comments