@@ -90,6 +90,8 @@ export default class ConnectionController {
9090 private _currentConnectionId : null | string = null ;
9191
9292 _connectionAttempt : null | ConnectionAttempt = null ;
93+ _connectionStringInputCancellationToken : null | vscode . CancellationTokenSource =
94+ null ;
9395 private _connectingConnectionId : null | string = null ;
9496 private _disconnecting = false ;
9597
@@ -144,33 +146,44 @@ export default class ConnectionController {
144146
145147 log . info ( 'connectWithURI command called' ) ;
146148
147- try {
148- connectionString = await vscode . window . showInputBox ( {
149- value : '' ,
150- ignoreFocusOut : true ,
151- placeHolder :
152- 'e.g. mongodb+srv://username:password@cluster0.mongodb.net/admin' ,
153- prompt : 'Enter your connection string (SRV or standard)' ,
154- validateInput : ( uri : string ) => {
155- if (
156- ! uri . startsWith ( 'mongodb://' ) &&
157- ! uri . startsWith ( 'mongodb+srv://' )
158- ) {
159- return 'MongoDB connection strings begin with "mongodb://" or "mongodb+srv://"' ;
160- }
149+ const cancellationToken = new vscode . CancellationTokenSource ( ) ;
150+ this . _connectionStringInputCancellationToken = cancellationToken ;
161151
162- try {
163- // eslint-disable-next-line no-new
164- new ConnectionString ( uri ) ;
165- } catch ( error ) {
166- return formatError ( error ) . message ;
167- }
168-
169- return null ;
152+ try {
153+ connectionString = await vscode . window . showInputBox (
154+ {
155+ value : '' ,
156+ ignoreFocusOut : true ,
157+ placeHolder :
158+ 'e.g. mongodb+srv://username:password@cluster0.mongodb.net/admin' ,
159+ prompt : 'Enter your connection string (SRV or standard)' ,
160+ validateInput : ( uri : string ) => {
161+ if (
162+ ! uri . startsWith ( 'mongodb://' ) &&
163+ ! uri . startsWith ( 'mongodb+srv://' )
164+ ) {
165+ return 'MongoDB connection strings begin with "mongodb://" or "mongodb+srv://"' ;
166+ }
167+
168+ try {
169+ // eslint-disable-next-line no-new
170+ new ConnectionString ( uri ) ;
171+ } catch ( error ) {
172+ return formatError ( error ) . message ;
173+ }
174+
175+ return null ;
176+ } ,
170177 } ,
171- } ) ;
178+ cancellationToken . token
179+ ) ;
172180 } catch ( e ) {
173181 return false ;
182+ } finally {
183+ if ( this . _connectionStringInputCancellationToken === cancellationToken ) {
184+ this . _connectionStringInputCancellationToken . dispose ( ) ;
185+ this . _connectionStringInputCancellationToken = null ;
186+ }
174187 }
175188
176189 if ( ! connectionString ) {
@@ -687,6 +700,10 @@ export default class ConnectionController {
687700 this . eventEmitter . removeListener ( eventType , listener ) ;
688701 }
689702
703+ closeConnectionStringInput ( ) {
704+ this . _connectionStringInputCancellationToken ?. cancel ( ) ;
705+ }
706+
690707 isConnecting ( ) : boolean {
691708 return ! ! this . _connectionAttempt ;
692709 }
0 commit comments