Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
- Tweak return types + logging
- Update changelog
  • Loading branch information
shati-patel committed Aug 4, 2021
1 parent 1aef089 commit 83c68ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 9 additions & 5 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => (
{
Expand All @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions extensions/ql-vscode/src/run-remote-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand All @@ -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.');
}
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 83c68ec

Please sign in to comment.