Merge pull request #2525 from github/robertbrignull/sendRequest_progress
Remove ProgressCallback / CancellationToken arguments where they aren't used
This commit is contained in:
@@ -300,7 +300,6 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
|||||||
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
|
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
|
||||||
this.app.credentials,
|
this.app.credentials,
|
||||||
(update) => this.showProgress(update),
|
(update) => this.showProgress(update),
|
||||||
tokenSource.token,
|
|
||||||
this.cliServer,
|
this.cliServer,
|
||||||
);
|
);
|
||||||
if (!database) {
|
if (!database) {
|
||||||
@@ -354,16 +353,12 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
|||||||
|
|
||||||
// After the flow model has been generated, we can remove the temporary database
|
// After the flow model has been generated, we can remove the temporary database
|
||||||
// which we used for generating the flow model.
|
// which we used for generating the flow model.
|
||||||
await this.databaseManager.removeDatabaseItem(
|
await this.showProgress({
|
||||||
() =>
|
step: 3900,
|
||||||
this.showProgress({
|
maxStep: 4000,
|
||||||
step: 3900,
|
message: "Removing temporary database",
|
||||||
maxStep: 4000,
|
});
|
||||||
message: "Removing temporary database",
|
await this.databaseManager.removeDatabaseItem(database);
|
||||||
}),
|
|
||||||
tokenSource.token,
|
|
||||||
database,
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.clearProgress();
|
await this.clearProgress();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetch, { Response } from "node-fetch";
|
import fetch, { Response } from "node-fetch";
|
||||||
import { zip } from "zip-a-folder";
|
import { zip } from "zip-a-folder";
|
||||||
import { Open } from "unzipper";
|
import { Open } from "unzipper";
|
||||||
import { Uri, CancellationToken, window, InputBoxOptions } from "vscode";
|
import { Uri, window, InputBoxOptions } from "vscode";
|
||||||
import { CodeQLCliServer } from "../codeql-cli/cli";
|
import { CodeQLCliServer } from "../codeql-cli/cli";
|
||||||
import {
|
import {
|
||||||
ensureDir,
|
ensureDir,
|
||||||
@@ -44,7 +44,6 @@ export async function promptImportInternetDatabase(
|
|||||||
databaseManager: DatabaseManager,
|
databaseManager: DatabaseManager,
|
||||||
storagePath: string,
|
storagePath: string,
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
token: CancellationToken,
|
|
||||||
cli?: CodeQLCliServer,
|
cli?: CodeQLCliServer,
|
||||||
): Promise<DatabaseItem | undefined> {
|
): Promise<DatabaseItem | undefined> {
|
||||||
const databaseUrl = await window.showInputBox({
|
const databaseUrl = await window.showInputBox({
|
||||||
@@ -63,7 +62,6 @@ export async function promptImportInternetDatabase(
|
|||||||
storagePath,
|
storagePath,
|
||||||
undefined,
|
undefined,
|
||||||
progress,
|
progress,
|
||||||
token,
|
|
||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -86,7 +84,6 @@ export async function promptImportInternetDatabase(
|
|||||||
* @param storagePath where to store the unzipped database.
|
* @param storagePath where to store the unzipped database.
|
||||||
* @param credentials the credentials to use to authenticate with GitHub
|
* @param credentials the credentials to use to authenticate with GitHub
|
||||||
* @param progress the progress callback
|
* @param progress the progress callback
|
||||||
* @param token the cancellation token
|
|
||||||
* @param cli the CodeQL CLI server
|
* @param cli the CodeQL CLI server
|
||||||
*/
|
*/
|
||||||
export async function promptImportGithubDatabase(
|
export async function promptImportGithubDatabase(
|
||||||
@@ -95,7 +92,6 @@ export async function promptImportGithubDatabase(
|
|||||||
storagePath: string,
|
storagePath: string,
|
||||||
credentials: Credentials | undefined,
|
credentials: Credentials | undefined,
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
token: CancellationToken,
|
|
||||||
cli?: CodeQLCliServer,
|
cli?: CodeQLCliServer,
|
||||||
): Promise<DatabaseItem | undefined> {
|
): Promise<DatabaseItem | undefined> {
|
||||||
const githubRepo = await askForGitHubRepo(progress);
|
const githubRepo = await askForGitHubRepo(progress);
|
||||||
@@ -109,7 +105,6 @@ export async function promptImportGithubDatabase(
|
|||||||
storagePath,
|
storagePath,
|
||||||
credentials,
|
credentials,
|
||||||
progress,
|
progress,
|
||||||
token,
|
|
||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -157,7 +152,6 @@ export async function askForGitHubRepo(
|
|||||||
* @param storagePath where to store the unzipped database.
|
* @param storagePath where to store the unzipped database.
|
||||||
* @param credentials the credentials to use to authenticate with GitHub
|
* @param credentials the credentials to use to authenticate with GitHub
|
||||||
* @param progress the progress callback
|
* @param progress the progress callback
|
||||||
* @param token the cancellation token
|
|
||||||
* @param cli the CodeQL CLI server
|
* @param cli the CodeQL CLI server
|
||||||
* @param language the language to download. If undefined, the user will be prompted to choose a language.
|
* @param language the language to download. If undefined, the user will be prompted to choose a language.
|
||||||
**/
|
**/
|
||||||
@@ -167,7 +161,6 @@ export async function downloadGitHubDatabase(
|
|||||||
storagePath: string,
|
storagePath: string,
|
||||||
credentials: Credentials | undefined,
|
credentials: Credentials | undefined,
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
token: CancellationToken,
|
|
||||||
cli?: CodeQLCliServer,
|
cli?: CodeQLCliServer,
|
||||||
language?: string,
|
language?: string,
|
||||||
): Promise<DatabaseItem | undefined> {
|
): Promise<DatabaseItem | undefined> {
|
||||||
@@ -213,7 +206,6 @@ export async function downloadGitHubDatabase(
|
|||||||
storagePath,
|
storagePath,
|
||||||
`${owner}/${name}`,
|
`${owner}/${name}`,
|
||||||
progress,
|
progress,
|
||||||
token,
|
|
||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -231,7 +223,6 @@ export async function importArchiveDatabase(
|
|||||||
databaseManager: DatabaseManager,
|
databaseManager: DatabaseManager,
|
||||||
storagePath: string,
|
storagePath: string,
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
token: CancellationToken,
|
|
||||||
cli?: CodeQLCliServer,
|
cli?: CodeQLCliServer,
|
||||||
): Promise<DatabaseItem | undefined> {
|
): Promise<DatabaseItem | undefined> {
|
||||||
try {
|
try {
|
||||||
@@ -242,7 +233,6 @@ export async function importArchiveDatabase(
|
|||||||
storagePath,
|
storagePath,
|
||||||
undefined,
|
undefined,
|
||||||
progress,
|
progress,
|
||||||
token,
|
|
||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
if (item) {
|
if (item) {
|
||||||
@@ -275,7 +265,6 @@ export async function importArchiveDatabase(
|
|||||||
* @param storagePath where to store the unzipped database.
|
* @param storagePath where to store the unzipped database.
|
||||||
* @param nameOverride a name for the database that overrides the default
|
* @param nameOverride a name for the database that overrides the default
|
||||||
* @param progress callback to send progress messages to
|
* @param progress callback to send progress messages to
|
||||||
* @param token cancellation token
|
|
||||||
*/
|
*/
|
||||||
async function databaseArchiveFetcher(
|
async function databaseArchiveFetcher(
|
||||||
databaseUrl: string,
|
databaseUrl: string,
|
||||||
@@ -284,7 +273,6 @@ async function databaseArchiveFetcher(
|
|||||||
storagePath: string,
|
storagePath: string,
|
||||||
nameOverride: string | undefined,
|
nameOverride: string | undefined,
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
token: CancellationToken,
|
|
||||||
cli?: CodeQLCliServer,
|
cli?: CodeQLCliServer,
|
||||||
): Promise<DatabaseItem> {
|
): Promise<DatabaseItem> {
|
||||||
progress({
|
progress({
|
||||||
@@ -327,8 +315,6 @@ async function databaseArchiveFetcher(
|
|||||||
const makeSelected = true;
|
const makeSelected = true;
|
||||||
|
|
||||||
const item = await databaseManager.openDatabase(
|
const item = await databaseManager.openDatabase(
|
||||||
progress,
|
|
||||||
token,
|
|
||||||
Uri.file(dbPath),
|
Uri.file(dbPath),
|
||||||
makeSelected,
|
makeSelected,
|
||||||
nameOverride,
|
nameOverride,
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
|
|
||||||
private async handleSetDefaultTourDatabase(): Promise<void> {
|
private async handleSetDefaultTourDatabase(): Promise<void> {
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (progress, token) => {
|
async () => {
|
||||||
try {
|
try {
|
||||||
if (!workspace.workspaceFolders?.length) {
|
if (!workspace.workspaceFolders?.length) {
|
||||||
throw new Error("No workspace folder is open.");
|
throw new Error("No workspace folder is open.");
|
||||||
@@ -332,8 +332,6 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
const isTutorialDatabase = true;
|
const isTutorialDatabase = true;
|
||||||
|
|
||||||
await this.databaseManager.openDatabase(
|
await this.databaseManager.openDatabase(
|
||||||
progress,
|
|
||||||
token,
|
|
||||||
uri,
|
uri,
|
||||||
makeSelected,
|
makeSelected,
|
||||||
nameOverride,
|
nameOverride,
|
||||||
@@ -485,13 +483,12 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
|
|
||||||
private async handleChooseDatabaseInternet(): Promise<void> {
|
private async handleChooseDatabaseInternet(): Promise<void> {
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (progress, token) => {
|
async (progress) => {
|
||||||
await promptImportInternetDatabase(
|
await promptImportInternetDatabase(
|
||||||
this.app.commands,
|
this.app.commands,
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.storagePath,
|
this.storagePath,
|
||||||
progress,
|
progress,
|
||||||
token,
|
|
||||||
this.queryServer?.cliServer,
|
this.queryServer?.cliServer,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -503,7 +500,7 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
|
|
||||||
private async handleChooseDatabaseGithub(): Promise<void> {
|
private async handleChooseDatabaseGithub(): Promise<void> {
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (progress, token) => {
|
async (progress) => {
|
||||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||||
|
|
||||||
await promptImportGithubDatabase(
|
await promptImportGithubDatabase(
|
||||||
@@ -512,7 +509,6 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
this.storagePath,
|
this.storagePath,
|
||||||
credentials,
|
credentials,
|
||||||
progress,
|
progress,
|
||||||
token,
|
|
||||||
this.queryServer?.cliServer,
|
this.queryServer?.cliServer,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -608,14 +604,13 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
|
|
||||||
private async handleClearCache(): Promise<void> {
|
private async handleClearCache(): Promise<void> {
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (progress, token) => {
|
async (_progress, token) => {
|
||||||
if (
|
if (
|
||||||
this.queryServer !== undefined &&
|
this.queryServer !== undefined &&
|
||||||
this.databaseManager.currentDatabaseItem !== undefined
|
this.databaseManager.currentDatabaseItem !== undefined
|
||||||
) {
|
) {
|
||||||
await this.queryServer.clearCacheInDatabase(
|
await this.queryServer.clearCacheInDatabase(
|
||||||
this.databaseManager.currentDatabaseItem,
|
this.databaseManager.currentDatabaseItem,
|
||||||
progress,
|
|
||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -633,7 +628,7 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
|
|
||||||
private async handleSetCurrentDatabase(uri: Uri): Promise<void> {
|
private async handleSetCurrentDatabase(uri: Uri): Promise<void> {
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (progress, token) => {
|
async (progress) => {
|
||||||
try {
|
try {
|
||||||
// Assume user has selected an archive if the file has a .zip extension
|
// Assume user has selected an archive if the file has a .zip extension
|
||||||
if (uri.path.endsWith(".zip")) {
|
if (uri.path.endsWith(".zip")) {
|
||||||
@@ -643,11 +638,10 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.storagePath,
|
this.storagePath,
|
||||||
progress,
|
progress,
|
||||||
token,
|
|
||||||
this.queryServer?.cliServer,
|
this.queryServer?.cliServer,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await this.databaseManager.openDatabase(progress, token, uri);
|
await this.databaseManager.openDatabase(uri);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// rethrow and let this be handled by default error handling.
|
// rethrow and let this be handled by default error handling.
|
||||||
@@ -668,10 +662,10 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
databaseItems: DatabaseItem[],
|
databaseItems: DatabaseItem[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (progress, token) => {
|
async () => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
databaseItems.map((dbItem) =>
|
databaseItems.map((dbItem) =>
|
||||||
this.databaseManager.removeDatabaseItem(progress, token, dbItem),
|
this.databaseManager.removeDatabaseItem(dbItem),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -758,15 +752,11 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
|
|
||||||
return await withInheritedProgress(
|
return await withInheritedProgress(
|
||||||
progress,
|
progress,
|
||||||
async (progress, token) => {
|
async (progress) => {
|
||||||
if (byFolder) {
|
if (byFolder) {
|
||||||
const fixedUri = await this.fixDbUri(uri);
|
const fixedUri = await this.fixDbUri(uri);
|
||||||
// we are selecting a database folder
|
// we are selecting a database folder
|
||||||
return await this.databaseManager.openDatabase(
|
return await this.databaseManager.openDatabase(fixedUri);
|
||||||
progress,
|
|
||||||
token,
|
|
||||||
fixedUri,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// we are selecting a database archive. Must unzip into a workspace-controlled area
|
// we are selecting a database archive. Must unzip into a workspace-controlled area
|
||||||
// before importing.
|
// before importing.
|
||||||
@@ -776,7 +766,6 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.storagePath,
|
this.storagePath,
|
||||||
progress,
|
progress,
|
||||||
token,
|
|
||||||
this.queryServer?.cliServer,
|
this.queryServer?.cliServer,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,6 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
* databases.
|
* databases.
|
||||||
*/
|
*/
|
||||||
public async openDatabase(
|
public async openDatabase(
|
||||||
progress: ProgressCallback,
|
|
||||||
token: vscode.CancellationToken,
|
|
||||||
uri: vscode.Uri,
|
uri: vscode.Uri,
|
||||||
makeSelected = true,
|
makeSelected = true,
|
||||||
displayName?: string,
|
displayName?: string,
|
||||||
@@ -115,9 +113,7 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
|
|
||||||
return await this.addExistingDatabaseItem(
|
return await this.addExistingDatabaseItem(
|
||||||
databaseItem,
|
databaseItem,
|
||||||
progress,
|
|
||||||
makeSelected,
|
makeSelected,
|
||||||
token,
|
|
||||||
isTutorialDatabase,
|
isTutorialDatabase,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -130,9 +126,7 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
*/
|
*/
|
||||||
private async addExistingDatabaseItem(
|
private async addExistingDatabaseItem(
|
||||||
databaseItem: DatabaseItemImpl,
|
databaseItem: DatabaseItemImpl,
|
||||||
progress: ProgressCallback,
|
|
||||||
makeSelected: boolean,
|
makeSelected: boolean,
|
||||||
token: vscode.CancellationToken,
|
|
||||||
isTutorialDatabase?: boolean,
|
isTutorialDatabase?: boolean,
|
||||||
): Promise<DatabaseItem> {
|
): Promise<DatabaseItem> {
|
||||||
const existingItem = this.findDatabaseItem(databaseItem.databaseUri);
|
const existingItem = this.findDatabaseItem(databaseItem.databaseUri);
|
||||||
@@ -143,7 +137,7 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
return existingItem;
|
return existingItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.addDatabaseItem(progress, token, databaseItem);
|
await this.addDatabaseItem(databaseItem);
|
||||||
if (makeSelected) {
|
if (makeSelected) {
|
||||||
await this.setCurrentDatabaseItem(databaseItem);
|
await this.setCurrentDatabaseItem(databaseItem);
|
||||||
}
|
}
|
||||||
@@ -260,14 +254,11 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async reregisterDatabases(
|
private async reregisterDatabases(progress: ProgressCallback) {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: vscode.CancellationToken,
|
|
||||||
) {
|
|
||||||
let completed = 0;
|
let completed = 0;
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
this._databaseItems.map(async (databaseItem) => {
|
this._databaseItems.map(async (databaseItem) => {
|
||||||
await this.registerDatabase(progress, token, databaseItem);
|
await this.registerDatabase(databaseItem);
|
||||||
completed++;
|
completed++;
|
||||||
progress({
|
progress({
|
||||||
maxStep: this._databaseItems.length,
|
maxStep: this._databaseItems.length,
|
||||||
@@ -324,8 +315,6 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async createDatabaseItemFromPersistedState(
|
private async createDatabaseItemFromPersistedState(
|
||||||
progress: ProgressCallback,
|
|
||||||
token: vscode.CancellationToken,
|
|
||||||
state: PersistedDatabaseItem,
|
state: PersistedDatabaseItem,
|
||||||
): Promise<DatabaseItemImpl> {
|
): Promise<DatabaseItemImpl> {
|
||||||
let displayName: string | undefined = undefined;
|
let displayName: string | undefined = undefined;
|
||||||
@@ -356,12 +345,12 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
|
|
||||||
// Avoid persisting the database state after adding since that should happen only after
|
// Avoid persisting the database state after adding since that should happen only after
|
||||||
// all databases have been added.
|
// all databases have been added.
|
||||||
await this.addDatabaseItem(progress, token, item, false);
|
await this.addDatabaseItem(item, false);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async loadPersistedState(): Promise<void> {
|
public async loadPersistedState(): Promise<void> {
|
||||||
return withProgress(async (progress, token) => {
|
return withProgress(async (progress) => {
|
||||||
const currentDatabaseUri =
|
const currentDatabaseUri =
|
||||||
this.ctx.workspaceState.get<string>(CURRENT_DB);
|
this.ctx.workspaceState.get<string>(CURRENT_DB);
|
||||||
const databases = this.ctx.workspaceState.get<PersistedDatabaseItem[]>(
|
const databases = this.ctx.workspaceState.get<PersistedDatabaseItem[]>(
|
||||||
@@ -388,13 +377,11 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const databaseItem = await this.createDatabaseItemFromPersistedState(
|
const databaseItem = await this.createDatabaseItemFromPersistedState(
|
||||||
progress,
|
|
||||||
token,
|
|
||||||
database,
|
database,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
await this.refreshDatabase(databaseItem);
|
await this.refreshDatabase(databaseItem);
|
||||||
await this.registerDatabase(progress, token, databaseItem);
|
await this.registerDatabase(databaseItem);
|
||||||
if (currentDatabaseUri === database.uri) {
|
if (currentDatabaseUri === database.uri) {
|
||||||
await this.setCurrentDatabaseItem(databaseItem, true);
|
await this.setCurrentDatabaseItem(databaseItem, true);
|
||||||
}
|
}
|
||||||
@@ -489,8 +476,6 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async addDatabaseItem(
|
private async addDatabaseItem(
|
||||||
progress: ProgressCallback,
|
|
||||||
token: vscode.CancellationToken,
|
|
||||||
item: DatabaseItemImpl,
|
item: DatabaseItemImpl,
|
||||||
updatePersistedState = true,
|
updatePersistedState = true,
|
||||||
) {
|
) {
|
||||||
@@ -504,7 +489,7 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
// Database items reconstituted from persisted state
|
// Database items reconstituted from persisted state
|
||||||
// will not have their contents yet.
|
// will not have their contents yet.
|
||||||
if (item.contents?.datasetUri) {
|
if (item.contents?.datasetUri) {
|
||||||
await this.registerDatabase(progress, token, item);
|
await this.registerDatabase(item);
|
||||||
}
|
}
|
||||||
// note that we use undefined as the item in order to reset the entire tree
|
// note that we use undefined as the item in order to reset the entire tree
|
||||||
this._onDidChangeDatabaseItem.fire({
|
this._onDidChangeDatabaseItem.fire({
|
||||||
@@ -523,11 +508,7 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeDatabaseItem(
|
public async removeDatabaseItem(item: DatabaseItem) {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: vscode.CancellationToken,
|
|
||||||
item: DatabaseItem,
|
|
||||||
) {
|
|
||||||
if (this._currentDatabaseItem === item) {
|
if (this._currentDatabaseItem === item) {
|
||||||
this._currentDatabaseItem = undefined;
|
this._currentDatabaseItem = undefined;
|
||||||
}
|
}
|
||||||
@@ -549,7 +530,7 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove this database item from the allow-list
|
// Remove this database item from the allow-list
|
||||||
await this.deregisterDatabase(progress, token, item);
|
await this.deregisterDatabase(item);
|
||||||
|
|
||||||
// Delete folder from file system only if it is controlled by the extension
|
// Delete folder from file system only if it is controlled by the extension
|
||||||
if (this.isExtensionControlledLocation(item.databaseUri)) {
|
if (this.isExtensionControlledLocation(item.databaseUri)) {
|
||||||
@@ -572,22 +553,15 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeAllDatabases(
|
public async removeAllDatabases() {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: vscode.CancellationToken,
|
|
||||||
) {
|
|
||||||
for (const item of this.databaseItems) {
|
for (const item of this.databaseItems) {
|
||||||
await this.removeDatabaseItem(progress, token, item);
|
await this.removeDatabaseItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async deregisterDatabase(
|
private async deregisterDatabase(dbItem: DatabaseItem) {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: vscode.CancellationToken,
|
|
||||||
dbItem: DatabaseItem,
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
await this.qs.deregisterDatabase(progress, token, dbItem);
|
await this.qs.deregisterDatabase(dbItem);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = getErrorMessage(e);
|
const message = getErrorMessage(e);
|
||||||
if (message === "Connection is disposed.") {
|
if (message === "Connection is disposed.") {
|
||||||
@@ -600,12 +574,8 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async registerDatabase(
|
private async registerDatabase(dbItem: DatabaseItem) {
|
||||||
progress: ProgressCallback,
|
await this.qs.registerDatabase(dbItem);
|
||||||
token: vscode.CancellationToken,
|
|
||||||
dbItem: DatabaseItem,
|
|
||||||
) {
|
|
||||||
await this.qs.registerDatabase(progress, token, dbItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ export class LocalQueries extends DisposableObject {
|
|||||||
|
|
||||||
private async createSkeletonQuery(): Promise<void> {
|
private async createSkeletonQuery(): Promise<void> {
|
||||||
await withProgress(
|
await withProgress(
|
||||||
async (progress: ProgressCallback, token: CancellationToken) => {
|
async (progress: ProgressCallback) => {
|
||||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||||
const contextStoragePath =
|
const contextStoragePath =
|
||||||
this.app.workspaceStoragePath || this.app.globalStoragePath;
|
this.app.workspaceStoragePath || this.app.globalStoragePath;
|
||||||
@@ -294,7 +294,6 @@ export class LocalQueries extends DisposableObject {
|
|||||||
credentials,
|
credentials,
|
||||||
this.app.logger,
|
this.app.logger,
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
token,
|
|
||||||
contextStoragePath,
|
contextStoragePath,
|
||||||
);
|
);
|
||||||
await skeletonQueryWizard.execute();
|
await skeletonQueryWizard.execute();
|
||||||
|
|||||||
@@ -55,10 +55,9 @@ export class LegacyQueryRunner extends QueryRunner {
|
|||||||
}
|
}
|
||||||
async clearCacheInDatabase(
|
async clearCacheInDatabase(
|
||||||
dbItem: DatabaseItem,
|
dbItem: DatabaseItem,
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await clearCacheInDatabase(this.qs, dbItem, progress, token);
|
await clearCacheInDatabase(this.qs, dbItem, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async compileAndRunQueryAgainstDatabaseCore(
|
public async compileAndRunQueryAgainstDatabaseCore(
|
||||||
@@ -88,11 +87,7 @@ export class LegacyQueryRunner extends QueryRunner {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deregisterDatabase(
|
async deregisterDatabase(dbItem: DatabaseItem): Promise<void> {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
|
||||||
dbItem: DatabaseItem,
|
|
||||||
): Promise<void> {
|
|
||||||
if (dbItem.contents) {
|
if (dbItem.contents) {
|
||||||
const databases: Dataset[] = [
|
const databases: Dataset[] = [
|
||||||
{
|
{
|
||||||
@@ -100,19 +95,10 @@ export class LegacyQueryRunner extends QueryRunner {
|
|||||||
workingSet: "default",
|
workingSet: "default",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
await this.qs.sendRequest(
|
await this.qs.sendRequest(deregisterDatabases, { databases });
|
||||||
deregisterDatabases,
|
|
||||||
{ databases },
|
|
||||||
token,
|
|
||||||
progress,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async registerDatabase(
|
async registerDatabase(dbItem: DatabaseItem): Promise<void> {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
|
||||||
dbItem: DatabaseItem,
|
|
||||||
): Promise<void> {
|
|
||||||
if (dbItem.contents) {
|
if (dbItem.contents) {
|
||||||
const databases: Dataset[] = [
|
const databases: Dataset[] = [
|
||||||
{
|
{
|
||||||
@@ -120,12 +106,7 @@ export class LegacyQueryRunner extends QueryRunner {
|
|||||||
workingSet: "default",
|
workingSet: "default",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
await this.qs.sendRequest(
|
await this.qs.sendRequest(registerDatabases, { databases });
|
||||||
registerDatabases,
|
|
||||||
{ databases },
|
|
||||||
token,
|
|
||||||
progress,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -200,7 +200,6 @@ export class QueryInProgress {
|
|||||||
export async function clearCacheInDatabase(
|
export async function clearCacheInDatabase(
|
||||||
qs: qsClient.QueryServerClient,
|
qs: qsClient.QueryServerClient,
|
||||||
dbItem: DatabaseItem,
|
dbItem: DatabaseItem,
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
): Promise<messages.ClearCacheResult> {
|
): Promise<messages.ClearCacheResult> {
|
||||||
if (dbItem.contents === undefined) {
|
if (dbItem.contents === undefined) {
|
||||||
@@ -217,7 +216,7 @@ export async function clearCacheInDatabase(
|
|||||||
db,
|
db,
|
||||||
};
|
};
|
||||||
|
|
||||||
return qs.sendRequest(messages.clearCache, params, token, progress);
|
return qs.sendRequest(messages.clearCache, params, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reportNoUpgradePath(
|
function reportNoUpgradePath(
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ export class NewQueryRunner extends QueryRunner {
|
|||||||
|
|
||||||
async clearCacheInDatabase(
|
async clearCacheInDatabase(
|
||||||
dbItem: DatabaseItem,
|
dbItem: DatabaseItem,
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (dbItem.contents === undefined) {
|
if (dbItem.contents === undefined) {
|
||||||
@@ -68,7 +67,7 @@ export class NewQueryRunner extends QueryRunner {
|
|||||||
dryRun: false,
|
dryRun: false,
|
||||||
db,
|
db,
|
||||||
};
|
};
|
||||||
await this.qs.sendRequest(clearCache, params, token, progress);
|
await this.qs.sendRequest(clearCache, params, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async compileAndRunQueryAgainstDatabaseCore(
|
public async compileAndRunQueryAgainstDatabaseCore(
|
||||||
@@ -98,34 +97,16 @@ export class NewQueryRunner extends QueryRunner {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deregisterDatabase(
|
async deregisterDatabase(dbItem: DatabaseItem): Promise<void> {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
|
||||||
dbItem: DatabaseItem,
|
|
||||||
): Promise<void> {
|
|
||||||
if (dbItem.contents) {
|
if (dbItem.contents) {
|
||||||
const databases: string[] = [dbItem.databaseUri.fsPath];
|
const databases: string[] = [dbItem.databaseUri.fsPath];
|
||||||
await this.qs.sendRequest(
|
await this.qs.sendRequest(deregisterDatabases, { databases });
|
||||||
deregisterDatabases,
|
|
||||||
{ databases },
|
|
||||||
token,
|
|
||||||
progress,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async registerDatabase(
|
async registerDatabase(dbItem: DatabaseItem): Promise<void> {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
|
||||||
dbItem: DatabaseItem,
|
|
||||||
): Promise<void> {
|
|
||||||
if (dbItem.contents) {
|
if (dbItem.contents) {
|
||||||
const databases: string[] = [dbItem.databaseUri.fsPath];
|
const databases: string[] = [dbItem.databaseUri.fsPath];
|
||||||
await this.qs.sendRequest(
|
await this.qs.sendRequest(registerDatabases, { databases });
|
||||||
registerDatabases,
|
|
||||||
{ databases },
|
|
||||||
token,
|
|
||||||
progress,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ export abstract class QueryRunner {
|
|||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
) => Promise<void>,
|
) => Promise<void>,
|
||||||
): void;
|
): void;
|
||||||
|
|
||||||
abstract clearCacheInDatabase(
|
abstract clearCacheInDatabase(
|
||||||
dbItem: DatabaseItem,
|
dbItem: DatabaseItem,
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
|
||||||
@@ -83,17 +83,9 @@ export abstract class QueryRunner {
|
|||||||
logger: BaseLogger,
|
logger: BaseLogger,
|
||||||
): Promise<CoreQueryResults>;
|
): Promise<CoreQueryResults>;
|
||||||
|
|
||||||
abstract deregisterDatabase(
|
abstract deregisterDatabase(dbItem: DatabaseItem): Promise<void>;
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
|
||||||
dbItem: DatabaseItem,
|
|
||||||
): Promise<void>;
|
|
||||||
|
|
||||||
abstract registerDatabase(
|
abstract registerDatabase(dbItem: DatabaseItem): Promise<void>;
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
|
||||||
dbItem: DatabaseItem,
|
|
||||||
): Promise<void>;
|
|
||||||
|
|
||||||
abstract upgradeDatabaseExplicit(
|
abstract upgradeDatabaseExplicit(
|
||||||
dbItem: DatabaseItem,
|
dbItem: DatabaseItem,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export class TestRunner extends DisposableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.removeDatabasesBeforeTests(databasesUnderTest, token);
|
await this.removeDatabasesBeforeTests(databasesUnderTest);
|
||||||
try {
|
try {
|
||||||
const workspacePaths = getOnDiskWorkspaceFolders();
|
const workspacePaths = getOnDiskWorkspaceFolders();
|
||||||
for await (const event of this.cliServer.runTests(tests, workspacePaths, {
|
for await (const event of this.cliServer.runTests(tests, workspacePaths, {
|
||||||
@@ -66,24 +66,16 @@ export class TestRunner extends DisposableObject {
|
|||||||
await this.reopenDatabasesAfterTests(
|
await this.reopenDatabasesAfterTests(
|
||||||
databasesUnderTest,
|
databasesUnderTest,
|
||||||
currentDatabaseUri,
|
currentDatabaseUri,
|
||||||
token,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async removeDatabasesBeforeTests(
|
private async removeDatabasesBeforeTests(
|
||||||
databasesUnderTest: DatabaseItem[],
|
databasesUnderTest: DatabaseItem[],
|
||||||
token: CancellationToken,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
for (const database of databasesUnderTest) {
|
for (const database of databasesUnderTest) {
|
||||||
try {
|
try {
|
||||||
await this.databaseManager.removeDatabaseItem(
|
await this.databaseManager.removeDatabaseItem(database);
|
||||||
(_) => {
|
|
||||||
/* no progress reporting */
|
|
||||||
},
|
|
||||||
token,
|
|
||||||
database,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// This method is invoked from Test Explorer UI, and testing indicates that Test
|
// This method is invoked from Test Explorer UI, and testing indicates that Test
|
||||||
// Explorer UI swallows any thrown exception without reporting it to the user.
|
// Explorer UI swallows any thrown exception without reporting it to the user.
|
||||||
@@ -103,17 +95,12 @@ export class TestRunner extends DisposableObject {
|
|||||||
private async reopenDatabasesAfterTests(
|
private async reopenDatabasesAfterTests(
|
||||||
databasesUnderTest: DatabaseItem[],
|
databasesUnderTest: DatabaseItem[],
|
||||||
currentDatabaseUri: Uri | undefined,
|
currentDatabaseUri: Uri | undefined,
|
||||||
token: CancellationToken,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
for (const closedDatabase of databasesUnderTest) {
|
for (const closedDatabase of databasesUnderTest) {
|
||||||
const uri = closedDatabase.databaseUri;
|
const uri = closedDatabase.databaseUri;
|
||||||
if (await isFileAccessible(uri)) {
|
if (await isFileAccessible(uri)) {
|
||||||
try {
|
try {
|
||||||
const reopenedDatabase = await this.databaseManager.openDatabase(
|
const reopenedDatabase = await this.databaseManager.openDatabase(
|
||||||
(_) => {
|
|
||||||
/* no progress reporting */
|
|
||||||
},
|
|
||||||
token,
|
|
||||||
uri,
|
uri,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { CancellationToken, Uri, workspace, window as Window } from "vscode";
|
import { Uri, workspace, window as Window } from "vscode";
|
||||||
import { CodeQLCliServer } from "./codeql-cli/cli";
|
import { CodeQLCliServer } from "./codeql-cli/cli";
|
||||||
import { BaseLogger } from "./common";
|
import { BaseLogger } from "./common";
|
||||||
import { Credentials } from "./common/authentication";
|
import { Credentials } from "./common/authentication";
|
||||||
@@ -51,7 +51,6 @@ export class SkeletonQueryWizard {
|
|||||||
private readonly credentials: Credentials | undefined,
|
private readonly credentials: Credentials | undefined,
|
||||||
private readonly logger: BaseLogger,
|
private readonly logger: BaseLogger,
|
||||||
private readonly databaseManager: DatabaseManager,
|
private readonly databaseManager: DatabaseManager,
|
||||||
private readonly token: CancellationToken,
|
|
||||||
private readonly databaseStoragePath: string | undefined,
|
private readonly databaseStoragePath: string | undefined,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -258,7 +257,6 @@ export class SkeletonQueryWizard {
|
|||||||
this.databaseStoragePath,
|
this.databaseStoragePath,
|
||||||
this.credentials,
|
this.credentials,
|
||||||
this.progress,
|
this.progress,
|
||||||
this.token,
|
|
||||||
this.cliServer,
|
this.cliServer,
|
||||||
this.language,
|
this.language,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { CancellationToken, Uri, window } from "vscode";
|
import { Uri, window } from "vscode";
|
||||||
|
|
||||||
import { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
|
import { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
|
||||||
import { DatabaseManager } from "../../../../src/databases/local-databases";
|
import { DatabaseManager } from "../../../../src/databases/local-databases";
|
||||||
@@ -52,7 +52,6 @@ describe("database-fetcher", () => {
|
|||||||
databaseManager,
|
databaseManager,
|
||||||
storagePath,
|
storagePath,
|
||||||
progressCallback,
|
progressCallback,
|
||||||
{} as CancellationToken,
|
|
||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
expect(dbItem).toBe(databaseManager.currentDatabaseItem);
|
expect(dbItem).toBe(databaseManager.currentDatabaseItem);
|
||||||
@@ -74,7 +73,6 @@ describe("database-fetcher", () => {
|
|||||||
databaseManager,
|
databaseManager,
|
||||||
storagePath,
|
storagePath,
|
||||||
progressCallback,
|
progressCallback,
|
||||||
{} as CancellationToken,
|
|
||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
expect(dbItem).toBeDefined();
|
expect(dbItem).toBeDefined();
|
||||||
|
|||||||
@@ -142,14 +142,7 @@ describeWithCodeQL()("using the legacy query server", () => {
|
|||||||
const parsedResults = new Checkpoint<void>();
|
const parsedResults = new Checkpoint<void>();
|
||||||
|
|
||||||
it("should register the database if necessary", async () => {
|
it("should register the database if necessary", async () => {
|
||||||
await qs.sendRequest(
|
await qs.sendRequest(messages.registerDatabases, { databases: [db] });
|
||||||
messages.registerDatabases,
|
|
||||||
{ databases: [db] },
|
|
||||||
token,
|
|
||||||
(() => {
|
|
||||||
/**/
|
|
||||||
}) as any,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should be able to compile query ${queryName}`, async () => {
|
it(`should be able to compile query ${queryName}`, async () => {
|
||||||
|
|||||||
@@ -152,14 +152,7 @@ describeWithCodeQL()("using the new query server", () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await qs.sendRequest(
|
await qs.sendRequest(messages.registerDatabases, { databases: [db] });
|
||||||
messages.registerDatabases,
|
|
||||||
{ databases: [db] },
|
|
||||||
token,
|
|
||||||
(() => {
|
|
||||||
/**/
|
|
||||||
}) as any,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should be able to run query ${queryName}`, async () => {
|
it(`should be able to run query ${queryName}`, async () => {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { QlPackGenerator } from "../../../src/qlpack-generator";
|
|||||||
import * as workspaceFolders from "../../../src/common/vscode/workspace-folders";
|
import * as workspaceFolders from "../../../src/common/vscode/workspace-folders";
|
||||||
import { createFileSync, ensureDirSync, removeSync } from "fs-extra";
|
import { createFileSync, ensureDirSync, removeSync } from "fs-extra";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { CancellationTokenSource } from "vscode-jsonrpc";
|
|
||||||
import { testCredentialsWithStub } from "../../factories/authentication";
|
import { testCredentialsWithStub } from "../../factories/authentication";
|
||||||
import {
|
import {
|
||||||
DatabaseItem,
|
DatabaseItem,
|
||||||
@@ -47,7 +46,6 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
typeof workspace.openTextDocument
|
typeof workspace.openTextDocument
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const token = new CancellationTokenSource().token;
|
|
||||||
const credentials = testCredentialsWithStub();
|
const credentials = testCredentialsWithStub();
|
||||||
const chosenLanguage = "ruby";
|
const chosenLanguage = "ruby";
|
||||||
|
|
||||||
@@ -117,7 +115,6 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
credentials,
|
credentials,
|
||||||
extLogger,
|
extLogger,
|
||||||
mockDatabaseManager,
|
mockDatabaseManager,
|
||||||
token,
|
|
||||||
storagePath,
|
storagePath,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -252,7 +249,6 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
credentials,
|
credentials,
|
||||||
extLogger,
|
extLogger,
|
||||||
mockDatabaseManagerWithItems,
|
mockDatabaseManagerWithItems,
|
||||||
token,
|
|
||||||
storagePath,
|
storagePath,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { load, dump } from "js-yaml";
|
import { load, dump } from "js-yaml";
|
||||||
import { realpathSync, readFileSync, writeFileSync } from "fs-extra";
|
import { realpathSync, readFileSync, writeFileSync } from "fs-extra";
|
||||||
import {
|
import { Uri, extensions } from "vscode";
|
||||||
CancellationToken,
|
|
||||||
CancellationTokenSource,
|
|
||||||
Uri,
|
|
||||||
extensions,
|
|
||||||
} from "vscode";
|
|
||||||
import {
|
import {
|
||||||
DatabaseItem,
|
DatabaseItem,
|
||||||
DatabaseManager,
|
DatabaseManager,
|
||||||
@@ -14,7 +9,6 @@ import {
|
|||||||
import { CodeQLCliServer } from "../../src/codeql-cli/cli";
|
import { CodeQLCliServer } from "../../src/codeql-cli/cli";
|
||||||
import { removeWorkspaceRefs } from "../../src/variant-analysis/run-remote-query";
|
import { removeWorkspaceRefs } from "../../src/variant-analysis/run-remote-query";
|
||||||
import { CodeQLExtensionInterface } from "../../src/extension";
|
import { CodeQLExtensionInterface } from "../../src/extension";
|
||||||
import { ProgressCallback } from "../../src/common/vscode/progress";
|
|
||||||
import { importArchiveDatabase } from "../../src/databases/database-fetcher";
|
import { importArchiveDatabase } from "../../src/databases/database-fetcher";
|
||||||
import { createMockCommandManager } from "../__mocks__/commandsMock";
|
import { createMockCommandManager } from "../__mocks__/commandsMock";
|
||||||
|
|
||||||
@@ -49,7 +43,6 @@ export async function ensureTestDatabase(
|
|||||||
(_p) => {
|
(_p) => {
|
||||||
/**/
|
/**/
|
||||||
},
|
},
|
||||||
new CancellationTokenSource().token,
|
|
||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -77,10 +70,7 @@ export async function getActivatedExtension(): Promise<CodeQLExtensionInterface>
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function cleanDatabases(databaseManager: DatabaseManager) {
|
export async function cleanDatabases(databaseManager: DatabaseManager) {
|
||||||
await databaseManager.removeAllDatabases(
|
await databaseManager.removeAllDatabases();
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as tmp from "tmp";
|
import * as tmp from "tmp";
|
||||||
import * as fs from "fs-extra";
|
import * as fs from "fs-extra";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { CancellationToken, ExtensionContext, Uri, workspace } from "vscode";
|
import { ExtensionContext, Uri, workspace } from "vscode";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DatabaseContentsWithDbScheme,
|
DatabaseContentsWithDbScheme,
|
||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
FullDatabaseOptions,
|
FullDatabaseOptions,
|
||||||
} from "../../../src/databases/local-databases";
|
} from "../../../src/databases/local-databases";
|
||||||
import { Logger } from "../../../src/common";
|
import { Logger } from "../../../src/common";
|
||||||
import { ProgressCallback } from "../../../src/common/vscode/progress";
|
|
||||||
import { CodeQLCliServer, DbInfo } from "../../../src/codeql-cli/cli";
|
import { CodeQLCliServer, DbInfo } from "../../../src/codeql-cli/cli";
|
||||||
import {
|
import {
|
||||||
encodeArchiveBasePath,
|
encodeArchiveBasePath,
|
||||||
@@ -119,11 +118,7 @@ describe("local databases", () => {
|
|||||||
const mockDbItem = createMockDB(dir);
|
const mockDbItem = createMockDB(dir);
|
||||||
const onDidChangeDatabaseItem = jest.fn();
|
const onDidChangeDatabaseItem = jest.fn();
|
||||||
databaseManager.onDidChangeDatabaseItem(onDidChangeDatabaseItem);
|
databaseManager.onDidChangeDatabaseItem(onDidChangeDatabaseItem);
|
||||||
await (databaseManager as any).addDatabaseItem(
|
await (databaseManager as any).addDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect((databaseManager as any)._databaseItems).toEqual([mockDbItem]);
|
expect((databaseManager as any)._databaseItems).toEqual([mockDbItem]);
|
||||||
expect(updateSpy).toBeCalledWith("databaseList", [
|
expect(updateSpy).toBeCalledWith("databaseList", [
|
||||||
@@ -141,11 +136,7 @@ describe("local databases", () => {
|
|||||||
onDidChangeDatabaseItem.mockClear();
|
onDidChangeDatabaseItem.mockClear();
|
||||||
|
|
||||||
// now remove the item
|
// now remove the item
|
||||||
await databaseManager.removeDatabaseItem(
|
await databaseManager.removeDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
expect((databaseManager as any)._databaseItems).toEqual([]);
|
expect((databaseManager as any)._databaseItems).toEqual([]);
|
||||||
expect(updateSpy).toBeCalledWith("databaseList", []);
|
expect(updateSpy).toBeCalledWith("databaseList", []);
|
||||||
expect(onDidChangeDatabaseItem).toBeCalledWith({
|
expect(onDidChangeDatabaseItem).toBeCalledWith({
|
||||||
@@ -159,11 +150,7 @@ describe("local databases", () => {
|
|||||||
const mockDbItem = createMockDB(dir);
|
const mockDbItem = createMockDB(dir);
|
||||||
const onDidChangeDatabaseItem = jest.fn();
|
const onDidChangeDatabaseItem = jest.fn();
|
||||||
databaseManager.onDidChangeDatabaseItem(onDidChangeDatabaseItem);
|
databaseManager.onDidChangeDatabaseItem(onDidChangeDatabaseItem);
|
||||||
await (databaseManager as any).addDatabaseItem(
|
await (databaseManager as any).addDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
await databaseManager.renameDatabaseItem(mockDbItem, "new name");
|
await databaseManager.renameDatabaseItem(mockDbItem, "new name");
|
||||||
|
|
||||||
@@ -188,11 +175,7 @@ describe("local databases", () => {
|
|||||||
databaseManager.onDidChangeDatabaseItem(onDidChangeDatabaseItem);
|
databaseManager.onDidChangeDatabaseItem(onDidChangeDatabaseItem);
|
||||||
const mockDbItem = createMockDB(dir);
|
const mockDbItem = createMockDB(dir);
|
||||||
|
|
||||||
await (databaseManager as any).addDatabaseItem(
|
await (databaseManager as any).addDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(databaseManager.databaseItems).toEqual([mockDbItem]);
|
expect(databaseManager.databaseItems).toEqual([mockDbItem]);
|
||||||
expect(updateSpy).toBeCalledWith("databaseList", [
|
expect(updateSpy).toBeCalledWith("databaseList", [
|
||||||
@@ -235,19 +218,11 @@ describe("local databases", () => {
|
|||||||
.spyOn(mockDbItem, "belongsToSourceArchiveExplorerUri")
|
.spyOn(mockDbItem, "belongsToSourceArchiveExplorerUri")
|
||||||
.mockReturnValue(true);
|
.mockReturnValue(true);
|
||||||
|
|
||||||
await (databaseManager as any).addDatabaseItem(
|
await (databaseManager as any).addDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
updateSpy.mockClear();
|
updateSpy.mockClear();
|
||||||
|
|
||||||
await databaseManager.removeDatabaseItem(
|
await databaseManager.removeDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(databaseManager.databaseItems).toEqual([]);
|
expect(databaseManager.databaseItems).toEqual([]);
|
||||||
expect(updateSpy).toBeCalledWith("databaseList", []);
|
expect(updateSpy).toBeCalledWith("databaseList", []);
|
||||||
@@ -268,22 +243,14 @@ describe("local databases", () => {
|
|||||||
jest
|
jest
|
||||||
.spyOn(mockDbItem, "belongsToSourceArchiveExplorerUri")
|
.spyOn(mockDbItem, "belongsToSourceArchiveExplorerUri")
|
||||||
.mockReturnValue(true);
|
.mockReturnValue(true);
|
||||||
await (databaseManager as any).addDatabaseItem(
|
await (databaseManager as any).addDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
updateSpy.mockClear();
|
updateSpy.mockClear();
|
||||||
|
|
||||||
// pretend that the database location is not controlled by the extension
|
// pretend that the database location is not controlled by the extension
|
||||||
(databaseManager as any).ctx.storageUri = Uri.file("hucairz");
|
(databaseManager as any).ctx.storageUri = Uri.file("hucairz");
|
||||||
extensionContextStoragePath = "hucairz";
|
extensionContextStoragePath = "hucairz";
|
||||||
|
|
||||||
await databaseManager.removeDatabaseItem(
|
await databaseManager.removeDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(databaseManager.databaseItems).toEqual([]);
|
expect(databaseManager.databaseItems).toEqual([]);
|
||||||
expect(updateSpy).toBeCalledWith("databaseList", []);
|
expect(updateSpy).toBeCalledWith("databaseList", []);
|
||||||
@@ -301,22 +268,14 @@ describe("local databases", () => {
|
|||||||
// registration messages.
|
// registration messages.
|
||||||
const mockDbItem = createMockDB(dir);
|
const mockDbItem = createMockDB(dir);
|
||||||
|
|
||||||
await (databaseManager as any).addDatabaseItem(
|
await (databaseManager as any).addDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
// Should have registered this database
|
// Should have registered this database
|
||||||
expect(registerSpy).toBeCalledWith({}, {}, mockDbItem);
|
expect(registerSpy).toBeCalledWith(mockDbItem);
|
||||||
|
|
||||||
await databaseManager.removeDatabaseItem(
|
await databaseManager.removeDatabaseItem(mockDbItem);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Should have deregistered this database
|
// Should have deregistered this database
|
||||||
expect(deregisterSpy).toBeCalledWith({}, {}, mockDbItem);
|
expect(deregisterSpy).toBeCalledWith(mockDbItem);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -753,31 +712,19 @@ describe("local databases", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should resolve the database contents", async () => {
|
it("should resolve the database contents", async () => {
|
||||||
await databaseManager.openDatabase(
|
await databaseManager.openDatabase(mockDbItem.databaseUri);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem.databaseUri,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(resolveDatabaseContentsSpy).toBeCalledTimes(2);
|
expect(resolveDatabaseContentsSpy).toBeCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set the database as the currently selected one", async () => {
|
it("should set the database as the currently selected one", async () => {
|
||||||
await databaseManager.openDatabase(
|
await databaseManager.openDatabase(mockDbItem.databaseUri);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem.databaseUri,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(setCurrentDatabaseItemSpy).toBeCalledTimes(1);
|
expect(setCurrentDatabaseItemSpy).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add database source archive folder", async () => {
|
it("should add database source archive folder", async () => {
|
||||||
await databaseManager.openDatabase(
|
await databaseManager.openDatabase(mockDbItem.databaseUri);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem.databaseUri,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(addDatabaseSourceArchiveFolderSpy).toBeCalledTimes(1);
|
expect(addDatabaseSourceArchiveFolderSpy).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
@@ -792,8 +739,6 @@ describe("local databases", () => {
|
|||||||
const nameOverride = "CodeQL Tutorial Database";
|
const nameOverride = "CodeQL Tutorial Database";
|
||||||
|
|
||||||
await databaseManager.openDatabase(
|
await databaseManager.openDatabase(
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem.databaseUri,
|
mockDbItem.databaseUri,
|
||||||
makeSelected,
|
makeSelected,
|
||||||
nameOverride,
|
nameOverride,
|
||||||
@@ -808,11 +753,7 @@ describe("local databases", () => {
|
|||||||
it("should create a skeleton QL pack", async () => {
|
it("should create a skeleton QL pack", async () => {
|
||||||
jest.spyOn(Setting.prototype, "getValue").mockReturnValue(true);
|
jest.spyOn(Setting.prototype, "getValue").mockReturnValue(true);
|
||||||
|
|
||||||
await databaseManager.openDatabase(
|
await databaseManager.openDatabase(mockDbItem.databaseUri);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem.databaseUri,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(createSkeletonPacksSpy).toBeCalledTimes(1);
|
expect(createSkeletonPacksSpy).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
@@ -823,11 +764,7 @@ describe("local databases", () => {
|
|||||||
it("should not create a skeleton QL pack", async () => {
|
it("should not create a skeleton QL pack", async () => {
|
||||||
jest.spyOn(Setting.prototype, "getValue").mockReturnValue(false);
|
jest.spyOn(Setting.prototype, "getValue").mockReturnValue(false);
|
||||||
|
|
||||||
await databaseManager.openDatabase(
|
await databaseManager.openDatabase(mockDbItem.databaseUri);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem.databaseUri,
|
|
||||||
);
|
|
||||||
expect(createSkeletonPacksSpy).toBeCalledTimes(0);
|
expect(createSkeletonPacksSpy).toBeCalledTimes(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -836,11 +773,7 @@ describe("local databases", () => {
|
|||||||
it("should not create a skeleton QL pack", async () => {
|
it("should not create a skeleton QL pack", async () => {
|
||||||
jest.spyOn(Setting.prototype, "getValue").mockReturnValue(undefined);
|
jest.spyOn(Setting.prototype, "getValue").mockReturnValue(undefined);
|
||||||
|
|
||||||
await databaseManager.openDatabase(
|
await databaseManager.openDatabase(mockDbItem.databaseUri);
|
||||||
{} as ProgressCallback,
|
|
||||||
{} as CancellationToken,
|
|
||||||
mockDbItem.databaseUri,
|
|
||||||
);
|
|
||||||
expect(createSkeletonPacksSpy).toBeCalledTimes(0);
|
expect(createSkeletonPacksSpy).toBeCalledTimes(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -155,16 +155,10 @@ describe("test-runner", () => {
|
|||||||
).toBeGreaterThan(openDatabaseSpy.mock.invocationCallOrder[0]);
|
).toBeGreaterThan(openDatabaseSpy.mock.invocationCallOrder[0]);
|
||||||
|
|
||||||
expect(removeDatabaseItemSpy).toBeCalledTimes(1);
|
expect(removeDatabaseItemSpy).toBeCalledTimes(1);
|
||||||
expect(removeDatabaseItemSpy).toBeCalledWith(
|
expect(removeDatabaseItemSpy).toBeCalledWith(preTestDatabaseItem);
|
||||||
expect.anything(),
|
|
||||||
expect.anything(),
|
|
||||||
preTestDatabaseItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(openDatabaseSpy).toBeCalledTimes(1);
|
expect(openDatabaseSpy).toBeCalledTimes(1);
|
||||||
expect(openDatabaseSpy).toBeCalledWith(
|
expect(openDatabaseSpy).toBeCalledWith(
|
||||||
expect.anything(),
|
|
||||||
expect.anything(),
|
|
||||||
preTestDatabaseItem.databaseUri,
|
preTestDatabaseItem.databaseUri,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -232,8 +232,6 @@ describe("run-queries", () => {
|
|||||||
it("should register", async () => {
|
it("should register", async () => {
|
||||||
const qs = createMockQueryServerClient();
|
const qs = createMockQueryServerClient();
|
||||||
const runner = new LegacyQueryRunner(qs);
|
const runner = new LegacyQueryRunner(qs);
|
||||||
const mockProgress = "progress-monitor";
|
|
||||||
const mockCancel = "cancel-token";
|
|
||||||
const datasetUri = Uri.file("dataset-uri");
|
const datasetUri = Uri.file("dataset-uri");
|
||||||
|
|
||||||
const dbItem: DatabaseItem = {
|
const dbItem: DatabaseItem = {
|
||||||
@@ -242,33 +240,22 @@ describe("run-queries", () => {
|
|||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
await runner.registerDatabase(
|
await runner.registerDatabase(dbItem);
|
||||||
mockProgress as any,
|
|
||||||
mockCancel as any,
|
|
||||||
dbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(qs.sendRequest).toHaveBeenCalledTimes(1);
|
expect(qs.sendRequest).toHaveBeenCalledTimes(1);
|
||||||
expect(qs.sendRequest).toHaveBeenCalledWith(
|
expect(qs.sendRequest).toHaveBeenCalledWith(registerDatabases, {
|
||||||
registerDatabases,
|
databases: [
|
||||||
{
|
{
|
||||||
databases: [
|
dbDir: datasetUri.fsPath,
|
||||||
{
|
workingSet: "default",
|
||||||
dbDir: datasetUri.fsPath,
|
},
|
||||||
workingSet: "default",
|
],
|
||||||
},
|
});
|
||||||
],
|
|
||||||
},
|
|
||||||
mockCancel,
|
|
||||||
mockProgress,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should deregister", async () => {
|
it("should deregister", async () => {
|
||||||
const qs = createMockQueryServerClient();
|
const qs = createMockQueryServerClient();
|
||||||
const runner = new LegacyQueryRunner(qs);
|
const runner = new LegacyQueryRunner(qs);
|
||||||
const mockProgress = "progress-monitor";
|
|
||||||
const mockCancel = "cancel-token";
|
|
||||||
const datasetUri = Uri.file("dataset-uri");
|
const datasetUri = Uri.file("dataset-uri");
|
||||||
|
|
||||||
const dbItem: DatabaseItem = {
|
const dbItem: DatabaseItem = {
|
||||||
@@ -277,26 +264,17 @@ describe("run-queries", () => {
|
|||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
await runner.deregisterDatabase(
|
await runner.deregisterDatabase(dbItem);
|
||||||
mockProgress as any,
|
|
||||||
mockCancel as any,
|
|
||||||
dbItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(qs.sendRequest).toHaveBeenCalledTimes(1);
|
expect(qs.sendRequest).toHaveBeenCalledTimes(1);
|
||||||
expect(qs.sendRequest).toHaveBeenCalledWith(
|
expect(qs.sendRequest).toHaveBeenCalledWith(deregisterDatabases, {
|
||||||
deregisterDatabases,
|
databases: [
|
||||||
{
|
{
|
||||||
databases: [
|
dbDir: datasetUri.fsPath,
|
||||||
{
|
workingSet: "default",
|
||||||
dbDir: datasetUri.fsPath,
|
},
|
||||||
workingSet: "default",
|
],
|
||||||
},
|
});
|
||||||
],
|
|
||||||
},
|
|
||||||
mockCancel,
|
|
||||||
mockProgress,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user