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
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
// In application mode, we need the database of a specific library to generate
// the modeled methods. In framework mode, we'll use the current database.
if (this.mode === Mode.Application) {
addedDatabase = await this.promptImportAndResetDatabase((update) =>
addedDatabase = await this.promptImportDatabase((update) =>
this.showProgress(update),
);
if (!addedDatabase) {
Expand Down Expand Up @@ -423,7 +423,7 @@ export class DataExtensionsEditorView extends AbstractWebview<

private async modelDependency(): Promise<void> {
return withProgress(async (progress, token) => {
const addedDatabase = await this.promptImportAndResetDatabase(progress);
const addedDatabase = await this.promptImportDatabase(progress);
if (!addedDatabase || token.isCancellationRequested) {
return;
}
Expand Down Expand Up @@ -454,14 +454,13 @@ export class DataExtensionsEditorView extends AbstractWebview<
});
}

private async promptImportAndResetDatabase(
private async promptImportDatabase(
progress: ProgressCallback,
): Promise<DatabaseItem | undefined> {
const selectedDatabase = this.databaseManager.currentDatabaseItem;

// The external API methods are in the library source code, so we need to ask
// 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 addedDatabase = await promptImportGithubDatabase(
this.app.commands,
this.databaseManager,
Expand All @@ -470,16 +469,13 @@ export class DataExtensionsEditorView extends AbstractWebview<
progress,
this.cliServer,
this.databaseItem.language,
makeSelected,
);
if (!addedDatabase) {
void this.app.logger.log("No database chosen");
return undefined;
return;
}

// The library database was set as the current database by importing it,
// but we need to set it back to the originally selected database.
await this.databaseManager.setCurrentDatabaseItem(selectedDatabase);

return addedDatabase;
}

Expand Down
14 changes: 11 additions & 3 deletions extensions/ql-vscode/src/databases/database-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export async function promptImportInternetDatabase(
* @param progress the progress callback
* @param cli the CodeQL CLI server
* @param language the language to download. If undefined, the user will be prompted to choose a language.
* @param makeSelected make the new database selected in the databases panel (default: true)
*/
export async function promptImportGithubDatabase(
commandManager: AppCommandManager,
Expand All @@ -95,6 +96,7 @@ export async function promptImportGithubDatabase(
progress: ProgressCallback,
cli?: CodeQLCliServer,
language?: string,
makeSelected = true,
): Promise<DatabaseItem | undefined> {
const githubRepo = await askForGitHubRepo(progress);
if (!githubRepo) {
Expand All @@ -109,10 +111,13 @@ export async function promptImportGithubDatabase(
progress,
cli,
language,
makeSelected,
);

if (databaseItem) {
await commandManager.execute("codeQLDatabases.focus");
if (makeSelected) {
await commandManager.execute("codeQLDatabases.focus");
}
void showAndLogInformationMessage(
extLogger,
"Database downloaded and imported successfully.",
Expand Down Expand Up @@ -157,6 +162,7 @@ export async function askForGitHubRepo(
* @param progress the progress callback
* @param cli the CodeQL CLI server
* @param language the language to download. If undefined, the user will be prompted to choose a language.
* @param makeSelected make the new database selected in the databases panel (default: true)
**/
export async function downloadGitHubDatabase(
githubRepo: string,
Expand All @@ -166,6 +172,7 @@ export async function downloadGitHubDatabase(
progress: ProgressCallback,
cli?: CodeQLCliServer,
language?: string,
makeSelected = true,
): Promise<DatabaseItem | undefined> {
const nwo = getNwoFromGitHubUrl(githubRepo) || githubRepo;
if (!isValidGitHubNwo(nwo)) {
Expand Down Expand Up @@ -210,6 +217,7 @@ export async function downloadGitHubDatabase(
`${owner}/${name}`,
progress,
cli,
makeSelected,
);
}

Expand Down Expand Up @@ -268,6 +276,7 @@ export async function importArchiveDatabase(
* @param storagePath where to store the unzipped database.
* @param nameOverride a name for the database that overrides the default
* @param progress callback to send progress messages to
* @param makeSelected make the new database selected in the databases panel (default: true)
*/
async function databaseArchiveFetcher(
databaseUrl: string,
Expand All @@ -277,6 +286,7 @@ async function databaseArchiveFetcher(
nameOverride: string | undefined,
progress: ProgressCallback,
cli?: CodeQLCliServer,
makeSelected = true,
): Promise<DatabaseItem> {
progress({
message: "Getting database",
Expand Down Expand Up @@ -315,8 +325,6 @@ async function databaseArchiveFetcher(
});
await ensureZippedSourceLocation(dbPath);

const makeSelected = true;

const item = await databaseManager.openDatabase(
Uri.file(dbPath),
makeSelected,
Expand Down