Skip to content

Commit 0617e3e

Browse files
Merge pull request #2626 from github/robertbrignull/data-make-selected
Instead of resetting the database after importing, pass through makeSelected = false
2 parents dacaf4e + e6566b9 commit 0617e3e

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
@@ -296,7 +296,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
296296
// In application mode, we need the database of a specific library to generate
297297
// the modeled methods. In framework mode, we'll use the current database.
298298
if (this.mode === Mode.Application) {
299-
addedDatabase = await this.promptImportAndResetDatabase((update) =>
299+
addedDatabase = await this.promptImportDatabase((update) =>
300300
this.showProgress(update),
301301
);
302302
if (!addedDatabase) {
@@ -426,7 +426,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
426426

427427
private async modelDependency(): Promise<void> {
428428
return withProgress(async (progress, token) => {
429-
const addedDatabase = await this.promptImportAndResetDatabase(progress);
429+
const addedDatabase = await this.promptImportDatabase(progress);
430430
if (!addedDatabase || token.isCancellationRequested) {
431431
return;
432432
}
@@ -457,14 +457,13 @@ export class DataExtensionsEditorView extends AbstractWebview<
457457
});
458458
}
459459

460-
private async promptImportAndResetDatabase(
460+
private async promptImportDatabase(
461461
progress: ProgressCallback,
462462
): Promise<DatabaseItem | undefined> {
463-
const selectedDatabase = this.databaseManager.currentDatabaseItem;
464-
465463
// The external API methods are in the library source code, so we need to ask
466464
// the user to import the library database. We need to have the database
467465
// imported to the query server, so we need to register it to our workspace.
466+
const makeSelected = false;
468467
const addedDatabase = await promptImportGithubDatabase(
469468
this.app.commands,
470469
this.databaseManager,
@@ -473,16 +472,13 @@ export class DataExtensionsEditorView extends AbstractWebview<
473472
progress,
474473
this.cliServer,
475474
this.databaseItem.language,
475+
makeSelected,
476476
);
477477
if (!addedDatabase) {
478478
void this.app.logger.log("No database chosen");
479-
return undefined;
479+
return;
480480
}
481481

482-
// The library database was set as the current database by importing it,
483-
// but we need to set it back to the originally selected database.
484-
await this.databaseManager.setCurrentDatabaseItem(selectedDatabase);
485-
486482
return addedDatabase;
487483
}
488484

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)