Merge remote-tracking branch 'origin/main' into koesie10/typed-local-database-ui-commands
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { CommandManager } from "../packages/commands";
|
||||
import type { Uri } from "vscode";
|
||||
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
|
||||
import type { DatabaseItem } from "../local-databases";
|
||||
import type { QueryHistoryInfo } from "../query-history/query-history-info";
|
||||
|
||||
@@ -10,6 +11,12 @@ export type SelectionCommandFunction<Item> = (
|
||||
multiSelect: Item[],
|
||||
) => Promise<void>;
|
||||
|
||||
// A command function matching the signature that VS Code calls when
|
||||
// a command on a selection is invoked when canSelectMany is false.
|
||||
export type SingleSelectionCommandFunction<Item> = (
|
||||
singleItem: Item,
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* Contains type definitions for all commands used by the extension.
|
||||
*
|
||||
@@ -88,9 +95,23 @@ export type VariantAnalysisCommands = {
|
||||
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
|
||||
};
|
||||
|
||||
export type DatabasePanelCommands = {
|
||||
"codeQLVariantAnalysisRepositories.openConfigFile": () => Promise<void>;
|
||||
"codeQLVariantAnalysisRepositories.addNewDatabase": () => Promise<void>;
|
||||
"codeQLVariantAnalysisRepositories.addNewList": () => Promise<void>;
|
||||
"codeQLVariantAnalysisRepositories.setupControllerRepository": () => Promise<void>;
|
||||
|
||||
"codeQLVariantAnalysisRepositories.setSelectedItem": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||
"codeQLVariantAnalysisRepositories.renameItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||
"codeQLVariantAnalysisRepositories.removeItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||
};
|
||||
|
||||
export type AllCommands = BaseCommands &
|
||||
QueryHistoryCommands &
|
||||
LocalDatabasesCommands &
|
||||
VariantAnalysisCommands;
|
||||
VariantAnalysisCommands &
|
||||
DatabasePanelCommands;
|
||||
|
||||
export type AppCommandManager = CommandManager<AllCommands>;
|
||||
|
||||
@@ -6,10 +6,12 @@ import { DbConfigStore } from "./config/db-config-store";
|
||||
import { DbManager } from "./db-manager";
|
||||
import { DbPanel } from "./ui/db-panel";
|
||||
import { DbSelectionDecorationProvider } from "./ui/db-selection-decoration-provider";
|
||||
import { DatabasePanelCommands } from "../common/commands";
|
||||
|
||||
export class DbModule extends DisposableObject {
|
||||
public readonly dbManager: DbManager;
|
||||
private readonly dbConfigStore: DbConfigStore;
|
||||
private dbPanel: DbPanel | undefined;
|
||||
|
||||
private constructor(app: App) {
|
||||
super();
|
||||
@@ -26,15 +28,24 @@ export class DbModule extends DisposableObject {
|
||||
return dbModule;
|
||||
}
|
||||
|
||||
public getCommands(): DatabasePanelCommands {
|
||||
if (!this.dbPanel) {
|
||||
throw new Error("Database panel not initialized");
|
||||
}
|
||||
|
||||
return {
|
||||
...this.dbPanel.getCommands(),
|
||||
};
|
||||
}
|
||||
|
||||
private async initialize(app: App): Promise<void> {
|
||||
void extLogger.log("Initializing database module");
|
||||
|
||||
await this.dbConfigStore.initialize();
|
||||
|
||||
const dbPanel = new DbPanel(this.dbManager, app.credentials);
|
||||
await dbPanel.initialize();
|
||||
this.dbPanel = new DbPanel(this.dbManager, app.credentials);
|
||||
|
||||
this.push(dbPanel);
|
||||
this.push(this.dbPanel);
|
||||
this.push(this.dbConfigStore);
|
||||
|
||||
const dbSelectionDecorationProvider = new DbSelectionDecorationProvider();
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
window,
|
||||
workspace,
|
||||
} from "vscode";
|
||||
import { commandRunner, UserCancellationException } from "../../commandRunner";
|
||||
import { UserCancellationException } from "../../commandRunner";
|
||||
import {
|
||||
getNwoFromGitHubUrl,
|
||||
isValidGitHubNwo,
|
||||
@@ -32,6 +32,7 @@ import { getGitHubUrl } from "./db-tree-view-item-action";
|
||||
import { getControllerRepo } from "../../variant-analysis/run-remote-query";
|
||||
import { getErrorMessage } from "../../pure/helpers-pure";
|
||||
import { Credentials } from "../../common/authentication";
|
||||
import { DatabasePanelCommands } from "../../common/commands";
|
||||
|
||||
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
|
||||
kind: string;
|
||||
@@ -72,58 +73,28 @@ export class DbPanel extends DisposableObject {
|
||||
this.push(this.treeView);
|
||||
}
|
||||
|
||||
public async initialize(): Promise<void> {
|
||||
this.push(
|
||||
commandRunner("codeQLVariantAnalysisRepositories.openConfigFile", () =>
|
||||
this.openConfigFile(),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner("codeQLVariantAnalysisRepositories.addNewDatabase", () =>
|
||||
this.addNewRemoteDatabase(),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner("codeQLVariantAnalysisRepositories.addNewList", () =>
|
||||
this.addNewList(),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLVariantAnalysisRepositories.setSelectedItem",
|
||||
(treeViewItem: DbTreeViewItem) => this.setSelectedItem(treeViewItem),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu",
|
||||
(treeViewItem: DbTreeViewItem) => this.setSelectedItem(treeViewItem),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu",
|
||||
(treeViewItem: DbTreeViewItem) => this.openOnGitHub(treeViewItem),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLVariantAnalysisRepositories.renameItemContextMenu",
|
||||
(treeViewItem: DbTreeViewItem) => this.renameItem(treeViewItem),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLVariantAnalysisRepositories.removeItemContextMenu",
|
||||
(treeViewItem: DbTreeViewItem) => this.removeItem(treeViewItem),
|
||||
),
|
||||
);
|
||||
this.push(
|
||||
commandRunner(
|
||||
"codeQLVariantAnalysisRepositories.setupControllerRepository",
|
||||
() => this.setupControllerRepository(),
|
||||
),
|
||||
);
|
||||
public getCommands(): DatabasePanelCommands {
|
||||
return {
|
||||
"codeQLVariantAnalysisRepositories.openConfigFile":
|
||||
this.openConfigFile.bind(this),
|
||||
"codeQLVariantAnalysisRepositories.addNewDatabase":
|
||||
this.addNewRemoteDatabase.bind(this),
|
||||
"codeQLVariantAnalysisRepositories.addNewList":
|
||||
this.addNewList.bind(this),
|
||||
"codeQLVariantAnalysisRepositories.setupControllerRepository":
|
||||
this.setupControllerRepository.bind(this),
|
||||
|
||||
"codeQLVariantAnalysisRepositories.setSelectedItem":
|
||||
this.setSelectedItem.bind(this),
|
||||
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu":
|
||||
this.setSelectedItem.bind(this),
|
||||
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu":
|
||||
this.openOnGitHub.bind(this),
|
||||
"codeQLVariantAnalysisRepositories.renameItemContextMenu":
|
||||
this.renameItem.bind(this),
|
||||
"codeQLVariantAnalysisRepositories.removeItemContextMenu":
|
||||
this.removeItem.bind(this),
|
||||
};
|
||||
}
|
||||
|
||||
private async openConfigFile(): Promise<void> {
|
||||
|
||||
@@ -108,10 +108,7 @@ import {
|
||||
handleInstallPackDependencies,
|
||||
} from "./packaging";
|
||||
import { HistoryItemLabelProvider } from "./query-history/history-item-label-provider";
|
||||
import {
|
||||
exportSelectedVariantAnalysisResults,
|
||||
exportVariantAnalysisResults,
|
||||
} from "./variant-analysis/export-results";
|
||||
import { exportSelectedVariantAnalysisResults } from "./variant-analysis/export-results";
|
||||
import { EvalLogViewer } from "./eval-log-viewer";
|
||||
import { SummaryLanguageSupport } from "./log-insights/summary-language-support";
|
||||
import { JoinOrderScannerProvider } from "./log-insights/join-order";
|
||||
@@ -1095,6 +1092,7 @@ async function activateWithInstalledDistribution(
|
||||
...qhm.getCommands(),
|
||||
...variantAnalysisManager.getCommands(),
|
||||
...databaseUI.getCommands(),
|
||||
...dbModule.getCommands(),
|
||||
};
|
||||
|
||||
for (const [commandName, command] of Object.entries(allCommands)) {
|
||||
@@ -1145,46 +1143,12 @@ async function activateWithInstalledDistribution(
|
||||
),
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
async (variantAnalysisId: number) => {
|
||||
await variantAnalysisManager.cancelVariantAnalysis(variantAnalysisId);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(
|
||||
commandRunner("codeQL.exportSelectedVariantAnalysisResults", async () => {
|
||||
await exportSelectedVariantAnalysisResults(qhm);
|
||||
await exportSelectedVariantAnalysisResults(variantAnalysisManager, qhm);
|
||||
}),
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(
|
||||
commandRunnerWithProgress(
|
||||
"codeQL.exportVariantAnalysisResults",
|
||||
async (
|
||||
progress: ProgressCallback,
|
||||
token: CancellationToken,
|
||||
variantAnalysisId: number,
|
||||
filterSort?: RepositoriesFilterSortStateWithIds,
|
||||
) => {
|
||||
await exportVariantAnalysisResults(
|
||||
variantAnalysisManager,
|
||||
variantAnalysisId,
|
||||
filterSort,
|
||||
app.credentials,
|
||||
progress,
|
||||
token,
|
||||
);
|
||||
},
|
||||
{
|
||||
title: "Exporting variant analysis results",
|
||||
cancellable: true,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.loadVariantAnalysisRepoResults",
|
||||
@@ -1207,15 +1171,6 @@ async function activateWithInstalledDistribution(
|
||||
),
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.openVariantAnalysisQueryText",
|
||||
async (variantAnalysisId: number) => {
|
||||
await variantAnalysisManager.openQueryText(variantAnalysisId);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(
|
||||
commandRunner("codeQL.openReferencedFile", async (selectedQuery: Uri) => {
|
||||
await openReferencedFile(qs, cliServer, selectedQuery);
|
||||
|
||||
@@ -894,8 +894,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
if (item.t === "local") {
|
||||
item.cancel();
|
||||
} else if (item.t === "variant-analysis") {
|
||||
await commands.executeCommand(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
await this.variantAnalysisManager.cancelVariantAnalysis(
|
||||
item.variantAnalysis.id,
|
||||
);
|
||||
} else {
|
||||
@@ -921,8 +920,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
}
|
||||
|
||||
if (finalSingleItem.t === "variant-analysis") {
|
||||
await commands.executeCommand(
|
||||
"codeQL.openVariantAnalysisQueryText",
|
||||
await this.variantAnalysisManager.openQueryText(
|
||||
finalSingleItem.variantAnalysis.id,
|
||||
);
|
||||
return;
|
||||
@@ -1124,8 +1122,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
return;
|
||||
}
|
||||
|
||||
await commands.executeCommand(
|
||||
"codeQL.exportVariantAnalysisResults",
|
||||
await this.variantAnalysisManager.exportResults(
|
||||
finalSingleItem.variantAnalysis.id,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,11 @@ import {
|
||||
window,
|
||||
workspace,
|
||||
} from "vscode";
|
||||
import { ProgressCallback, UserCancellationException } from "../commandRunner";
|
||||
import {
|
||||
ProgressCallback,
|
||||
UserCancellationException,
|
||||
withProgress,
|
||||
} from "../commandRunner";
|
||||
import { showInformationMessageWithAction } from "../helpers";
|
||||
import { extLogger } from "../common";
|
||||
import { QueryHistoryManager } from "../query-history/query-history-manager";
|
||||
@@ -37,6 +41,7 @@ import { Credentials } from "../common/authentication";
|
||||
* Exports the results of the currently-selected variant analysis.
|
||||
*/
|
||||
export async function exportSelectedVariantAnalysisResults(
|
||||
variantAnalysisManager: VariantAnalysisManager,
|
||||
queryHistoryManager: QueryHistoryManager,
|
||||
): Promise<void> {
|
||||
const queryHistoryItem = queryHistoryManager.getCurrentQueryHistoryItem();
|
||||
@@ -46,8 +51,7 @@ export async function exportSelectedVariantAnalysisResults(
|
||||
);
|
||||
}
|
||||
|
||||
return commands.executeCommand(
|
||||
"codeQL.exportVariantAnalysisResults",
|
||||
await variantAnalysisManager.exportResults(
|
||||
queryHistoryItem.variantAnalysis.id,
|
||||
);
|
||||
}
|
||||
@@ -63,108 +67,117 @@ export async function exportVariantAnalysisResults(
|
||||
variantAnalysisId: number,
|
||||
filterSort: RepositoriesFilterSortStateWithIds | undefined,
|
||||
credentials: Credentials,
|
||||
progress: ProgressCallback,
|
||||
token: CancellationToken,
|
||||
): Promise<void> {
|
||||
const variantAnalysis = await variantAnalysisManager.getVariantAnalysis(
|
||||
variantAnalysisId,
|
||||
);
|
||||
if (!variantAnalysis) {
|
||||
void extLogger.log(
|
||||
`Could not find variant analysis with id ${variantAnalysisId}`,
|
||||
);
|
||||
throw new Error(
|
||||
"There was an error when trying to retrieve variant analysis information",
|
||||
);
|
||||
}
|
||||
await withProgress(
|
||||
async (progress: ProgressCallback, token: CancellationToken) => {
|
||||
const variantAnalysis = await variantAnalysisManager.getVariantAnalysis(
|
||||
variantAnalysisId,
|
||||
);
|
||||
if (!variantAnalysis) {
|
||||
void extLogger.log(
|
||||
`Could not find variant analysis with id ${variantAnalysisId}`,
|
||||
);
|
||||
throw new Error(
|
||||
"There was an error when trying to retrieve variant analysis information",
|
||||
);
|
||||
}
|
||||
|
||||
if (token.isCancellationRequested) {
|
||||
throw new UserCancellationException("Cancelled");
|
||||
}
|
||||
if (token.isCancellationRequested) {
|
||||
throw new UserCancellationException("Cancelled");
|
||||
}
|
||||
|
||||
const repoStates = await variantAnalysisManager.getRepoStates(
|
||||
variantAnalysisId,
|
||||
);
|
||||
|
||||
void extLogger.log(
|
||||
`Exporting variant analysis results for variant analysis with id ${variantAnalysis.id}`,
|
||||
);
|
||||
|
||||
progress({
|
||||
maxStep: MAX_VARIANT_ANALYSIS_EXPORT_PROGRESS_STEPS,
|
||||
step: 0,
|
||||
message: "Determining export format",
|
||||
});
|
||||
|
||||
const exportFormat = await determineExportFormat();
|
||||
if (!exportFormat) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (token.isCancellationRequested) {
|
||||
throw new UserCancellationException("Cancelled");
|
||||
}
|
||||
|
||||
const repositories = filterAndSortRepositoriesWithResults(
|
||||
variantAnalysis.scannedRepos,
|
||||
filterSort,
|
||||
)?.filter(
|
||||
(repo) =>
|
||||
repo.resultCount &&
|
||||
repoStates.find((r) => r.repositoryId === repo.repository.id)
|
||||
?.downloadStatus ===
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
);
|
||||
|
||||
async function* getAnalysesResults(): AsyncGenerator<
|
||||
[VariantAnalysisScannedRepository, VariantAnalysisScannedRepositoryResult]
|
||||
> {
|
||||
if (!variantAnalysis) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!repositories) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const repo of repositories) {
|
||||
const result = await variantAnalysisManager.loadResults(
|
||||
variantAnalysis.id,
|
||||
repo.repository.fullName,
|
||||
{
|
||||
skipCacheStore: true,
|
||||
},
|
||||
const repoStates = await variantAnalysisManager.getRepoStates(
|
||||
variantAnalysisId,
|
||||
);
|
||||
|
||||
yield [repo, result];
|
||||
}
|
||||
}
|
||||
void extLogger.log(
|
||||
`Exporting variant analysis results for variant analysis with id ${variantAnalysis.id}`,
|
||||
);
|
||||
|
||||
const exportDirectory =
|
||||
variantAnalysisManager.getVariantAnalysisStorageLocation(
|
||||
variantAnalysis.id,
|
||||
);
|
||||
progress({
|
||||
maxStep: MAX_VARIANT_ANALYSIS_EXPORT_PROGRESS_STEPS,
|
||||
step: 0,
|
||||
message: "Determining export format",
|
||||
});
|
||||
|
||||
// The date will be formatted like the following: 20221115T123456Z. The time is in UTC.
|
||||
const formattedDate = new Date()
|
||||
.toISOString()
|
||||
.replace(/[-:]/g, "")
|
||||
.replace(/\.\d+Z$/, "Z");
|
||||
const exportedResultsDirectory = join(
|
||||
exportDirectory,
|
||||
"exported-results",
|
||||
`results_${formattedDate}`,
|
||||
);
|
||||
const exportFormat = await determineExportFormat();
|
||||
if (!exportFormat) {
|
||||
return;
|
||||
}
|
||||
|
||||
await exportVariantAnalysisAnalysisResults(
|
||||
exportedResultsDirectory,
|
||||
variantAnalysis,
|
||||
getAnalysesResults(),
|
||||
repositories?.length ?? 0,
|
||||
exportFormat,
|
||||
credentials,
|
||||
progress,
|
||||
token,
|
||||
if (token.isCancellationRequested) {
|
||||
throw new UserCancellationException("Cancelled");
|
||||
}
|
||||
|
||||
const repositories = filterAndSortRepositoriesWithResults(
|
||||
variantAnalysis.scannedRepos,
|
||||
filterSort,
|
||||
)?.filter(
|
||||
(repo) =>
|
||||
repo.resultCount &&
|
||||
repoStates.find((r) => r.repositoryId === repo.repository.id)
|
||||
?.downloadStatus ===
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
);
|
||||
|
||||
async function* getAnalysesResults(): AsyncGenerator<
|
||||
[
|
||||
VariantAnalysisScannedRepository,
|
||||
VariantAnalysisScannedRepositoryResult,
|
||||
]
|
||||
> {
|
||||
if (!variantAnalysis) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!repositories) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const repo of repositories) {
|
||||
const result = await variantAnalysisManager.loadResults(
|
||||
variantAnalysis.id,
|
||||
repo.repository.fullName,
|
||||
{
|
||||
skipCacheStore: true,
|
||||
},
|
||||
);
|
||||
|
||||
yield [repo, result];
|
||||
}
|
||||
}
|
||||
|
||||
const exportDirectory =
|
||||
variantAnalysisManager.getVariantAnalysisStorageLocation(
|
||||
variantAnalysis.id,
|
||||
);
|
||||
|
||||
// The date will be formatted like the following: 20221115T123456Z. The time is in UTC.
|
||||
const formattedDate = new Date()
|
||||
.toISOString()
|
||||
.replace(/[-:]/g, "")
|
||||
.replace(/\.\d+Z$/, "Z");
|
||||
const exportedResultsDirectory = join(
|
||||
exportDirectory,
|
||||
"exported-results",
|
||||
`results_${formattedDate}`,
|
||||
);
|
||||
|
||||
await exportVariantAnalysisAnalysisResults(
|
||||
exportedResultsDirectory,
|
||||
variantAnalysis,
|
||||
getAnalysesResults(),
|
||||
repositories?.length ?? 0,
|
||||
exportFormat,
|
||||
credentials,
|
||||
progress,
|
||||
token,
|
||||
);
|
||||
},
|
||||
{
|
||||
title: "Exporting variant analysis results",
|
||||
cancellable: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ import { DbManager } from "../databases/db-manager";
|
||||
import { App } from "../common/app";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { AppCommandManager, VariantAnalysisCommands } from "../common/commands";
|
||||
import { exportVariantAnalysisResults } from "./export-results";
|
||||
|
||||
export class VariantAnalysisManager
|
||||
extends DisposableObject
|
||||
@@ -690,6 +691,18 @@ export class VariantAnalysisManager
|
||||
await env.clipboard.writeText(text.join(EOL));
|
||||
}
|
||||
|
||||
public async exportResults(
|
||||
variantAnalysisId: number,
|
||||
filterSort?: RepositoriesFilterSortStateWithIds,
|
||||
) {
|
||||
await exportVariantAnalysisResults(
|
||||
this,
|
||||
variantAnalysisId,
|
||||
filterSort,
|
||||
this.app.credentials,
|
||||
);
|
||||
}
|
||||
|
||||
private getRepoStatesStoragePath(variantAnalysisId: number): string {
|
||||
return join(
|
||||
this.getVariantAnalysisStorageLocation(variantAnalysisId),
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
VariantAnalysisScannedRepositoryState,
|
||||
} from "./shared/variant-analysis";
|
||||
import { AppCommandManager } from "../common/commands";
|
||||
import { RepositoriesFilterSortStateWithIds } from "../pure/variant-analysis-filter-sort";
|
||||
|
||||
export interface VariantAnalysisViewInterface {
|
||||
variantAnalysisId: number;
|
||||
@@ -25,4 +26,10 @@ export interface VariantAnalysisViewManager<
|
||||
variantAnalysisId: number,
|
||||
): Promise<VariantAnalysisScannedRepositoryState[]>;
|
||||
openQueryFile(variantAnalysisId: number): Promise<void>;
|
||||
openQueryText(variantAnalysisId: number): Promise<void>;
|
||||
cancelVariantAnalysis(variantAnalysisId: number): Promise<void>;
|
||||
exportResults(
|
||||
variantAnalysisId: number,
|
||||
filterSort?: RepositoriesFilterSortStateWithIds,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -115,10 +115,7 @@ export class VariantAnalysisView
|
||||
|
||||
break;
|
||||
case "cancelVariantAnalysis":
|
||||
void commands.executeCommand(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
this.variantAnalysisId,
|
||||
);
|
||||
await this.manager.cancelVariantAnalysis(this.variantAnalysisId);
|
||||
break;
|
||||
case "requestRepositoryResults":
|
||||
void commands.executeCommand(
|
||||
@@ -131,10 +128,7 @@ export class VariantAnalysisView
|
||||
await this.manager.openQueryFile(this.variantAnalysisId);
|
||||
break;
|
||||
case "openQueryText":
|
||||
void commands.executeCommand(
|
||||
"codeQL.openVariantAnalysisQueryText",
|
||||
this.variantAnalysisId,
|
||||
);
|
||||
await this.manager.openQueryText(this.variantAnalysisId);
|
||||
break;
|
||||
case "copyRepositoryList":
|
||||
void commands.executeCommand(
|
||||
@@ -144,8 +138,7 @@ export class VariantAnalysisView
|
||||
);
|
||||
break;
|
||||
case "exportResults":
|
||||
void commands.executeCommand(
|
||||
"codeQL.exportVariantAnalysisResults",
|
||||
await this.manager.exportResults(
|
||||
this.variantAnalysisId,
|
||||
msg.filterSort,
|
||||
);
|
||||
|
||||
@@ -32,12 +32,14 @@ const openQueryText = () => {
|
||||
vscode.postMessage({
|
||||
t: "openQueryText",
|
||||
});
|
||||
sendTelemetry("variant-analysis-open-query-text");
|
||||
};
|
||||
|
||||
const stopQuery = () => {
|
||||
vscode.postMessage({
|
||||
t: "cancelVariantAnalysis",
|
||||
});
|
||||
sendTelemetry("variant-analysis-cancel");
|
||||
};
|
||||
|
||||
const openLogs = () => {
|
||||
@@ -137,6 +139,7 @@ export function VariantAnalysis({
|
||||
repositoryIds: selectedRepositoryIds,
|
||||
},
|
||||
});
|
||||
sendTelemetry("variant-analysis-export-results");
|
||||
}, [filterSortState, selectedRepositoryIds]);
|
||||
|
||||
if (
|
||||
|
||||
@@ -41,6 +41,9 @@ describe("QueryHistoryManager", () => {
|
||||
let executeCommandSpy: jest.SpiedFunction<
|
||||
typeof vscode.commands.executeCommand
|
||||
>;
|
||||
let cancelVariantAnalysisSpy: jest.SpiedFunction<
|
||||
typeof variantAnalysisManagerStub.cancelVariantAnalysis
|
||||
>;
|
||||
const doCompareCallback = jest.fn();
|
||||
|
||||
let queryHistoryManager: QueryHistoryManager;
|
||||
@@ -82,9 +85,15 @@ describe("QueryHistoryManager", () => {
|
||||
onVariantAnalysisStatusUpdated: jest.fn(),
|
||||
onVariantAnalysisRemoved: jest.fn(),
|
||||
removeVariantAnalysis: jest.fn(),
|
||||
cancelVariantAnalysis: jest.fn(),
|
||||
exportResults: jest.fn(),
|
||||
showView: jest.fn(),
|
||||
} as any as VariantAnalysisManager;
|
||||
|
||||
cancelVariantAnalysisSpy = jest
|
||||
.spyOn(variantAnalysisManagerStub, "cancelVariantAnalysis")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
localQueryHistory = [
|
||||
// completed
|
||||
createMockLocalQueryInfo({
|
||||
@@ -729,8 +738,7 @@ describe("QueryHistoryManager", () => {
|
||||
const inProgress1 = variantAnalysisHistory[1];
|
||||
|
||||
await queryHistoryManager.handleCancel(inProgress1, [inProgress1]);
|
||||
expect(executeCommandSpy).toBeCalledWith(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
expect(cancelVariantAnalysisSpy).toBeCalledWith(
|
||||
inProgress1.variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
@@ -746,12 +754,10 @@ describe("QueryHistoryManager", () => {
|
||||
inProgress1,
|
||||
inProgress2,
|
||||
]);
|
||||
expect(executeCommandSpy).toBeCalledWith(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
expect(cancelVariantAnalysisSpy).toBeCalledWith(
|
||||
inProgress1.variantAnalysis.id,
|
||||
);
|
||||
expect(executeCommandSpy).toBeCalledWith(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
expect(cancelVariantAnalysisSpy).toBeCalledWith(
|
||||
inProgress2.variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
@@ -793,8 +799,7 @@ describe("QueryHistoryManager", () => {
|
||||
await queryHistoryManager.handleCancel(completedVariantAnalysis, [
|
||||
completedVariantAnalysis,
|
||||
]);
|
||||
expect(executeCommandSpy).not.toBeCalledWith(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
expect(cancelVariantAnalysisSpy).not.toBeCalledWith(
|
||||
completedVariantAnalysis.variantAnalysis,
|
||||
);
|
||||
});
|
||||
@@ -810,12 +815,10 @@ describe("QueryHistoryManager", () => {
|
||||
completedVariantAnalysis,
|
||||
failedVariantAnalysis,
|
||||
]);
|
||||
expect(executeCommandSpy).not.toBeCalledWith(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
expect(cancelVariantAnalysisSpy).not.toBeCalledWith(
|
||||
completedVariantAnalysis.variantAnalysis.id,
|
||||
);
|
||||
expect(executeCommandSpy).not.toBeCalledWith(
|
||||
"codeQL.cancelVariantAnalysis",
|
||||
expect(cancelVariantAnalysisSpy).not.toBeCalledWith(
|
||||
failedVariantAnalysis.variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
@@ -860,7 +863,7 @@ describe("QueryHistoryManager", () => {
|
||||
const item = localQueryHistory[4];
|
||||
await queryHistoryManager.handleExportResults(item, [item]);
|
||||
|
||||
expect(executeCommandSpy).not.toBeCalled();
|
||||
expect(variantAnalysisManagerStub.exportResults).not.toBeCalled();
|
||||
});
|
||||
|
||||
it("should export results for a single variant analysis", async () => {
|
||||
@@ -868,8 +871,7 @@ describe("QueryHistoryManager", () => {
|
||||
|
||||
const item = variantAnalysisHistory[1];
|
||||
await queryHistoryManager.handleExportResults(item, [item]);
|
||||
expect(executeCommandSpy).toBeCalledWith(
|
||||
"codeQL.exportVariantAnalysisResults",
|
||||
expect(variantAnalysisManagerStub.exportResults).toBeCalledWith(
|
||||
item.variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
@@ -880,7 +882,7 @@ describe("QueryHistoryManager", () => {
|
||||
const item1 = variantAnalysisHistory[1];
|
||||
const item2 = variantAnalysisHistory[3];
|
||||
await queryHistoryManager.handleExportResults(item1, [item1, item2]);
|
||||
expect(executeCommandSpy).not.toBeCalled();
|
||||
expect(variantAnalysisManagerStub.exportResults).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "fs-extra";
|
||||
import { join } from "path";
|
||||
|
||||
import { commands, ExtensionContext, Uri } from "vscode";
|
||||
import { ExtensionContext, Uri } from "vscode";
|
||||
import { DatabaseManager } from "../../../../src/local-databases";
|
||||
import { tmpDir, walkDirectory } from "../../../../src/helpers";
|
||||
import { DisposableBucket } from "../../disposable-bucket";
|
||||
@@ -54,9 +54,12 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
||||
rehydrateVariantAnalysis: rehydrateVariantAnalysisStub,
|
||||
onVariantAnalysisStatusUpdated: jest.fn(),
|
||||
showView: showViewStub,
|
||||
openQueryText: jest.fn(),
|
||||
} as any as VariantAnalysisManager;
|
||||
|
||||
let executeCommandSpy: jest.SpiedFunction<typeof commands.executeCommand>;
|
||||
let openQueryTextSpy: jest.SpiedFunction<
|
||||
typeof variantAnalysisManagerStub.openQueryText
|
||||
>;
|
||||
|
||||
beforeEach(async () => {
|
||||
// Since these tests change the state of the query history manager, we need to copy the original
|
||||
@@ -95,8 +98,8 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
||||
);
|
||||
disposables.push(qhm);
|
||||
|
||||
executeCommandSpy = jest
|
||||
.spyOn(commands, "executeCommand")
|
||||
openQueryTextSpy = jest
|
||||
.spyOn(variantAnalysisManagerStub, "openQueryText")
|
||||
.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
@@ -180,8 +183,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
||||
await qhm.readQueryHistory();
|
||||
await qhm.handleShowQueryText(qhm.treeDataProvider.allHistory[0], []);
|
||||
|
||||
expect(executeCommandSpy).toHaveBeenCalledWith(
|
||||
"codeQL.openVariantAnalysisQueryText",
|
||||
expect(openQueryTextSpy).toHaveBeenCalledWith(
|
||||
rawQueryHistory[0].variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user