Skip to content

Commit 0d6023e

Browse files
committed
fix: add option to not exclude imports in loadDocument
1 parent 8a9eadd commit 0d6023e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

packages/language/src/document.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import { getDataModelAndTypeDefs, getDocument, hasAttribute, resolveImport, reso
1414
export async function loadDocument(
1515
fileName: string,
1616
additionalModelFiles: string[] = [],
17+
keepImports: boolean = false,
1718
): Promise<
18-
{ success: true; model: Model; warnings: string[], services: ZModelServices } | { success: false; errors: string[]; warnings: string[] }
19+
| { success: true; model: Model; warnings: string[]; services: ZModelServices }
20+
| { success: false; errors: string[]; warnings: string[] }
1921
> {
2022
const { ZModelLanguage: services } = createZModelServices(false);
2123
const extensions = services.LanguageMetaData.fileExtensions;
@@ -103,14 +105,16 @@ export async function loadDocument(
103105

104106
const model = document.parseResult.value as Model;
105107

106-
// merge all declarations into the main document
107-
const imported = mergeImportsDeclarations(langiumDocuments, model);
108+
if (keepImports === false) {
109+
// merge all declarations into the main document
110+
const imported = mergeImportsDeclarations(langiumDocuments, model);
108111

109-
// remove imported documents
110-
imported.forEach((model) => {
111-
langiumDocuments.deleteDocument(model.$document!.uri);
112-
services.shared.workspace.IndexManager.remove(model.$document!.uri);
113-
});
112+
// remove imported documents
113+
imported.forEach((model) => {
114+
langiumDocuments.deleteDocument(model.$document!.uri);
115+
services.shared.workspace.IndexManager.remove(model.$document!.uri);
116+
});
117+
}
114118

115119
// extra validation after merging imported declarations
116120
const additionalErrors = validationAfterImportMerge(model);

0 commit comments

Comments
 (0)