MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / resolveTransitiveImportsInternal

Function resolveTransitiveImportsInternal

packages/language/src/utils.ts:457–482  ·  view source on GitHub ↗
(
    documents: LangiumDocuments,
    model: Model,
    initialModel = model,
    visited: Set<string> = new Set(),
    models: Set<Model> = new Set(),
)

Source from the content-addressed store, hash-verified

455}
456
457function resolveTransitiveImportsInternal(
458 documents: LangiumDocuments,
459 model: Model,
460 initialModel = model,
461 visited: Set<string> = new Set(),
462 models: Set<Model> = new Set(),
463) {
464 const doc = AstUtils.getDocument(model);
465 const initialDoc = AstUtils.getDocument(initialModel);
466
467 if (initialDoc.uri.fsPath.toLowerCase() !== doc.uri.fsPath.toLowerCase()) {
468 models.add(model);
469 }
470
471 const normalizedPath = doc.uri.fsPath.toLowerCase();
472 if (!visited.has(normalizedPath)) {
473 visited.add(normalizedPath);
474 for (const imp of model.imports) {
475 const importedModel = resolveImport(documents, imp);
476 if (importedModel) {
477 resolveTransitiveImportsInternal(documents, importedModel, initialModel, visited, models);
478 }
479 }
480 }
481 return Array.from(models);
482}
483
484/**
485 * Resolves the given import and returns the imported model. Returns `undefined`

Callers 1

resolveTransitiveImportsFunction · 0.85

Calls 1

resolveImportFunction · 0.85

Tested by

no test coverage detected