-
Notifications
You must be signed in to change notification settings - Fork 35
/
user-validator.ts
28 lines (27 loc) · 1.52 KB
/
user-validator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { AstNode, AstNodeDescription, AstUtils, DefaultDocumentValidator, DefaultLinker, DiagnosticInfo, DocumentState, DocumentValidator, LangiumDocument, LinkingError, LinkingErrorData, ReferenceInfo, ValidationOptions } from "langium";
import { LangiumServices } from "langium/lsp";
import { Diagnostic } from "vscode-languageserver";
export class PlaygroundValidator extends DefaultDocumentValidator {
constructor(services: LangiumServices) {
super(services);
}
protected override processLinkingErrors(document: LangiumDocument, diagnostics: Diagnostic[], _options: ValidationOptions): void {
for (const reference of document.references) {
const linkingError = reference.error;
if (linkingError) {
const info: DiagnosticInfo<AstNode, string> = {
node: linkingError.container,
property: linkingError.property,
index: linkingError.index,
data: {
code: DocumentValidator.LinkingError,
containerType: linkingError.container.$type,
property: linkingError.property,
refText: linkingError.reference.$refText
} satisfies LinkingErrorData
};
diagnostics.push(this.toDiagnostic('warning', `${linkingError.message}\nIn case you want to adjust the linking rules, please consult the learning section in the Langium documentation.`, info));
}
}
}
};