@@ -417,6 +417,25 @@ describe('DefaultDocumentBuilder', () => {
417417 await builder . build ( [ document ] , { validation : true } ) ;
418418 } ) ;
419419
420+ test ( '`waitUntil` will correctly resolve if the document is already in the target state.' , async ( ) => {
421+ const services = await createServices ( ) ;
422+ const documentFactory = services . shared . workspace . LangiumDocumentFactory ;
423+ const documents = services . shared . workspace . LangiumDocuments ;
424+ const builder = services . shared . workspace . DocumentBuilder ;
425+ const documentUri = URI . parse ( 'file:///test1.txt' ) ;
426+ const document = documentFactory . fromString ( '' , documentUri ) ;
427+ documents . addDocument ( document ) ;
428+ await builder . build ( [ document ] , { validation : true } ) ;
429+ expect ( document . state ) . toBe ( DocumentState . Validated ) ;
430+ // Should instantly resolve, since the document is already validated.
431+ await expect (
432+ Promise . race ( [
433+ builder . waitUntil ( DocumentState . Validated , documentUri ) ,
434+ new Promise ( ( _ , rej ) => setTimeout ( rej ) )
435+ ] )
436+ ) . resolves . toEqual ( documentUri ) ;
437+ } ) ;
438+
420439 test ( '`onDocumentPhase` always triggers before the respective `onBuildPhase`' , async ( ) => {
421440 const services = await createServices ( ) ;
422441 const documentFactory = services . shared . workspace . LangiumDocumentFactory ;
0 commit comments