Only construct DatabaseFetcher once in extension.ts
This commit is contained in:
@@ -42,7 +42,7 @@ import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogErrorMessage,
|
||||
} from "../common/logging";
|
||||
import { DatabaseFetcher } from "./database-fetcher";
|
||||
import type { DatabaseFetcher } from "./database-fetcher";
|
||||
import { asError, asyncFilter, getErrorMessage } from "../common/helpers-pure";
|
||||
import type { QueryRunner } from "../query-server";
|
||||
import type { App } from "../common/app";
|
||||
@@ -248,6 +248,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
public constructor(
|
||||
private app: App,
|
||||
private databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
languageContext: LanguageContextStore,
|
||||
private readonly queryServer: QueryRunner,
|
||||
private readonly storagePath: string,
|
||||
@@ -536,13 +537,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
private async handleChooseDatabaseInternet(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress) => {
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
await databaseFetcher.promptImportInternetDatabase(progress);
|
||||
await this.databaseFetcher.promptImportInternetDatabase(progress);
|
||||
},
|
||||
{
|
||||
title: "Adding database from URL",
|
||||
@@ -553,13 +548,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
private async handleChooseDatabaseGithub(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress) => {
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
await databaseFetcher.promptImportGithubDatabase(progress);
|
||||
await this.databaseFetcher.promptImportGithubDatabase(progress);
|
||||
},
|
||||
{
|
||||
title: "Adding database from GitHub",
|
||||
@@ -708,13 +697,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
try {
|
||||
// Assume user has selected an archive if the file has a .zip extension
|
||||
if (uri.path.endsWith(".zip")) {
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
await databaseFetcher.importArchiveDatabase(
|
||||
await this.databaseFetcher.importArchiveDatabase(
|
||||
uri.toString(true),
|
||||
progress,
|
||||
);
|
||||
@@ -957,13 +940,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
} else {
|
||||
// we are selecting a database archive. Must unzip into a workspace-controlled area
|
||||
// before importing.
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
return await databaseFetcher.importArchiveDatabase(
|
||||
return await this.databaseFetcher.importArchiveDatabase(
|
||||
uri.toString(true),
|
||||
progress,
|
||||
);
|
||||
|
||||
@@ -800,12 +800,20 @@ async function activateWithInstalledDistribution(
|
||||
// Let this run async.
|
||||
void dbm.loadPersistedState();
|
||||
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
app,
|
||||
dbm,
|
||||
getContextStoragePath(ctx),
|
||||
cliServer,
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(dbm);
|
||||
|
||||
void extLogger.log("Initializing database panel.");
|
||||
const databaseUI = new DatabaseUI(
|
||||
app,
|
||||
dbm,
|
||||
databaseFetcher,
|
||||
languageContext,
|
||||
qs,
|
||||
getContextStoragePath(ctx),
|
||||
@@ -882,7 +890,7 @@ async function activateWithInstalledDistribution(
|
||||
await GitHubDatabasesModule.initialize(
|
||||
app,
|
||||
dbm,
|
||||
new DatabaseFetcher(app, dbm, getContextStoragePath(ctx), cliServer),
|
||||
databaseFetcher,
|
||||
githubDatabaseConfigListener,
|
||||
);
|
||||
|
||||
@@ -953,6 +961,7 @@ async function activateWithInstalledDistribution(
|
||||
qs,
|
||||
qhm,
|
||||
dbm,
|
||||
databaseFetcher,
|
||||
cliServer,
|
||||
databaseUI,
|
||||
localQueryResultsView,
|
||||
@@ -977,6 +986,7 @@ async function activateWithInstalledDistribution(
|
||||
const modelEditorModule = await ModelEditorModule.initialize(
|
||||
app,
|
||||
dbm,
|
||||
databaseFetcher,
|
||||
variantAnalysisManager,
|
||||
cliServer,
|
||||
qs,
|
||||
|
||||
@@ -51,7 +51,7 @@ import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
|
||||
import { tryGetQueryLanguage } from "../common/query-language";
|
||||
import type { LanguageContextStore } from "../language-context-store";
|
||||
import type { ExtensionApp } from "../common/vscode/vscode-app";
|
||||
import { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
import type { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
|
||||
export enum QuickEvalType {
|
||||
None,
|
||||
@@ -67,6 +67,7 @@ export class LocalQueries extends DisposableObject {
|
||||
private readonly queryRunner: QueryRunner,
|
||||
private readonly queryHistoryManager: QueryHistoryManager,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly databaseUI: DatabaseUI,
|
||||
private readonly localQueryResultsView: ResultsView,
|
||||
@@ -323,21 +324,13 @@ export class LocalQueries extends DisposableObject {
|
||||
private async createSkeletonQuery(): Promise<void> {
|
||||
await withProgress(
|
||||
async (progress: ProgressCallback) => {
|
||||
const contextStoragePath =
|
||||
this.app.workspaceStoragePath || this.app.globalStoragePath;
|
||||
const language = this.languageContextStore.selectedLanguage;
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
contextStoragePath,
|
||||
this.cliServer,
|
||||
);
|
||||
const skeletonQueryWizard = new SkeletonQueryWizard(
|
||||
this.cliServer,
|
||||
progress,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
databaseFetcher,
|
||||
this.databaseFetcher,
|
||||
this.selectedQueryTreeViewItems,
|
||||
language,
|
||||
);
|
||||
|
||||
@@ -32,6 +32,7 @@ import { INITIAL_MODE } from "./shared/mode";
|
||||
import { isSupportedLanguage } from "./supported-languages";
|
||||
import { DefaultNotifier, checkConsistency } from "./consistency-check";
|
||||
import type { VariantAnalysisManager } from "../variant-analysis/variant-analysis-manager";
|
||||
import type { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
|
||||
export class ModelEditorModule extends DisposableObject {
|
||||
private readonly queryStorageDir: string;
|
||||
@@ -42,6 +43,7 @@ export class ModelEditorModule extends DisposableObject {
|
||||
private constructor(
|
||||
private readonly app: App,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly variantAnalysisManager: VariantAnalysisManager,
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly queryRunner: QueryRunner,
|
||||
@@ -65,6 +67,7 @@ export class ModelEditorModule extends DisposableObject {
|
||||
public static async initialize(
|
||||
app: App,
|
||||
databaseManager: DatabaseManager,
|
||||
databaseFetcher: DatabaseFetcher,
|
||||
variantAnalysisManager: VariantAnalysisManager,
|
||||
cliServer: CodeQLCliServer,
|
||||
queryRunner: QueryRunner,
|
||||
@@ -73,6 +76,7 @@ export class ModelEditorModule extends DisposableObject {
|
||||
const modelEditorModule = new ModelEditorModule(
|
||||
app,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
variantAnalysisManager,
|
||||
cliServer,
|
||||
queryRunner,
|
||||
@@ -236,6 +240,7 @@ export class ModelEditorModule extends DisposableObject {
|
||||
this.modelingEvents,
|
||||
this.modelConfig,
|
||||
this.databaseManager,
|
||||
this.databaseFetcher,
|
||||
this.variantAnalysisManager,
|
||||
this.cliServer,
|
||||
this.queryRunner,
|
||||
|
||||
@@ -29,7 +29,7 @@ import type {
|
||||
} from "../databases/local-databases";
|
||||
import type { CodeQLCliServer } from "../codeql-cli/cli";
|
||||
import { asError, assertNever, getErrorMessage } from "../common/helpers-pure";
|
||||
import { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
import type { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
import type { App } from "../common/app";
|
||||
import { redactableError } from "../common/errors";
|
||||
import {
|
||||
@@ -86,6 +86,7 @@ export class ModelEditorView extends AbstractWebview<
|
||||
private readonly modelingEvents: ModelingEvents,
|
||||
private readonly modelConfig: ModelConfigListener,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly variantAnalysisManager: VariantAnalysisManager,
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly queryRunner: QueryRunner,
|
||||
@@ -848,6 +849,7 @@ export class ModelEditorView extends AbstractWebview<
|
||||
this.modelingEvents,
|
||||
this.modelConfig,
|
||||
this.databaseManager,
|
||||
this.databaseFetcher,
|
||||
this.variantAnalysisManager,
|
||||
this.cliServer,
|
||||
this.queryRunner,
|
||||
@@ -916,13 +918,7 @@ export class ModelEditorView extends AbstractWebview<
|
||||
// the user to import the library database. We need to have the database
|
||||
// imported to the query server, so we need to register it to our workspace.
|
||||
const makeSelected = false;
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
|
||||
this.cliServer,
|
||||
);
|
||||
const addedDatabase = await databaseFetcher.promptImportGithubDatabase(
|
||||
const addedDatabase = await this.databaseFetcher.promptImportGithubDatabase(
|
||||
progress,
|
||||
this.databaseItem.language,
|
||||
undefined,
|
||||
|
||||
@@ -4,7 +4,6 @@ import { createMockApp } from "../../../../__mocks__/appMock";
|
||||
import type { App } from "../../../../../src/common/app";
|
||||
import type { DatabaseManager } from "../../../../../src/databases/local-databases";
|
||||
import { mockEmptyDatabaseManager } from "../../query-testing/test-runner-helpers";
|
||||
import type { CodeQLCliServer } from "../../../../../src/codeql-cli/cli";
|
||||
import { mockDatabaseItem, mockedObject } from "../../../utils/mocking.helpers";
|
||||
import type { GitHubDatabaseConfig } from "../../../../../src/config";
|
||||
import { GitHubDatabasesModule } from "../../../../../src/databases/github-databases";
|
||||
@@ -16,15 +15,13 @@ import * as githubDatabasesApi from "../../../../../src/databases/github-databas
|
||||
import * as githubDatabasesDownload from "../../../../../src/databases/github-databases/download";
|
||||
import * as githubDatabasesUpdates from "../../../../../src/databases/github-databases/updates";
|
||||
import type { DatabaseUpdate } from "../../../../../src/databases/github-databases/updates";
|
||||
import { DatabaseFetcher } from "../../../../../src/databases/database-fetcher";
|
||||
import type { DatabaseFetcher } from "../../../../../src/databases/database-fetcher";
|
||||
|
||||
describe("GitHubDatabasesModule", () => {
|
||||
describe("promptGitHubRepositoryDownload", () => {
|
||||
let app: App;
|
||||
let databaseManager: DatabaseManager;
|
||||
let databaseStoragePath: string;
|
||||
let cliServer: CodeQLCliServer;
|
||||
let databaseFetcher: DatabaseFetcher;
|
||||
const databaseFetcher = mockedObject<DatabaseFetcher>({});
|
||||
let config: GitHubDatabaseConfig;
|
||||
let gitHubDatabasesModule: GitHubDatabasesModule;
|
||||
|
||||
@@ -66,14 +63,6 @@ describe("GitHubDatabasesModule", () => {
|
||||
beforeEach(() => {
|
||||
app = createMockApp();
|
||||
databaseManager = mockEmptyDatabaseManager();
|
||||
databaseStoragePath = "/a/b/some-path";
|
||||
cliServer = mockedObject<CodeQLCliServer>({});
|
||||
databaseFetcher = new DatabaseFetcher(
|
||||
app,
|
||||
databaseManager,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
);
|
||||
config = mockedObject<GitHubDatabaseConfig>({
|
||||
download: "ask",
|
||||
update: "ask",
|
||||
|
||||
@@ -20,6 +20,7 @@ import { testDisposeHandler } from "../../test-dispose-handler";
|
||||
import { createMockApp } from "../../../__mocks__/appMock";
|
||||
import { QueryLanguage } from "../../../../src/common/query-language";
|
||||
import { mockedQuickPickItem, mockedObject } from "../../utils/mocking.helpers";
|
||||
import type { DatabaseFetcher } from "../../../../src/databases/database-fetcher";
|
||||
|
||||
describe("local-databases-ui", () => {
|
||||
const storageDir = dirSync({ unsafeCleanup: true }).name;
|
||||
@@ -104,6 +105,7 @@ describe("local-databases-ui", () => {
|
||||
},
|
||||
setCurrentDatabaseItem: () => {},
|
||||
} as any,
|
||||
mockedObject<DatabaseFetcher>({}),
|
||||
{
|
||||
onLanguageContextChanged: () => {
|
||||
/**/
|
||||
@@ -142,6 +144,7 @@ describe("local-databases-ui", () => {
|
||||
setCurrentDatabaseItem: () => {},
|
||||
currentDatabaseItem: { databaseUri: Uri.file(db1) },
|
||||
} as any,
|
||||
mockedObject<DatabaseFetcher>({}),
|
||||
{
|
||||
onLanguageContextChanged: () => {
|
||||
/**/
|
||||
@@ -178,6 +181,7 @@ describe("local-databases-ui", () => {
|
||||
const databaseUI = new DatabaseUI(
|
||||
app,
|
||||
databaseManager,
|
||||
mockedObject<DatabaseFetcher>({}),
|
||||
{
|
||||
onLanguageContextChanged: () => {
|
||||
/**/
|
||||
|
||||
@@ -13,6 +13,7 @@ import type { ModelConfigListener } from "../../../../src/config";
|
||||
import { createMockModelingEvents } from "../../../__mocks__/model-editor/modelingEventsMock";
|
||||
import { QueryLanguage } from "../../../../src/common/query-language";
|
||||
import type { VariantAnalysisManager } from "../../../../src/variant-analysis/variant-analysis-manager";
|
||||
import type { DatabaseFetcher } from "../../../../src/databases/database-fetcher";
|
||||
|
||||
describe("ModelEditorView", () => {
|
||||
const app = createMockApp({});
|
||||
@@ -22,6 +23,7 @@ describe("ModelEditorView", () => {
|
||||
onDidChangeConfiguration: jest.fn(),
|
||||
});
|
||||
const databaseManager = mockEmptyDatabaseManager();
|
||||
const databaseFetcher = mockedObject<DatabaseFetcher>({});
|
||||
const variantAnalysisManager = mockedObject<VariantAnalysisManager>({});
|
||||
const cliServer = mockedObject<CodeQLCliServer>({});
|
||||
const queryRunner = mockedObject<QueryRunner>({});
|
||||
@@ -50,6 +52,7 @@ describe("ModelEditorView", () => {
|
||||
modelingEvents,
|
||||
modelConfig,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
variantAnalysisManager,
|
||||
cliServer,
|
||||
queryRunner,
|
||||
|
||||
Reference in New Issue
Block a user