@@ -90,6 +90,8 @@ export default class ConnectionController {
90
90
private _currentConnectionId : null | string = null ;
91
91
92
92
_connectionAttempt : null | ConnectionAttempt = null ;
93
+ _connectionStringInputCancellationToken : null | vscode . CancellationTokenSource =
94
+ null ;
93
95
private _connectingConnectionId : null | string = null ;
94
96
private _disconnecting = false ;
95
97
@@ -144,33 +146,44 @@ export default class ConnectionController {
144
146
145
147
log . info ( 'connectWithURI command called' ) ;
146
148
147
- try {
148
- connectionString = await vscode . window . showInputBox ( {
149
- value : '' ,
150
- ignoreFocusOut : true ,
151
- placeHolder :
152
- 'e.g. mongodb+srv://username:[email protected] /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 ;
161
151
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:[email protected] /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
+ } ,
170
177
} ,
171
- } ) ;
178
+ cancellationToken . token
179
+ ) ;
172
180
} catch ( e ) {
173
181
return false ;
182
+ } finally {
183
+ if ( this . _connectionStringInputCancellationToken === cancellationToken ) {
184
+ this . _connectionStringInputCancellationToken . dispose ( ) ;
185
+ this . _connectionStringInputCancellationToken = null ;
186
+ }
174
187
}
175
188
176
189
if ( ! connectionString ) {
@@ -687,6 +700,10 @@ export default class ConnectionController {
687
700
this . eventEmitter . removeListener ( eventType , listener ) ;
688
701
}
689
702
703
+ closeConnectionStringInput ( ) {
704
+ this . _connectionStringInputCancellationToken ?. cancel ( ) ;
705
+ }
706
+
690
707
isConnecting ( ) : boolean {
691
708
return ! ! this . _connectionAttempt ;
692
709
}
0 commit comments