MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / createZModelLanguageServices

Function createZModelLanguageServices

packages/language/src/module.ts:94–148  ·  view source on GitHub ↗
(
    context: DefaultSharedModuleContext,
    logToConsole = false,
)

Source from the content-addressed store, hash-verified

92 * @returns An object wrapping the shared services and the language-specific services
93 */
94export function createZModelLanguageServices(
95 context: DefaultSharedModuleContext,
96 logToConsole = false,
97): {
98 shared: LangiumSharedServices;
99 ZModelLanguage: ZModelServices;
100} {
101 const shared = inject(createDefaultSharedModule(context), ZModelGeneratedSharedModule, ZModelSharedModule);
102 const ZModelLanguage = inject(createDefaultModule({ shared }), ZModelGeneratedModule, ZModelLanguageModule);
103 shared.ServiceRegistry.register(ZModelLanguage);
104 registerValidationChecks(ZModelLanguage);
105 if (!context.connection) {
106 // We don't run inside a language server
107 // Therefore, initialize the configuration provider instantly
108 shared.workspace.ConfigurationProvider.initialized({});
109 }
110
111 // when documents reach Parsed state, inspect plugin declarations and load corresponding
112 // plugin zmodel docs
113 // Note we must use `onBuildPhase` instead of `onDocumentPhase` here because the latter is
114 // not called when not running inside a language server.
115 shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Parsed, async (documents) => {
116 for (const doc of documents) {
117 if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) {
118 // balk if there are lexer or parser errors
119 continue;
120 }
121
122 if (doc.uri.scheme !== 'file') {
123 continue;
124 }
125
126 const schemaPath = fileURLToPath(doc.uri.toString());
127 const pluginSchemas = getPluginDocuments(doc.parseResult.value as Model, schemaPath);
128
129 // ensure plugin docs are loaded
130 for (const plugin of pluginSchemas) {
131 const pluginDocUri = URI.file(path.resolve(plugin));
132 let pluginDoc = shared.workspace.LangiumDocuments.getDocument(pluginDocUri);
133 if (!pluginDoc) {
134 pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(pluginDocUri);
135 if (pluginDoc) {
136 // add to indexer so the plugin model's definitions are globally visible
137 shared.workspace.IndexManager.updateContent(pluginDoc);
138 if (logToConsole) {
139 console.log(`Loaded plugin model: ${plugin}`);
140 }
141 }
142 }
143 }
144 }
145 });
146
147 return { shared, ZModelLanguage };
148}
149
150// TODO: proper logging system
151export function createZModelServices(logToConsole = false) {

Callers 2

main.tsFile · 0.90
createZModelServicesFunction · 0.85

Calls 5

registerValidationChecksFunction · 0.90
getPluginDocumentsFunction · 0.90
resolveMethod · 0.80
logMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected