Skip to content

Commit 3e6ee01

Browse files
committed
Move findLanguage function into helpers.ts
1 parent f6485da commit 3e6ee01

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import {
7373
import { CodeQlStatusBarHandler } from './status-bar';
7474

7575
import { Credentials } from './authentication';
76-
import { runRemoteQuery, findLanguage } from './run-remote-query';
76+
import { runRemoteQuery } from './run-remote-query';
7777

7878
/**
7979
* extension.ts
@@ -576,7 +576,7 @@ async function activateWithInstalledDistribution(
576576
return;
577577
}
578578
// If possible, only show databases with the right language (otherwise show all databases).
579-
const queryLanguage = await findLanguage(cliServer, uri);
579+
const queryLanguage = await helpers.findLanguage(cliServer, uri);
580580
if (queryLanguage) {
581581
filteredDBs = dbm.databaseItems.filter(db => db.language === queryLanguage);
582582
if (filteredDBs.length === 0) {

extensions/ql-vscode/src/helpers.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,34 @@ export async function isLikelyDatabaseRoot(maybeRoot: string) {
424424
export function isLikelyDbLanguageFolder(dbPath: string) {
425425
return !!path.basename(dbPath).startsWith('db-');
426426
}
427+
428+
/**
429+
* Finds the language that a query targets.
430+
* If it can't be autodetected, prompt the user to specify the language manually.
431+
*/
432+
export async function findLanguage(
433+
cliServer: CodeQLCliServer,
434+
queryUri: Uri | undefined
435+
): Promise<string | undefined> {
436+
const uri = queryUri || Window.activeTextEditor?.document.uri;
437+
if (uri !== undefined) {
438+
try {
439+
const queryInfo = await cliServer.resolveQueryByLanguage(getOnDiskWorkspaceFolders(), uri);
440+
const language = (Object.keys(queryInfo.byLanguage))[0];
441+
void logger.log(`Detected query language: ${language}`);
442+
return language;
443+
} catch (e) {
444+
void logger.log('Could not autodetect query language. Select language manually.');
445+
}
446+
}
447+
const availableLanguages = Object.keys(await cliServer.resolveLanguages());
448+
const language = await Window.showQuickPick(
449+
availableLanguages,
450+
{ placeHolder: 'Select target language for your query', ignoreFocusOut: true }
451+
);
452+
if (!language) {
453+
// This only happens if the user cancels the quick pick.
454+
void showAndLogErrorMessage('Language not found. Language must be specified manually.');
455+
}
456+
return language;
457+
}

extensions/ql-vscode/src/run-remote-query.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { QuickPickItem, Uri, window } from 'vscode';
22
import * as yaml from 'js-yaml';
33
import * as fs from 'fs-extra';
4-
import { getOnDiskWorkspaceFolders, showAndLogErrorMessage, showAndLogInformationMessage } from './helpers';
4+
import { findLanguage, showAndLogErrorMessage, showAndLogInformationMessage } from './helpers';
55
import { Credentials } from './authentication';
66
import * as cli from './cli';
77
import { logger } from './logging';
@@ -16,37 +16,6 @@ interface Config {
1616
const OWNER = 'dsp-testing';
1717
const REPO = 'qc-controller';
1818

19-
/**
20-
* Finds the language that a query targets.
21-
* If it can't be autodetected, prompt the user to specify the language manually.
22-
*/
23-
export async function findLanguage(
24-
cliServer: cli.CodeQLCliServer,
25-
queryUri: Uri | undefined
26-
): Promise<string | undefined> {
27-
const uri = queryUri || window.activeTextEditor?.document.uri;
28-
if (uri !== undefined) {
29-
try {
30-
const queryInfo = await cliServer.resolveQueryByLanguage(getOnDiskWorkspaceFolders(), uri);
31-
const language = (Object.keys(queryInfo.byLanguage))[0];
32-
void logger.log(`Detected query language: ${language}`);
33-
return language;
34-
} catch (e) {
35-
void logger.log('Could not autodetect query language. Select language manually.');
36-
}
37-
}
38-
const availableLanguages = Object.keys(await cliServer.resolveLanguages());
39-
const language = await window.showQuickPick(
40-
availableLanguages,
41-
{ placeHolder: 'Select target language for your query', ignoreFocusOut: true }
42-
);
43-
if (!language) {
44-
// This only happens if the user cancels the quick pick.
45-
void showAndLogErrorMessage('Language not found. Language must be specified manually.');
46-
}
47-
return language;
48-
}
49-
5019
interface RepoListQuickPickItem extends QuickPickItem {
5120
repoList: string[];
5221
}

0 commit comments

Comments
 (0)