Skip to content

Commit d3ef294

Browse files
committed
Extract finding existing database item into separate method
1 parent b9c8983 commit d3ef294

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

extensions/ql-vscode/src/skeleton-query-wizard.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -217,40 +217,18 @@ export class SkeletonQueryWizard {
217217
}
218218

219219
private async selectExistingDatabase() {
220-
if (this.language === undefined) {
221-
throw new Error("Language is undefined");
222-
}
223-
224220
if (this.qlPackStoragePath === undefined) {
225221
throw new Error("QL Pack storage path is undefined");
226222
}
227223

228-
const databaseNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
229-
230-
const existingDatabaseItem = await this.findDatabaseItemByNwo(
231-
this.language,
232-
databaseNwo,
233-
this.databaseManager.databaseItems,
234-
);
224+
const existingDatabaseItem = await this.findExistingDatabaseItem();
235225

236226
if (existingDatabaseItem) {
237227
// select the found database
238228
await this.databaseManager.setCurrentDatabaseItem(existingDatabaseItem);
239229
} else {
240-
const sameLanguageDatabaseItem = await this.findDatabaseItemByLanguage(
241-
this.language,
242-
this.databaseManager.databaseItems,
243-
);
244-
245-
if (sameLanguageDatabaseItem) {
246-
// select the found database
247-
await this.databaseManager.setCurrentDatabaseItem(
248-
sameLanguageDatabaseItem,
249-
);
250-
} else {
251-
// download new database and select it
252-
await this.downloadDatabase();
253-
}
230+
// download new database and select it
231+
await this.downloadDatabase();
254232
}
255233
}
256234

@@ -286,4 +264,24 @@ export class SkeletonQueryWizard {
286264
}
287265
return dbs[0];
288266
}
267+
268+
private async findExistingDatabaseItem() {
269+
if (this.language === undefined) {
270+
throw new Error("Language is undefined");
271+
}
272+
273+
const databaseNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
274+
275+
return (
276+
(await this.findDatabaseItemByNwo(
277+
this.language,
278+
databaseNwo,
279+
this.databaseManager.databaseItems,
280+
)) ||
281+
(await this.findDatabaseItemByLanguage(
282+
this.language,
283+
this.databaseManager.databaseItems,
284+
))
285+
);
286+
}
289287
}

0 commit comments

Comments
 (0)