Skip to content

Commit b4586cc

Browse files
committed
fix(language): some references are not resolved; suppress validation on previous errors
1 parent 4837cf5 commit b4586cc

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

packages/language/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ export async function loadDocument(
7070

7171
// build the document together with standard library, plugin modules, and imported documents
7272
await services.shared.workspace.DocumentBuilder.build([stdLib, ...pluginDocs, document, ...importedDocuments], {
73-
validation: true,
73+
validation: {
74+
stopAfterLexingErrors: true,
75+
stopAfterParsingErrors: true,
76+
stopAfterLinkingErrors: true,
77+
},
7478
});
7579

7680
const diagnostics = langiumDocuments.all
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
import { DefaultDocumentBuilder, type BuildOptions, type LangiumDocument } from 'langium';
1+
import { DefaultDocumentBuilder, type LangiumSharedCoreServices } from 'langium';
22

33
export class ZModelDocumentBuilder extends DefaultDocumentBuilder {
4-
override buildDocuments(documents: LangiumDocument[], options: BuildOptions, cancelToken: any): Promise<void> {
5-
return super.buildDocuments(
6-
documents,
7-
{
8-
...options,
9-
validation:
10-
// force overriding validation options
11-
options.validation === false || options.validation === undefined
12-
? options.validation
13-
: {
14-
stopAfterLexingErrors: true,
15-
stopAfterParsingErrors: true,
16-
stopAfterLinkingErrors: true,
17-
},
18-
},
19-
cancelToken,
20-
);
4+
constructor(services: LangiumSharedCoreServices) {
5+
super(services);
6+
7+
// override update build options to skip validation when there are
8+
// errors in the previous stages
9+
let validationOptions = this.updateBuildOptions.validation;
10+
const stopFlags = {
11+
stopAfterLinkingErrors: true,
12+
stopAfterLexingErrors: true,
13+
stopAfterParsingErrors: true,
14+
};
15+
if (validationOptions === true) {
16+
validationOptions = stopFlags;
17+
} else if (typeof validationOptions === 'object') {
18+
validationOptions = { ...validationOptions, ...stopFlags };
19+
}
20+
21+
this.updateBuildOptions = {
22+
...this.updateBuildOptions,
23+
validation: validationOptions,
24+
};
2125
}
2226
}

packages/language/src/zmodel-linker.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
type LinkingError,
1212
type Reference,
1313
interruptAndCheck,
14-
isReference,
1514
} from 'langium';
1615
import { match } from 'ts-pattern';
1716
import {
@@ -495,13 +494,7 @@ export class ZModelLinker extends DefaultLinker {
495494
}
496495

497496
private resolveDefault(node: AstNode, document: LangiumDocument<AstNode>, extraScopes: ScopeProvider[]) {
498-
for (const [property, value] of Object.entries(node)) {
499-
if (!property.startsWith('$')) {
500-
if (isReference(value)) {
501-
this.linkReference(node, property, document, extraScopes);
502-
}
503-
}
504-
}
497+
AstUtils.streamReferences(node).forEach((ref) => this.doLink(ref, document));
505498
for (const child of AstUtils.streamContents(node)) {
506499
this.resolve(child, document, extraScopes);
507500
}

0 commit comments

Comments
 (0)