-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playground: Customize linking errors (#230)
* Add warnings instead of errors when linking has failed * Adjust wording
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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)); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters