@@ -33,6 +33,7 @@ import type {
33
33
PlaygroundTextAndSelection ,
34
34
MongoClientOptions ,
35
35
} from '../types/playgroundType' ;
36
+ import type { ClearCompletionsCache } from '../types/completionsCache' ;
36
37
import { Visitor } from './visitor' ;
37
38
import type { CompletionState } from './visitor' ;
38
39
@@ -134,10 +135,11 @@ export default class MongoDBService {
134
135
* Disconnect from CliServiceProvider.
135
136
*/
136
137
async disconnectFromServiceProvider ( ) : Promise < void > {
137
- this . _clearCachedDatabases ( ) ;
138
- this . _clearCachedCollections ( ) ;
139
- this . _clearCachedFields ( ) ;
140
-
138
+ this . clearCachedCompletions ( {
139
+ databases : true ,
140
+ collections : true ,
141
+ fields : true ,
142
+ } ) ;
141
143
await this . _clearCurrentConnection ( ) ;
142
144
}
143
145
@@ -148,7 +150,7 @@ export default class MongoDBService {
148
150
params : PlaygroundEvaluateParams ,
149
151
token : CancellationToken
150
152
) : Promise < ShellEvaluateResult | undefined > {
151
- this . _clearCachedFields ( ) ;
153
+ this . clearCachedFields ( ) ;
152
154
153
155
return new Promise ( ( resolve ) => {
154
156
if ( this . _connectionId !== params . connectionId ) {
@@ -511,7 +513,7 @@ export default class MongoDBService {
511
513
) ;
512
514
513
515
// Create and cache field completion items.
514
- this . _cacheFields ( namespace , schemaFields ) ;
516
+ this . cacheFields ( namespace , schemaFields ) ;
515
517
}
516
518
}
517
519
}
@@ -1021,7 +1023,7 @@ export default class MongoDBService {
1021
1023
/**
1022
1024
* Convert schema field names to Completion Items and cache them.
1023
1025
*/
1024
- _cacheFields ( namespace : string , fields : string [ ] ) : void {
1026
+ cacheFields ( namespace : string , fields : string [ ] ) : void {
1025
1027
if ( namespace ) {
1026
1028
this . _fields [ namespace ] = fields ? fields : [ ] ;
1027
1029
}
@@ -1045,15 +1047,15 @@ export default class MongoDBService {
1045
1047
this . _collections [ database ] = collections . map ( ( item ) => item . name ) ;
1046
1048
}
1047
1049
1048
- _clearCachedFields ( ) : void {
1050
+ clearCachedFields ( ) : void {
1049
1051
this . _fields = { } ;
1050
1052
}
1051
1053
1052
- _clearCachedDatabases ( ) : void {
1054
+ clearCachedDatabases ( ) : void {
1053
1055
this . _databaseCompletionItems = [ ] ;
1054
1056
}
1055
1057
1056
- _clearCachedCollections ( ) : void {
1058
+ clearCachedCollections ( ) : void {
1057
1059
this . _collections = { } ;
1058
1060
}
1059
1061
@@ -1068,4 +1070,16 @@ export default class MongoDBService {
1068
1070
await serviceProvider . close ( true ) ;
1069
1071
}
1070
1072
}
1073
+
1074
+ clearCachedCompletions ( clear : ClearCompletionsCache ) : void {
1075
+ if ( clear . fields ) {
1076
+ this . _fields = { } ;
1077
+ }
1078
+ if ( clear . databases ) {
1079
+ this . _databaseCompletionItems = [ ] ;
1080
+ }
1081
+ if ( clear . collections ) {
1082
+ this . _collections = { } ;
1083
+ }
1084
+ }
1071
1085
}
0 commit comments