Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/language/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export async function loadDocument(

// build the document together with standard library, plugin modules, and imported documents
await services.shared.workspace.DocumentBuilder.build([stdLib, ...pluginDocs, document, ...importedDocuments], {
validation: true,
validation: {
stopAfterLexingErrors: true,
stopAfterParsingErrors: true,
stopAfterLinkingErrors: true,
},
});

const diagnostics = langiumDocuments.all
Expand Down
40 changes: 22 additions & 18 deletions packages/language/src/zmodel-document-builder.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { DefaultDocumentBuilder, type BuildOptions, type LangiumDocument } from 'langium';
import { DefaultDocumentBuilder, type LangiumSharedCoreServices } from 'langium';

export class ZModelDocumentBuilder extends DefaultDocumentBuilder {
override buildDocuments(documents: LangiumDocument[], options: BuildOptions, cancelToken: any): Promise<void> {
return super.buildDocuments(
documents,
{
...options,
validation:
// force overriding validation options
options.validation === false || options.validation === undefined
? options.validation
: {
stopAfterLexingErrors: true,
stopAfterParsingErrors: true,
stopAfterLinkingErrors: true,
},
},
cancelToken,
);
constructor(services: LangiumSharedCoreServices) {
super(services);

// override update build options to skip validation when there are
// errors in the previous stages
let validationOptions = this.updateBuildOptions.validation;
const stopFlags = {
stopAfterLinkingErrors: true,
stopAfterLexingErrors: true,
stopAfterParsingErrors: true,
};
if (validationOptions === true) {
validationOptions = stopFlags;
} else if (typeof validationOptions === 'object') {
validationOptions = { ...validationOptions, ...stopFlags };
}

this.updateBuildOptions = {
...this.updateBuildOptions,
validation: validationOptions,
};
}
}
9 changes: 1 addition & 8 deletions packages/language/src/zmodel-linker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
type LinkingError,
type Reference,
interruptAndCheck,
isReference,
} from 'langium';
import { match } from 'ts-pattern';
import {
Expand Down Expand Up @@ -495,13 +494,7 @@ export class ZModelLinker extends DefaultLinker {
}

private resolveDefault(node: AstNode, document: LangiumDocument<AstNode>, extraScopes: ScopeProvider[]) {
for (const [property, value] of Object.entries(node)) {
if (!property.startsWith('$')) {
if (isReference(value)) {
this.linkReference(node, property, document, extraScopes);
}
}
}
AstUtils.streamReferences(node).forEach((ref) => this.doLink(ref, document));
for (const child of AstUtils.streamContents(node)) {
this.resolve(child, document, extraScopes);
}
Expand Down
Loading