Skip to content

Commit af7bc8e

Browse files
committed
Delete temporary test command
1 parent 0b3ea16 commit af7bc8e

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

extensions/ql-vscode/package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,6 @@
245245
"command": "codeQL.runQuery",
246246
"title": "CodeQL: Run Query"
247247
},
248-
{
249-
"command": "codeQL.findLanguage",
250-
"title": "CodeQL: Find Language"
251-
},
252248
{
253249
"command": "codeQL.runQueryOnMultipleDatabases",
254250
"title": "CodeQL: Run Query on Multiple Databases"
@@ -688,10 +684,6 @@
688684
"command": "codeQL.runQuery",
689685
"when": "resourceLangId == ql && resourceExtname == .ql"
690686
},
691-
{
692-
"command": "codeQL.findLanguage",
693-
"when": "resourceLangId == ql && resourceExtname == .ql"
694-
},
695687
{
696688
"command": "codeQL.runQueryOnMultipleDatabases",
697689
"when": "resourceLangId == ql && resourceExtname == .ql"

extensions/ql-vscode/src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface QuerySetup {
4747
* The expected output of `codeql resolve queries --format bylanguage`.
4848
*/
4949
export interface QueryInfoByLanguage {
50-
// What should the value of these objects be? I've only ever seen it as an empty object.
50+
// Using `unknown` as a placeholder. For now, the value is only ever an empty object.
5151
byLanguage: Record<string, Record<string, unknown>>;
5252
noDeclaredLanguage: Record<string, unknown>;
5353
multipleDeclaredLanguages: Record<string, unknown>;
@@ -493,7 +493,7 @@ export class CodeQLCliServer implements Disposable {
493493
}
494494

495495
/**
496-
* Finds the language that a query is analyzing.
496+
* Resolves the language for a query.
497497
* @param queryUri The URI of the query
498498
*/
499499
async resolveQueryByLanguage(workspaces: string[], queryUri: Uri): Promise<QueryInfoByLanguage> {

extensions/ql-vscode/src/extension.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)