File tree Expand file tree Collapse file tree
extensions/ql-vscode/src/databases Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,16 +99,29 @@ export class DbConfigStore extends DisposableObject {
9999 throw Error ( "Cannot add remote list if config is not loaded" ) ;
100100 }
101101
102+ if ( this . doesRemoteListExist ( listName ) ) {
103+ throw Error ( `A remote list with the name '${ listName } ' already exists` ) ;
104+ }
105+
102106 const config : DbConfig = cloneDbConfig ( this . config ) ;
103107 config . databases . remote . repositoryLists . push ( {
104108 name : listName ,
105109 repositories : [ ] ,
106110 } ) ;
107111
108- // TODO: validate that the name doesn't already exist
109112 await this . writeConfig ( config ) ;
110113 }
111114
115+ public doesRemoteListExist ( listName : string ) : boolean {
116+ if ( ! this . config ) {
117+ throw Error ( "Cannot check remote list existence if config is not loaded" ) ;
118+ }
119+
120+ return this . config . databases . remote . repositoryLists . some (
121+ ( l ) => l . name === listName ,
122+ ) ;
123+ }
124+
112125 private async writeConfig ( config : DbConfig ) : Promise < void > {
113126 await writeJSON ( this . configPath , config , {
114127 spaces : 2 ,
Original file line number Diff line number Diff line change @@ -76,6 +76,14 @@ export class DbManager {
7676 }
7777
7878 public async addNewRemoteList ( listName : string ) : Promise < void > {
79+ if ( this . dbConfigStore . doesRemoteListExist ( listName ) ) {
80+ throw Error ( `A list with the name '${ listName } ' already exists` ) ;
81+ }
82+
7983 await this . dbConfigStore . addRemoteList ( listName ) ;
8084 }
85+
86+ public doesRemoteListExist ( listName : string ) : boolean {
87+ return this . dbConfigStore . doesRemoteListExist ( listName ) ;
88+ }
8189}
Original file line number Diff line number Diff line change 11import { TreeViewExpansionEvent , window , workspace } from "vscode" ;
22import { commandRunner } from "../../commandRunner" ;
3+ import { showAndLogErrorMessage } from "../../helpers" ;
34import { DisposableObject } from "../../pure/disposable-object" ;
45import { DbManager } from "../db-manager" ;
56import { DbTreeDataProvider } from "./db-tree-data-provider" ;
@@ -58,15 +59,21 @@ export class DbPanel extends DisposableObject {
5859 }
5960
6061 private async addNewRemoteList ( ) : Promise < void > {
61- // TODO: check that config exists *before* showing the input box
6262 const listName = await window . showInputBox ( {
6363 prompt : "Enter a name for the new list" ,
6464 placeHolder : "example-list" ,
6565 } ) ;
6666 if ( listName === undefined ) {
6767 return ;
6868 }
69- await this . dbManager . addNewRemoteList ( listName ) ;
69+
70+ if ( this . dbManager . doesRemoteListExist ( listName ) ) {
71+ void showAndLogErrorMessage (
72+ `A list with the name '${ listName } ' already exists` ,
73+ ) ;
74+ } else {
75+ await this . dbManager . addNewRemoteList ( listName ) ;
76+ }
7077 }
7178
7279 private async setSelectedItem ( treeViewItem : DbTreeViewItem ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments