@@ -14,7 +14,11 @@ import {
1414 FromDataExtensionsEditorMessage ,
1515 ToDataExtensionsEditorMessage ,
1616} from "../common/interface-types" ;
17- import { ProgressUpdate , withProgress } from "../common/vscode/progress" ;
17+ import {
18+ ProgressCallback ,
19+ ProgressUpdate ,
20+ withProgress ,
21+ } from "../common/vscode/progress" ;
1822import { QueryRunner } from "../query-server" ;
1923import {
2024 showAndLogExceptionWithTelemetry ,
@@ -288,29 +292,12 @@ export class DataExtensionsEditorView extends AbstractWebview<
288292 // In application mode, we need the database of a specific library to generate
289293 // the modeled methods. In framework mode, we'll use the current database.
290294 if ( this . mode === Mode . Application ) {
291- const selectedDatabase = this . databaseManager . currentDatabaseItem ;
292-
293- // The external API methods are in the library source code, so we need to ask
294- // the user to import the library database. We need to have the database
295- // imported to the query server, so we need to register it to our workspace.
296- addedDatabase = await promptImportGithubDatabase (
297- this . app . commands ,
298- this . databaseManager ,
299- this . app . workspaceStoragePath ?? this . app . globalStoragePath ,
300- this . app . credentials ,
301- ( update ) => this . showProgress ( update ) ,
302- this . cliServer ,
295+ addedDatabase = await this . promptImportAndResetDatabase ( ( update ) =>
296+ this . showProgress ( update ) ,
303297 ) ;
304298 if ( ! addedDatabase ) {
305- await this . clearProgress ( ) ;
306- void this . app . logger . log ( "No database chosen" ) ;
307-
308299 return ;
309300 }
310-
311- // The library database was set as the current database by importing it,
312- // but we need to set it back to the originally selected database.
313- await this . databaseManager . setCurrentDatabaseItem ( selectedDatabase ) ;
314301 }
315302
316303 await this . showProgress ( {
@@ -435,30 +422,8 @@ export class DataExtensionsEditorView extends AbstractWebview<
435422
436423 private async modelDependency ( ) : Promise < void > {
437424 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 ) {
425+ const addedDatabase = await this . promptImportAndResetDatabase ( progress ) ;
426+ if ( ! addedDatabase || token . isCancellationRequested ) {
462427 return ;
463428 }
464429
@@ -488,6 +453,35 @@ export class DataExtensionsEditorView extends AbstractWebview<
488453 } ) ;
489454 }
490455
456+ private async promptImportAndResetDatabase (
457+ progress : ProgressCallback ,
458+ ) : Promise < DatabaseItem | undefined > {
459+ const selectedDatabase = this . databaseManager . currentDatabaseItem ;
460+
461+ // The external API methods are in the library source code, so we need to ask
462+ // the user to import the library database. We need to have the database
463+ // imported to the query server, so we need to register it to our workspace.
464+ const addedDatabase = await promptImportGithubDatabase (
465+ this . app . commands ,
466+ this . databaseManager ,
467+ this . app . workspaceStoragePath ?? this . app . globalStoragePath ,
468+ this . app . credentials ,
469+ progress ,
470+ this . cliServer ,
471+ this . databaseItem . language ,
472+ ) ;
473+ if ( ! addedDatabase ) {
474+ void this . app . logger . log ( "No database chosen" ) ;
475+ return undefined ;
476+ }
477+
478+ // The library database was set as the current database by importing it,
479+ // but we need to set it back to the originally selected database.
480+ await this . databaseManager . setCurrentDatabaseItem ( selectedDatabase ) ;
481+
482+ return addedDatabase ;
483+ }
484+
491485 /*
492486 * Progress in this class is a bit weird. Most of the progress is based on running the query.
493487 * Query progress is always between 0 and 1000. However, we still have some steps that need
0 commit comments