Skip to content

Commit e6566b9

Browse files
Instead of resetting the database after importing, pass through makeSelected = false
1 parent 778f839 commit e6566b9

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
293293
// In application mode, we need the database of a specific library to generate
294294
// the modeled methods. In framework mode, we'll use the current database.
295295
if (this.mode === Mode.Application) {
296-
addedDatabase = await this.promptImportAndResetDatabase((update) =>
296+
addedDatabase = await this.promptImportDatabase((update) =>
297297
this.showProgress(update),
298298
);
299299
if (!addedDatabase) {
@@ -423,7 +423,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
423423

424424
private async modelDependency(): Promise<void> {
425425
return withProgress(async (progress, token) => {
426-
const addedDatabase = await this.promptImportAndResetDatabase(progress);
426+
const addedDatabase = await this.promptImportDatabase(progress);
427427
if (!addedDatabase || token.isCancellationRequested) {
428428
return;
429429
}
@@ -454,14 +454,13 @@ export class DataExtensionsEditorView extends AbstractWebview<
454454
});
455455
}
456456

457-
private async promptImportAndResetDatabase(
457+
private async promptImportDatabase(
458458
progress: ProgressCallback,
459459
): Promise<DatabaseItem | undefined> {
460-
const selectedDatabase = this.databaseManager.currentDatabaseItem;
461-
462460
// The external API methods are in the library source code, so we need to ask
463461
// the user to import the library database. We need to have the database
464462
// imported to the query server, so we need to register it to our workspace.
463+
const makeSelected = false;
465464
const addedDatabase = await promptImportGithubDatabase(
466465
this.app.commands,
467466
this.databaseManager,
@@ -470,16 +469,13 @@ export class DataExtensionsEditorView extends AbstractWebview<
470469
progress,
471470
this.cliServer,
472471
this.databaseItem.language,
472+
makeSelected,
473473
);
474474
if (!addedDatabase) {
475475
void this.app.logger.log("No database chosen");
476-
return undefined;
476+
return;
477477
}
478478

479-
// The library database was set as the current database by importing it,
480-
// but we need to set it back to the originally selected database.
481-
await this.databaseManager.setCurrentDatabaseItem(selectedDatabase);
482-
483479
return addedDatabase;
484480
}
485481

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export async function promptImportInternetDatabase(
8686
* @param progress the progress callback
8787
* @param cli the CodeQL CLI server
8888
* @param language the language to download. If undefined, the user will be prompted to choose a language.
89+
* @param makeSelected make the new database selected in the databases panel (default: true)
8990
*/
9091
export async function promptImportGithubDatabase(
9192
commandManager: AppCommandManager,
@@ -95,6 +96,7 @@ export async function promptImportGithubDatabase(
9596
progress: ProgressCallback,
9697
cli?: CodeQLCliServer,
9798
language?: string,
99+
makeSelected = true,
98100
): Promise<DatabaseItem | undefined> {
99101
const githubRepo = await askForGitHubRepo(progress);
100102
if (!githubRepo) {
@@ -109,10 +111,13 @@ export async function promptImportGithubDatabase(
109111
progress,
110112
cli,
111113
language,
114+
makeSelected,
112115
);
113116

114117
if (databaseItem) {
115-
await commandManager.execute("codeQLDatabases.focus");
118+
if (makeSelected) {
119+
await commandManager.execute("codeQLDatabases.focus");
120+
}
116121
void showAndLogInformationMessage(
117122
extLogger,
118123
"Database downloaded and imported successfully.",
@@ -157,6 +162,7 @@ export async function askForGitHubRepo(
157162
* @param progress the progress callback
158163
* @param cli the CodeQL CLI server
159164
* @param language the language to download. If undefined, the user will be prompted to choose a language.
165+
* @param makeSelected make the new database selected in the databases panel (default: true)
160166
**/
161167
export async function downloadGitHubDatabase(
162168
githubRepo: string,
@@ -166,6 +172,7 @@ export async function downloadGitHubDatabase(
166172
progress: ProgressCallback,
167173
cli?: CodeQLCliServer,
168174
language?: string,
175+
makeSelected = true,
169176
): Promise<DatabaseItem | undefined> {
170177
const nwo = getNwoFromGitHubUrl(githubRepo) || githubRepo;
171178
if (!isValidGitHubNwo(nwo)) {
@@ -210,6 +217,7 @@ export async function downloadGitHubDatabase(
210217
`${owner}/${name}`,
211218
progress,
212219
cli,
220+
makeSelected,
213221
);
214222
}
215223

@@ -268,6 +276,7 @@ export async function importArchiveDatabase(
268276
* @param storagePath where to store the unzipped database.
269277
* @param nameOverride a name for the database that overrides the default
270278
* @param progress callback to send progress messages to
279+
* @param makeSelected make the new database selected in the databases panel (default: true)
271280
*/
272281
async function databaseArchiveFetcher(
273282
databaseUrl: string,
@@ -277,6 +286,7 @@ async function databaseArchiveFetcher(
277286
nameOverride: string | undefined,
278287
progress: ProgressCallback,
279288
cli?: CodeQLCliServer,
289+
makeSelected = true,
280290
): Promise<DatabaseItem> {
281291
progress({
282292
message: "Getting database",
@@ -315,8 +325,6 @@ async function databaseArchiveFetcher(
315325
});
316326
await ensureZippedSourceLocation(dbPath);
317327

318-
const makeSelected = true;
319-
320328
const item = await databaseManager.openDatabase(
321329
Uri.file(dbPath),
322330
makeSelected,

0 commit comments

Comments
 (0)