Skip to content

Commit 8236b8a

Browse files
authored
Merge branch 'main' into case-insensitive-slugs
2 parents bef4175 + 20cdca7 commit 8236b8a

13 files changed

Lines changed: 124 additions & 67 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
## [UNRELEASED]
44

5+
- Fix a bug that shows 'Set current database' when hovering over the currently selected database in the databases view. [#976](https://github.com/github/vscode-codeql/pull/976)
6+
- Fix a bug with importing large databases. Databases over 4GB can now be imported directly from LGTM or from a zip file. This functionality is only available when using CodeQL CLI version 2.6.0 or later. [#971](https://github.com/github/vscode-codeql/pull/971)
7+
- Replace certain control codes (`U+0000` - `U+001F`) with their corresponding control labels (`U+2400` - `U+241F`) in the results view. [#963](https://github.com/github/vscode-codeql/pull/963)
8+
- Make project slug for GitHub repositories case-insensitive when adding a CodeQL database from LGTM. [#978](https://github.com/github/vscode-codeql/pull/961)
9+
10+
## 1.5.6 - 07 October 2021
11+
512
- Add progress messages to LGTM download option. This makes the two-step process (selecting a project, then selecting a language) more clear. [#960](https://github.com/github/vscode-codeql/pull/960)
613
- Remove line about selecting a language from the dropdown when downloading database from LGTM. This makes the download progress visible when the popup is not expanded. [#957](https://github.com/github/vscode-codeql/pull/957)
7-
- Fixed a bug where copying the version information fails when a CodeQL CLI cannot be found. [#958](https://github.com/github/vscode-codeql/pull/958)
814
- Fix a bug where copying the version information fails when a CodeQL CLI cannot be found. [#958](https://github.com/github/vscode-codeql/pull/958)
915
- Avoid a race condition when deleting databases that can cause occasional errors. [#959](https://github.com/github/vscode-codeql/pull/959)
1016
- Update CodeQL logos. [#965](https://github.com/github/vscode-codeql/pull/965)
11-
- Fixed a bug where copying the version information fails when a CodeQL CLI cannot be found. [#958](https://github.com/github/vscode-codeql/pull/958)
12-
- Make project slug for GitHub repositories case-insensitive when adding a CodeQL database from LGTM. [#961](https://github.com/github/vscode-codeql/pull/961)
1317

1418
## 1.5.5 - 08 September 2021
1519

-468 KB
Loading
Lines changed: 4 additions & 14 deletions
Loading

extensions/ql-vscode/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "CodeQL for Visual Studio Code",
55
"author": "GitHub",
66
"private": true,
7-
"version": "1.5.6",
7+
"version": "1.5.7",
88
"publisher": "GitHub",
99
"license": "MIT",
1010
"icon": "media/VS-marketplace-CodeQL-icon.png",
@@ -604,7 +604,7 @@
604604
{
605605
"command": "codeQLDatabases.setCurrentDatabase",
606606
"group": "inline",
607-
"when": "view == codeQLDatabases"
607+
"when": "view == codeQLDatabases && viewItem != currentDatabase"
608608
},
609609
{
610610
"command": "codeQLDatabases.removeDatabase",

extensions/ql-vscode/src/cli.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,15 @@ export class CodeQLCliServer implements Disposable {
600600
return await this.runJsonCodeQlCliCommand<BQRSInfo>(['bqrs', 'info'], subcommandArgs, 'Reading bqrs header');
601601
}
602602

603+
async databaseUnbundle(archivePath: string, target: string, name?: string): Promise<string> {
604+
const subcommandArgs = [];
605+
if (target) subcommandArgs.push('--target', target);
606+
if (name) subcommandArgs.push('--name', name);
607+
subcommandArgs.push(archivePath);
608+
609+
return await this.runCodeQlCliCommand(['database', 'unbundle'], subcommandArgs, `Extracting ${archivePath} to directory ${target}`);
610+
}
611+
603612
/**
604613
* Gets the results from a bqrs.
605614
* @param bqrsPath The path to the bqrs.
@@ -1074,6 +1083,11 @@ export class CliVersionConstraint {
10741083
*/
10751084
public static CLI_VERSION_WITH_ALLOW_LIBRARY_PACKS_IN_RESOLVE_QUERIES = new SemVer('2.6.1');
10761085

1086+
/**
1087+
* CLI version where the `database unbundle` subcommand was introduced.
1088+
*/
1089+
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer('2.6.0');
1090+
10771091
constructor(private readonly cli: CodeQLCliServer) {
10781092
/**/
10791093
}
@@ -1105,4 +1119,9 @@ export class CliVersionConstraint {
11051119
async supportsDatabaseRegistration() {
11061120
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DB_REGISTRATION);
11071121
}
1122+
1123+
async supportsDatabaseUnbundle() {
1124+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE);
1125+
}
1126+
11081127
}

extensions/ql-vscode/src/databaseFetcher.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import fetch, { Response } from 'node-fetch';
2-
import * as unzipper from 'unzipper';
32
import { zip } from 'zip-a-folder';
3+
import * as unzipper from 'unzipper';
44
import {
55
Uri,
66
CancellationToken,
77
commands,
88
window,
99
} from 'vscode';
10+
import { CodeQLCliServer } from './cli';
1011
import * as fs from 'fs-extra';
1112
import * as path from 'path';
1213

@@ -32,6 +33,7 @@ export async function promptImportInternetDatabase(
3233
storagePath: string,
3334
progress: ProgressCallback,
3435
token: CancellationToken,
36+
cli?: CodeQLCliServer
3537
): Promise<DatabaseItem | undefined> {
3638
const databaseUrl = await window.showInputBox({
3739
prompt: 'Enter URL of zipfile of database to download',
@@ -47,7 +49,8 @@ export async function promptImportInternetDatabase(
4749
databaseManager,
4850
storagePath,
4951
progress,
50-
token
52+
token,
53+
cli
5154
);
5255

5356
if (item) {
@@ -70,7 +73,8 @@ export async function promptImportLgtmDatabase(
7073
databaseManager: DatabaseManager,
7174
storagePath: string,
7275
progress: ProgressCallback,
73-
token: CancellationToken
76+
token: CancellationToken,
77+
cli?: CodeQLCliServer
7478
): Promise<DatabaseItem | undefined> {
7579
progress({
7680
message: 'Choose project',
@@ -93,7 +97,8 @@ export async function promptImportLgtmDatabase(
9397
databaseManager,
9498
storagePath,
9599
progress,
96-
token
100+
token,
101+
cli
97102
);
98103
if (item) {
99104
await commands.executeCommand('codeQLDatabases.focus');
@@ -130,14 +135,16 @@ export async function importArchiveDatabase(
130135
storagePath: string,
131136
progress: ProgressCallback,
132137
token: CancellationToken,
138+
cli?: CodeQLCliServer,
133139
): Promise<DatabaseItem | undefined> {
134140
try {
135141
const item = await databaseArchiveFetcher(
136142
databaseUrl,
137143
databaseManager,
138144
storagePath,
139145
progress,
140-
token
146+
token,
147+
cli
141148
);
142149
if (item) {
143150
await commands.executeCommand('codeQLDatabases.focus');
@@ -169,7 +176,8 @@ async function databaseArchiveFetcher(
169176
databaseManager: DatabaseManager,
170177
storagePath: string,
171178
progress: ProgressCallback,
172-
token: CancellationToken
179+
token: CancellationToken,
180+
cli?: CodeQLCliServer,
173181
): Promise<DatabaseItem> {
174182
progress({
175183
message: 'Getting database',
@@ -183,9 +191,9 @@ async function databaseArchiveFetcher(
183191
const unzipPath = await getStorageFolder(storagePath, databaseUrl);
184192

185193
if (isFile(databaseUrl)) {
186-
await readAndUnzip(databaseUrl, unzipPath, progress);
194+
await readAndUnzip(databaseUrl, unzipPath, cli, progress);
187195
} else {
188-
await fetchAndUnzip(databaseUrl, unzipPath, progress);
196+
await fetchAndUnzip(databaseUrl, unzipPath, cli, progress);
189197
}
190198

191199
progress({
@@ -259,6 +267,7 @@ function validateHttpsUrl(databaseUrl: string) {
259267
async function readAndUnzip(
260268
zipUrl: string,
261269
unzipPath: string,
270+
cli?: CodeQLCliServer,
262271
progress?: ProgressCallback
263272
) {
264273
// TODO: Providing progress as the file is unzipped is currently blocked
@@ -269,16 +278,22 @@ async function readAndUnzip(
269278
step: 9,
270279
message: `Unzipping into ${path.basename(unzipPath)}`
271280
});
272-
// Must get the zip central directory since streaming the
273-
// zip contents may not have correct local file headers.
274-
// Instead, we can only rely on the central directory.
275-
const directory = await unzipper.Open.file(zipFile);
276-
await directory.extract({ path: unzipPath });
281+
if (cli && await cli.cliConstraints.supportsDatabaseUnbundle()) {
282+
// Use the `database unbundle` command if the installed cli version supports it
283+
await cli.databaseUnbundle(zipFile, unzipPath);
284+
} else {
285+
// Must get the zip central directory since streaming the
286+
// zip contents may not have correct local file headers.
287+
// Instead, we can only rely on the central directory.
288+
const directory = await unzipper.Open.file(zipFile);
289+
await directory.extract({ path: unzipPath });
290+
}
277291
}
278292

279293
async function fetchAndUnzip(
280294
databaseUrl: string,
281295
unzipPath: string,
296+
cli?: CodeQLCliServer,
282297
progress?: ProgressCallback
283298
) {
284299
// Although it is possible to download and stream directly to an unzipped directory,
@@ -308,7 +323,8 @@ async function fetchAndUnzip(
308323
.on('error', reject)
309324
);
310325

311-
await readAndUnzip(Uri.file(archivePath).toString(true), unzipPath, progress);
326+
await readAndUnzip(Uri.file(archivePath).toString(true), unzipPath, cli, progress);
327+
312328

313329
// remove archivePath eagerly since these archives can be large.
314330
await fs.remove(archivePath);

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class DatabaseTreeDataProvider extends DisposableObject
135135
this.extensionPath,
136136
SELECTED_DATABASE_ICON
137137
);
138+
item.contextValue = 'currentDatabase';
138139
} else if (element.error !== undefined) {
139140
item.iconPath = joinThemableIconPath(
140141
this.extensionPath,
@@ -451,14 +452,13 @@ export class DatabaseUI extends DisposableObject {
451452
handleChooseDatabaseInternet = async (
452453
progress: ProgressCallback,
453454
token: CancellationToken
454-
): Promise<
455-
DatabaseItem | undefined
456-
> => {
455+
): Promise<DatabaseItem | undefined> => {
457456
return await promptImportInternetDatabase(
458457
this.databaseManager,
459458
this.storagePath,
460459
progress,
461-
token
460+
token,
461+
this.queryServer?.cliServer
462462
);
463463
};
464464

@@ -470,7 +470,8 @@ export class DatabaseUI extends DisposableObject {
470470
this.databaseManager,
471471
this.storagePath,
472472
progress,
473-
token
473+
token,
474+
this.queryServer?.cliServer
474475
);
475476
};
476477

@@ -580,7 +581,8 @@ export class DatabaseUI extends DisposableObject {
580581
this.databaseManager,
581582
this.storagePath,
582583
progress,
583-
token
584+
token,
585+
this.queryServer?.cliServer
584586
);
585587
} else {
586588
await this.setCurrentDatabase(progress, token, uri);
@@ -696,7 +698,6 @@ export class DatabaseUI extends DisposableObject {
696698
token: CancellationToken,
697699
): Promise<DatabaseItem | undefined> {
698700
const uri = await chooseDatabaseDir(byFolder);
699-
700701
if (!uri) {
701702
return undefined;
702703
}
@@ -713,7 +714,8 @@ export class DatabaseUI extends DisposableObject {
713714
this.databaseManager,
714715
this.storagePath,
715716
progress,
716-
token
717+
token,
718+
this.queryServer?.cliServer
717719
);
718720
}
719721
}

extensions/ql-vscode/src/databases.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ export class DatabaseManager extends DisposableObject {
731731
this._currentDatabaseItem = item;
732732
this.updatePersistedCurrentDatabaseItem();
733733

734+
await vscode.commands.executeCommand('setContext', 'codeQL.currentDatabaseItem', item?.name);
735+
734736
this._onDidChangeCurrentDatabaseItem.fire({
735737
item,
736738
kind: DatabaseEventKind.Change
@@ -811,6 +813,9 @@ export class DatabaseManager extends DisposableObject {
811813
vscode.workspace.updateWorkspaceFolders(folderIndex, 1);
812814
}
813815

816+
// Remove this database item from the allow-list
817+
await this.deregisterDatabase(progress, token, item);
818+
814819
// Delete folder from file system only if it is controlled by the extension
815820
if (this.isExtensionControlledLocation(item.databaseUri)) {
816821
void logger.log('Deleting database from filesystem.');
@@ -819,9 +824,6 @@ export class DatabaseManager extends DisposableObject {
819824
e => void logger.log(`Failed to delete '${item.databaseUri.fsPath}'. Reason: ${e.message}`));
820825
}
821826

822-
// Remove this database item from the allow-list
823-
await this.deregisterDatabase(progress, token, item);
824-
825827
// note that we use undefined as the item in order to reset the entire tree
826828
this._onDidChangeDatabaseItem.fire({
827829
item: undefined,

extensions/ql-vscode/src/view/RawTableValue.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ interface Props {
99
}
1010

1111
export default function RawTableValue(props: Props): JSX.Element {
12-
const v = props.value;
12+
const rawValue = props.value;
1313
if (
14-
typeof v === 'string'
15-
|| typeof v === 'number'
16-
|| typeof v === 'boolean'
14+
typeof rawValue === 'string'
15+
|| typeof rawValue === 'number'
16+
|| typeof rawValue === 'boolean'
1717
) {
18-
return <span>{v.toString()}</span>;
18+
return <span>{renderLocation(undefined, rawValue.toString())}</span>;
1919
}
2020

21-
return renderLocation(v.url, v.label, props.databaseUri);
21+
return renderLocation(rawValue.url, rawValue.label, props.databaseUri);
2222
}

0 commit comments

Comments
 (0)