Skip to content

Commit fa01b33

Browse files
Implement modelDependency message
1 parent 0078044 commit fa01b33

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-view.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
FromDataExtensionsEditorMessage,
1515
ToDataExtensionsEditorMessage,
1616
} from "../common/interface-types";
17-
import { ProgressUpdate } from "../common/vscode/progress";
17+
import { ProgressUpdate, withProgress } from "../common/vscode/progress";
1818
import { QueryRunner } from "../query-server";
1919
import {
2020
showAndLogExceptionWithTelemetry,
@@ -44,6 +44,7 @@ import { getAutoModelUsages } from "./auto-model-usages-query";
4444
import { Mode } from "./shared/mode";
4545
import { loadModeledMethods, saveModeledMethods } from "./modeled-method-fs";
4646
import { join } from "path";
47+
import { pickExtensionPack } from "./extension-pack-picker";
4748

4849
export class DataExtensionsEditorView extends AbstractWebview<
4950
ToDataExtensionsEditorMessage,
@@ -140,6 +141,8 @@ export class DataExtensionsEditorView extends AbstractWebview<
140141

141142
break;
142143
case "modelDependency":
144+
await this.modelDependency();
145+
143146
break;
144147
case "switchMode":
145148
this.mode = msg.mode;
@@ -430,6 +433,61 @@ export class DataExtensionsEditorView extends AbstractWebview<
430433
await this.clearProgress();
431434
}
432435

436+
private async modelDependency(): Promise<void> {
437+
return withProgress(async (progress, token) => {
438+
const selectedDatabase = this.databaseManager.currentDatabaseItem;
439+
440+
// The external API methods are in the library source code, so we need to ask
441+
// the user to import the library database. We need to have the database
442+
// imported to the query server, so we need to register it to our workspace.
443+
const addedDatabase = await promptImportGithubDatabase(
444+
this.app.commands,
445+
this.databaseManager,
446+
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
447+
this.app.credentials,
448+
progress,
449+
this.cliServer,
450+
this.databaseItem.language,
451+
);
452+
if (!addedDatabase) {
453+
void this.app.logger.log("No database chosen");
454+
return;
455+
}
456+
457+
// The library database was set as the current database by importing it,
458+
// but we need to set it back to the originally selected database.
459+
await this.databaseManager.setCurrentDatabaseItem(selectedDatabase);
460+
461+
if (token.isCancellationRequested) {
462+
return;
463+
}
464+
465+
const modelFile = await pickExtensionPack(
466+
this.cliServer,
467+
addedDatabase,
468+
this.app.logger,
469+
progress,
470+
token,
471+
);
472+
if (!modelFile) {
473+
return;
474+
}
475+
476+
const view = new DataExtensionsEditorView(
477+
this.ctx,
478+
this.app,
479+
this.databaseManager,
480+
this.cliServer,
481+
this.queryRunner,
482+
this.queryStorageDir,
483+
addedDatabase,
484+
modelFile,
485+
Mode.Framework,
486+
);
487+
await view.openView();
488+
});
489+
}
490+
433491
/*
434492
* Progress in this class is a bit weird. Most of the progress is based on running the query.
435493
* Query progress is always between 0 and 1000. However, we still have some steps that need

extensions/ql-vscode/src/databases/database-fetcher.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export async function promptImportInternetDatabase(
8585
* @param credentials the credentials to use to authenticate with GitHub
8686
* @param progress the progress callback
8787
* @param cli the CodeQL CLI server
88+
* @param language the language to download. If undefined, the user will be prompted to choose a language.
8889
*/
8990
export async function promptImportGithubDatabase(
9091
commandManager: AppCommandManager,
@@ -93,6 +94,7 @@ export async function promptImportGithubDatabase(
9394
credentials: Credentials | undefined,
9495
progress: ProgressCallback,
9596
cli?: CodeQLCliServer,
97+
language?: string,
9698
): Promise<DatabaseItem | undefined> {
9799
const githubRepo = await askForGitHubRepo(progress);
98100
if (!githubRepo) {
@@ -106,6 +108,7 @@ export async function promptImportGithubDatabase(
106108
credentials,
107109
progress,
108110
cli,
111+
language,
109112
);
110113

111114
if (databaseItem) {

0 commit comments

Comments
 (0)