@@ -53,6 +53,7 @@ import { MultiDataStoreFactoryProvider } from '../../src/datastore/DataStore';
5353import { FeatureFlagProvider } from '../../src/featureFlag/FeatureFlagProvider' ;
5454import { LspCapabilities } from '../../src/protocol/LspCapabilities' ;
5555import { LspConnection } from '../../src/protocol/LspConnection' ;
56+ import { SamStoreKey } from '../../src/schema/SamSchemas' ;
5657import { SchemaRetriever } from '../../src/schema/SchemaRetriever' ;
5758import { SchemaStore } from '../../src/schema/SchemaStore' ;
5859import { CfnExternal } from '../../src/server/CfnExternal' ;
@@ -61,6 +62,7 @@ import { CfnLspProviders } from '../../src/server/CfnLspProviders';
6162import { CfnServer } from '../../src/server/CfnServer' ;
6263import { AwsMetadata , ExtendedInitializeParams } from '../../src/server/InitParams' ;
6364import { RelationshipSchemaService } from '../../src/services/RelationshipSchemaService' ;
65+ import { DefaultSettings } from '../../src/settings/Settings' ;
6466import { LoggerFactory } from '../../src/telemetry/LoggerFactory' ;
6567import { Closeable } from '../../src/utils/Closeable' ;
6668import { ExtensionName } from '../../src/utils/ExtensionConfig' ;
@@ -108,9 +110,6 @@ export class TestExtension implements Closeable {
108110 providers ! : CfnLspProviders ;
109111 server ! : CfnServer ;
110112
111- private lspClientReady = false ;
112- private lspServerReady = false ;
113-
114113 constructor ( ) {
115114 this . serverConnection = new LspConnection (
116115 createConnection ( new StreamMessageReader ( this . readStream ) , new StreamMessageWriter ( this . writeStream ) ) ,
@@ -154,16 +153,9 @@ export class TestExtension implements Closeable {
154153 this . server = new CfnServer ( lsp , this . core , this . external , this . providers ) ;
155154 return LspCapabilities ;
156155 } ,
157- onInitialized : ( params ) => {
158- this . server . initialized ( params ) ;
159- this . lspServerReady = true ;
160- } ,
161- onShutdown : ( ) => {
162- return this . server . close ( ) ;
163- } ,
164- onExit : ( ) => {
165- return this . server . close ( ) ;
166- } ,
156+ onInitialized : ( params ) => this . server . initialized ( params ) ,
157+ onShutdown : ( ) => this . server . close ( ) ,
158+ onExit : ( ) => this . server . close ( ) ,
167159 } ,
168160 ) ;
169161
@@ -185,33 +177,30 @@ export class TestExtension implements Closeable {
185177 }
186178
187179 async ready ( ) {
188- if ( ! this . lspClientReady ) {
189- await this . clientConnection . sendRequest ( InitializeRequest . type , this . initializeParams ) ;
190- await this . clientConnection . sendNotification ( InitializedNotification . type , { } ) ;
191- this . lspClientReady = true ;
192- }
180+ await this . clientConnection . sendRequest ( InitializeRequest . type , this . initializeParams ) ;
181+ await this . clientConnection . sendNotification ( InitializedNotification . type , { } ) ;
193182
194183 await WaitFor . waitFor ( ( ) => {
195- if ( ! this . lspServerReady ) {
196- throw new Error ( 'Server is not ready yet' ) ;
184+ const store = this . external . schemaStore ;
185+ const pbSchemas = store ?. publicSchemas ?. get ( DefaultSettings . profile . region ) ;
186+ const samSchemas = store ?. samSchemas ?. get ( SamStoreKey ) ;
187+
188+ if ( pbSchemas === undefined || samSchemas === undefined ) {
189+ throw new Error ( 'Schemas not loaded yet' ) ;
197190 }
198- } , 5000 ) ;
191+ } , 2_500 ) ;
199192
200193 await flushAllPromises ( ) ;
201194 }
202195
203196 async send ( method : string , params : any ) {
204197 await this . ready ( ) ;
205- const value = await this . clientConnection . sendRequest ( method , params ) ;
206- await wait ( 100 ) ;
207- return value ;
198+ return await this . clientConnection . sendRequest ( method , params ) ;
208199 }
209200
210201 async notify ( method : string , params : any ) {
211202 await this . ready ( ) ;
212- const value = await this . clientConnection . sendNotification ( method , params ) ;
213- await wait ( 100 ) ;
214- return value ;
203+ return await this . clientConnection . sendNotification ( method , params ) ;
215204 }
216205
217206 async close ( ) {
@@ -227,18 +216,22 @@ export class TestExtension implements Closeable {
227216
228217 async openDocument ( params : DidOpenTextDocumentParams ) {
229218 await this . notify ( DidOpenTextDocumentNotification . method , params ) ;
219+ await wait ( 10 ) ;
230220 }
231221
232222 async changeDocument ( params : DidChangeTextDocumentParams ) {
233223 await this . notify ( DidChangeTextDocumentNotification . method , params ) ;
224+ await wait ( 10 ) ;
234225 }
235226
236227 async closeDocument ( params : DidCloseTextDocumentParams ) {
237228 await this . notify ( DidCloseTextDocumentNotification . method , params ) ;
229+ await wait ( 10 ) ;
238230 }
239231
240- saveDocument ( params : DidSaveTextDocumentParams ) {
241- return this . notify ( DidSaveTextDocumentNotification . method , params ) ;
232+ async saveDocument ( params : DidSaveTextDocumentParams ) {
233+ await this . notify ( DidSaveTextDocumentNotification . method , params ) ;
234+ await wait ( 10 ) ;
242235 }
243236
244237 completion ( params : CompletionParams ) {
0 commit comments