Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions extensions/ql-vscode/src/databases/db-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import { DbPanel } from "./ui/db-panel";
import { DbSelectionDecorationProvider } from "./ui/db-selection-decoration-provider";

export class DbModule extends DisposableObject {
public readonly dbManager: DbManager;
private readonly dbConfigStore: DbConfigStore;

constructor(app: App) {
super();

this.dbConfigStore = new DbConfigStore(app);
this.dbManager = new DbManager(app, this.dbConfigStore);
}

public async initialize(app: App): Promise<void> {
if (
app.mode !== AppMode.Development ||
Expand All @@ -23,15 +33,13 @@ export class DbModule extends DisposableObject {

void extLogger.log("Initializing database module");

const dbConfigStore = new DbConfigStore(app);
await dbConfigStore.initialize();
await this.dbConfigStore.initialize();

const dbManager = new DbManager(app, dbConfigStore);
const dbPanel = new DbPanel(dbManager);
const dbPanel = new DbPanel(this.dbManager);
await dbPanel.initialize();

this.push(dbPanel);
this.push(dbConfigStore);
this.push(this.dbConfigStore);

const dbSelectionDecorationProvider = new DbSelectionDecorationProvider();

Expand All @@ -40,7 +48,7 @@ export class DbModule extends DisposableObject {
}

export async function initializeDbModule(app: App): Promise<DbModule> {
const dbModule = new DbModule();
const dbModule = new DbModule(app);
await dbModule.initialize(app);
return dbModule;
}
10 changes: 6 additions & 4 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ async function activateWithInstalledDistribution(
ctx.subscriptions.push(localQueryResultsView);

void extLogger.log("Initializing variant analysis manager.");

const app = new ExtensionApp(ctx);
const dbModule = await initializeDbModule(app);
ctx.subscriptions.push(dbModule);

const variantAnalysisStorageDir = join(
ctx.globalStorageUri.fsPath,
"variant-analyses",
Expand All @@ -636,6 +641,7 @@ async function activateWithInstalledDistribution(
cliServer,
variantAnalysisStorageDir,
variantAnalysisResultsManager,
dbModule.dbManager,
);
ctx.subscriptions.push(variantAnalysisManager);
ctx.subscriptions.push(variantAnalysisResultsManager);
Expand Down Expand Up @@ -1580,10 +1586,6 @@ async function activateWithInstalledDistribution(
void extLogger.log("Reading query history");
await qhm.readQueryHistory();

const app = new ExtensionApp(ctx);
const dbModule = await initializeDbModule(app);
ctx.subscriptions.push(dbModule);

void extLogger.log("Successfully finished extension initialization.");

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { extLogger } from "../common";
import {
getRemoteRepositoryLists,
getRemoteRepositoryListsPath,
isNewQueryRunExperienceEnabled,
} from "../config";
import { OWNER_REGEX, REPO_REGEX } from "../pure/helpers-pure";
import { UserCancellationException } from "../commandRunner";
import { DbManager } from "../databases/db-manager";
import { DbItemKind } from "../databases/db-item";

export interface RepositorySelection {
repositories?: string[];
Expand All @@ -30,7 +33,33 @@ interface RepoList {
* Gets the repositories or repository lists to run the query against.
* @returns The user selection.
*/
export async function getRepositorySelection(): Promise<RepositorySelection> {
export async function getRepositorySelection(
dbManager?: DbManager,
): Promise<RepositorySelection> {
if (isNewQueryRunExperienceEnabled()) {
const selectedDbItem = dbManager?.getSelectedDbItem();
if (selectedDbItem) {
switch (selectedDbItem.kind) {
case DbItemKind.LocalDatabase || DbItemKind.LocalList:
throw new Error("Local databases and lists are not supported yet.");
case DbItemKind.RemoteSystemDefinedList:
return { repositoryLists: [selectedDbItem.listName] };
case DbItemKind.RemoteUserDefinedList:
return {
repositories: selectedDbItem.repos.map((repo) => repo.repoFullName),
};
case DbItemKind.RemoteOwner:
return { owners: [selectedDbItem.ownerName] };
case DbItemKind.RemoteRepo:
return { repositories: [selectedDbItem.repoFullName] };
}
} else {
throw new Error(
"Please select a remote database to run the query against.",
);
}
}

const quickPickItems = [
createCustomRepoQuickPickItem(),
createAllReposOfOwnerQuickPickItem(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
RepositorySelection,
} from "./repository-selection";
import { Repository } from "./shared/repository";
import { DbManager } from "../databases/db-manager";

export interface QlPack {
name: string;
Expand Down Expand Up @@ -213,6 +214,7 @@ export async function prepareRemoteQueryRun(
uri: Uri | undefined,
progress: ProgressCallback,
token: CancellationToken,
dbManager?: DbManager, // the dbManager is only needed when the newQueryRunExperience is enabled
): Promise<PreparedRemoteQuery> {
if (!(await cliServer.cliConstraints.supportsRemoteQueries())) {
throw new Error(
Expand All @@ -232,7 +234,7 @@ export async function prepareRemoteQueryRun(
message: "Determining query target language",
});

const repoSelection = await getRepositorySelection();
const repoSelection = await getRepositorySelection(dbManager);
if (!isValidSelection(repoSelection)) {
throw new UserCancellationException("No repositories to query.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
RepositoriesFilterSortStateWithIds,
} from "../pure/variant-analysis-filter-sort";
import { URLSearchParams } from "url";
import { DbManager } from "../databases/db-manager";

export class VariantAnalysisManager
extends DisposableObject
Expand Down Expand Up @@ -100,6 +101,7 @@ export class VariantAnalysisManager
private readonly cliServer: CodeQLCliServer,
private readonly storagePath: string,
private readonly variantAnalysisResultsManager: VariantAnalysisResultsManager,
private readonly dbManager: DbManager,
) {
super();
this.variantAnalysisMonitor = this.push(
Expand Down Expand Up @@ -140,6 +142,7 @@ export class VariantAnalysisManager
uri,
progress,
token,
this.dbManager,
);

const queryName = getQueryName(queryMetadata, queryFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
defaultFilterSortState,
SortKey,
} from "../../../pure/variant-analysis-filter-sort";
import { DbManager } from "../../../databases/db-manager";

// up to 3 minutes per test
jest.setTimeout(3 * 60 * 1000);
Expand All @@ -69,6 +70,7 @@ describe("Variant Analysis Manager", () => {
let cancellationTokenSource: CancellationTokenSource;
let variantAnalysisManager: VariantAnalysisManager;
let variantAnalysisResultsManager: VariantAnalysisResultsManager;
let dbManager: DbManager;
let variantAnalysis: VariantAnalysis;
let scannedRepos: VariantAnalysisScannedRepository[];

Expand Down Expand Up @@ -107,6 +109,7 @@ describe("Variant Analysis Manager", () => {
cli,
storagePath,
variantAnalysisResultsManager,
dbManager,
);
});

Expand Down
Loading