Skip to content

Commit d11bde4

Browse files
committed
update
1 parent cf80771 commit d11bde4

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

packages/language/src/module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'langium/lsp';
1010
import { ZModelGeneratedModule, ZModelGeneratedSharedModule, ZModelLanguageMetaData } from './generated/module';
1111
import { ZModelValidator, registerValidationChecks } from './validator';
12+
import { ZModelDocumentBuilder } from './zmodel-document-builder';
1213
import { ZModelLinker } from './zmodel-linker';
1314
import { ZModelScopeComputation, ZModelScopeProvider } from './zmodel-scope';
1415
import { ZModelWorkspaceManager } from './zmodel-workspace-manager';
@@ -49,6 +50,7 @@ export type ZModelSharedServices = LangiumSharedServices;
4950

5051
export const ZModelSharedModule: Module<ZModelSharedServices, DeepPartial<ZModelSharedServices>> = {
5152
workspace: {
53+
DocumentBuilder: (services) => new ZModelDocumentBuilder(services),
5254
WorkspaceManager: (services) => new ZModelWorkspaceManager(services),
5355
},
5456
};

packages/language/src/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ export function getRecursiveBases(
171171
}
172172
seen.add(decl);
173173
decl.mixins.forEach((mixin) => {
174-
const baseDecl = mixin.ref;
174+
// avoid using mixin.ref since this function can be called before linking
175+
const baseDecl = decl.$container.declarations.find(
176+
(d): d is TypeDef => isTypeDef(d) && d.name === mixin.$refText,
177+
);
175178
if (baseDecl) {
176179
if (!includeDelegate && isDelegateModel(baseDecl)) {
177180
return;

packages/language/src/validator.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-unused-expressions */
2-
3-
import type { AstNode, LangiumDocument, ValidationAcceptor, ValidationChecks } from 'langium';
1+
import type { ValidationAcceptor, ValidationChecks } from 'langium';
42
import type {
53
Attribute,
64
DataModel,
@@ -50,54 +48,39 @@ export function registerValidationChecks(services: ZModelServices) {
5048
export class ZModelValidator {
5149
constructor(protected readonly services: ZModelServices) {}
5250

53-
private shouldCheck(node: AstNode) {
54-
let doc: LangiumDocument | undefined;
55-
let currNode: AstNode | undefined = node;
56-
while (currNode) {
57-
if (currNode.$document) {
58-
doc = currNode.$document;
59-
break;
60-
}
61-
currNode = currNode.$container;
62-
}
63-
64-
return doc?.parseResult.lexerErrors.length === 0 && doc?.parseResult.parserErrors.length === 0;
65-
}
66-
6751
checkModel(node: Model, accept: ValidationAcceptor): void {
68-
this.shouldCheck(node) &&
69-
new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
52+
new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
7053
}
7154

7255
checkDataSource(node: DataSource, accept: ValidationAcceptor): void {
73-
this.shouldCheck(node) && new DataSourceValidator().validate(node, accept);
56+
new DataSourceValidator().validate(node, accept);
7457
}
7558

7659
checkDataModel(node: DataModel, accept: ValidationAcceptor): void {
77-
this.shouldCheck(node) && new DataModelValidator().validate(node, accept);
60+
new DataModelValidator().validate(node, accept);
7861
}
7962

8063
checkTypeDef(node: TypeDef, accept: ValidationAcceptor): void {
81-
this.shouldCheck(node) && new TypeDefValidator().validate(node, accept);
64+
new TypeDefValidator().validate(node, accept);
8265
}
8366

8467
checkEnum(node: Enum, accept: ValidationAcceptor): void {
85-
this.shouldCheck(node) && new EnumValidator().validate(node, accept);
68+
new EnumValidator().validate(node, accept);
8669
}
8770

8871
checkAttribute(node: Attribute, accept: ValidationAcceptor): void {
89-
this.shouldCheck(node) && new AttributeValidator().validate(node, accept);
72+
new AttributeValidator().validate(node, accept);
9073
}
9174

9275
checkExpression(node: Expression, accept: ValidationAcceptor): void {
93-
this.shouldCheck(node) && new ExpressionValidator().validate(node, accept);
76+
new ExpressionValidator().validate(node, accept);
9477
}
9578

9679
checkFunctionInvocation(node: InvocationExpr, accept: ValidationAcceptor): void {
97-
this.shouldCheck(node) && new FunctionInvocationValidator().validate(node, accept);
80+
new FunctionInvocationValidator().validate(node, accept);
9881
}
9982

10083
checkFunctionDecl(node: FunctionDecl, accept: ValidationAcceptor): void {
101-
this.shouldCheck(node) && new FunctionDeclValidator().validate(node, accept);
84+
new FunctionDeclValidator().validate(node, accept);
10285
}
10386
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { DefaultDocumentBuilder, type BuildOptions, type LangiumDocument } from 'langium';
2+
3+
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+
);
21+
}
22+
}

0 commit comments

Comments
 (0)