@@ -94,27 +94,31 @@ export function createZModelLanguageServices(
9494
9595 // when documents reach Parsed state, inspect plugin declarations and load corresponding
9696 // plugin zmodel docs
97- shared . workspace . DocumentBuilder . onDocumentPhase ( DocumentState . Parsed , async ( doc ) => {
98- if ( doc . parseResult . lexerErrors . length > 0 || doc . parseResult . parserErrors . length > 0 ) {
99- // balk if there are lexer or parser errors
100- return ;
101- }
97+ // Note we must use `noBuildPhase` instead of `onDocumentPhase` here because the latter is
98+ // not called when not running inside a language server.
99+ shared . workspace . DocumentBuilder . onBuildPhase ( DocumentState . Parsed , async ( documents ) => {
100+ for ( const doc of documents ) {
101+ if ( doc . parseResult . lexerErrors . length > 0 || doc . parseResult . parserErrors . length > 0 ) {
102+ // balk if there are lexer or parser errors
103+ return ;
104+ }
102105
103- if ( doc . uri . scheme !== 'file' ) {
104- return ;
105- }
106+ if ( doc . uri . scheme !== 'file' ) {
107+ return ;
108+ }
106109
107- const schemaPath = fileURLToPath ( doc . uri . toString ( ) ) ;
108- const pluginSchemas = getPluginDocuments ( doc . parseResult . value as Model , schemaPath ) ;
109- for ( const plugin of pluginSchemas ) {
110- // load the plugin model document
111- const pluginDoc = await shared . workspace . LangiumDocuments . getOrCreateDocument (
112- URI . file ( path . resolve ( plugin ) ) ,
113- ) ;
114- // add to indexer so the plugin model's definitions are globally visible
115- shared . workspace . IndexManager . updateContent ( pluginDoc ) ;
116- if ( logToConsole ) {
117- console . log ( `Loaded plugin model: ${ plugin } ` ) ;
110+ const schemaPath = fileURLToPath ( doc . uri . toString ( ) ) ;
111+ const pluginSchemas = getPluginDocuments ( doc . parseResult . value as Model , schemaPath ) ;
112+ for ( const plugin of pluginSchemas ) {
113+ // load the plugin model document
114+ const pluginDoc = await shared . workspace . LangiumDocuments . getOrCreateDocument (
115+ URI . file ( path . resolve ( plugin ) ) ,
116+ ) ;
117+ // add to indexer so the plugin model's definitions are globally visible
118+ shared . workspace . IndexManager . updateContent ( pluginDoc ) ;
119+ if ( logToConsole ) {
120+ console . log ( `Loaded plugin model: ${ plugin } ` ) ;
121+ }
118122 }
119123 }
120124 } ) ;
0 commit comments