Address review comments
- Tweak return types + logging - Update changelog
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
## [UNRELEASED]
|
||||
|
||||
- Add a command _CodeQL: Run Query on Multiple Databases_, which lets users select multiple databases to run a query on. [#898](https://github.com/github/vscode-codeql/pull/898)
|
||||
- Autodetect what language a query targets. This refines the _CodeQL: Run Query on Multiple Databases_ command to only show relevant databases. [#915](https://github.com/github/vscode-codeql/pull/915)
|
||||
|
||||
## 1.5.2 - 13 July 2021
|
||||
|
||||
|
||||
@@ -570,11 +570,15 @@ async function activateWithInstalledDistribution(
|
||||
token: CancellationToken,
|
||||
uri: Uri | undefined
|
||||
) => {
|
||||
let filteredDBs = dbm.databaseItems;
|
||||
// If possible, only show databases with the right language (otherwise show all databases).
|
||||
const queryLanguage = await findLanguage(cliServer, uri);
|
||||
const filteredDBs = dbm.databaseItems.filter(db => db.language === queryLanguage);
|
||||
if (filteredDBs.length === 0) {
|
||||
void helpers.showAndLogErrorMessage(`No databases found for language ${queryLanguage}`);
|
||||
return;
|
||||
if (queryLanguage) {
|
||||
filteredDBs = dbm.databaseItems.filter(db => db.language === queryLanguage);
|
||||
if (filteredDBs.length === 0) {
|
||||
void helpers.showAndLogErrorMessage(`No databases found for language ${queryLanguage}. Please add a suitable database to your workspace.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const quickPickItems = filteredDBs.map<DatabaseQuickPickItem>(dbItem => (
|
||||
{
|
||||
@@ -588,7 +592,7 @@ async function activateWithInstalledDistribution(
|
||||
*/
|
||||
const quickpick = await window.showQuickPick<DatabaseQuickPickItem>(
|
||||
quickPickItems,
|
||||
{ canPickMany: true }
|
||||
{ canPickMany: true, ignoreFocusOut: true }
|
||||
);
|
||||
if (quickpick !== undefined) {
|
||||
// Collect all skipped databases and display them at the end (instead of popping up individual errors)
|
||||
|
||||
@@ -23,12 +23,14 @@ const REPO = 'qc-controller';
|
||||
export async function findLanguage(
|
||||
cliServer: cli.CodeQLCliServer,
|
||||
queryUri: Uri | undefined
|
||||
): Promise<string> {
|
||||
): Promise<string | undefined> {
|
||||
const uri = queryUri || window.activeTextEditor?.document.uri;
|
||||
if (uri !== undefined) {
|
||||
try {
|
||||
const queryInfo = await cliServer.resolveQueryByLanguage(getOnDiskWorkspaceFolders(), uri);
|
||||
return (Object.keys(queryInfo.byLanguage))[0];
|
||||
const language = (Object.keys(queryInfo.byLanguage))[0];
|
||||
void logger.log(`Detected query language: ${language}`);
|
||||
return language;
|
||||
} catch (e) {
|
||||
void logger.log('Could not autodetect query language. Select language manually.');
|
||||
}
|
||||
@@ -37,8 +39,8 @@ export async function findLanguage(
|
||||
const language = await window.showQuickPick(
|
||||
availableLanguages,
|
||||
{ placeHolder: 'Select target language for your query', ignoreFocusOut: true }
|
||||
) || '';
|
||||
if (language === '') {
|
||||
);
|
||||
if (!language) {
|
||||
// This only happens if the user cancels the quick pick.
|
||||
void showAndLogErrorMessage('Language not found. Language must be specified manually.');
|
||||
}
|
||||
@@ -68,6 +70,10 @@ export async function runRemoteQuery(cliServer: cli.CodeQLCliServer, credentials
|
||||
const language = config.language || await findLanguage(cliServer, uri);
|
||||
const repositories = config.repositories;
|
||||
|
||||
if (!language) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await octokit.request(
|
||||
'POST /repos/:owner/:repo/code-scanning/codeql/queries',
|
||||
|
||||
Reference in New Issue
Block a user