Skip to content

Commit ed27b47

Browse files
jiashengguomarcsigmund
authored andcommitted
feat(language): Allow including partial model in loadDocument when there is error (zenstackhq#2522)
1 parent 11bee44 commit ed27b47

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/language/src/document.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ export async function loadDocument(
3333
fileName: string,
3434
additionalModelFiles: string[] = [],
3535
mergeImports: boolean = true,
36+
returnPartialModelForError: boolean = false,
3637
): Promise<
3738
| { success: true; model: Model; warnings: string[]; services: ZModelServices }
38-
| { success: false; errors: string[]; warnings: string[] }
39+
| { success: false; model?: Model; errors: string[]; warnings: string[] }
3940
> {
4041
const { ZModelLanguage: services } = createZModelServices(false);
4142
const extensions = services.LanguageMetaData.fileExtensions;
@@ -116,6 +117,7 @@ export async function loadDocument(
116117
if (errors.length > 0) {
117118
return {
118119
success: false,
120+
model: returnPartialModelForError ? (document.parseResult.value as Model) : undefined,
119121
errors,
120122
warnings,
121123
};
@@ -139,6 +141,7 @@ export async function loadDocument(
139141
if (additionalErrors.length > 0) {
140142
return {
141143
success: false,
144+
model: returnPartialModelForError ? (document.parseResult.value as Model) : undefined,
142145
errors: additionalErrors,
143146
warnings,
144147
};

0 commit comments

Comments
 (0)