Merge pull request #2626 from github/robertbrignull/data-make-selected

Instead of resetting the database after importing, pass through makeSelected = false
This commit is contained in:
Robert
2023-07-21 16:20:37 +01:00
committed by GitHub
2 changed files with 17 additions and 13 deletions

View File

@@ -296,7 +296,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) {
@@ -426,7 +426,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;
}
@@ -457,14 +457,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,
@@ -473,16 +472,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;
}

View File

@@ -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,
@@ -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) {
@@ -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.",
@@ -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,
@@ -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)) {
@@ -210,6 +217,7 @@ export async function downloadGitHubDatabase(
`${owner}/${name}`,
progress,
cli,
makeSelected,
);
}
@@ -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,
@@ -277,6 +286,7 @@ async function databaseArchiveFetcher(
nameOverride: string | undefined,
progress: ProgressCallback,
cli?: CodeQLCliServer,
makeSelected = true,
): Promise<DatabaseItem> {
progress({
message: "Getting database",
@@ -315,8 +325,6 @@ async function databaseArchiveFetcher(
});
await ensureZippedSourceLocation(dbPath);
const makeSelected = true;
const item = await databaseManager.openDatabase(
Uri.file(dbPath),
makeSelected,