From 6ce8db6aa6a55c726257e6fde38ca207a6e93abf Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 6 May 2022 00:59:13 +0200 Subject: [PATCH] Implement `MissingPropertyValidationRule` --- .../validation/MissingPropertyValidation.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 server/src/providers/validation/MissingPropertyValidation.ts diff --git a/server/src/providers/validation/MissingPropertyValidation.ts b/server/src/providers/validation/MissingPropertyValidation.ts new file mode 100644 index 0000000..9302385 --- /dev/null +++ b/server/src/providers/validation/MissingPropertyValidation.ts @@ -0,0 +1,19 @@ +import { Diagnostic, DiagnosticSeverity } from "vscode-languageserver-types"; +import { ValidationContributor, WorkflowDocument } from "../../languageTypes"; + +export class MissingPropertyValidationRule implements ValidationContributor { + constructor(readonly nodePath: string, readonly severity?: DiagnosticSeverity | undefined) {} + + validate(workflowDocument: WorkflowDocument): Promise { + const result: Diagnostic[] = []; + const targetNode = workflowDocument.getNodeFromPath(this.nodePath); + if (!targetNode) { + result.push({ + message: `Property '${this.nodePath}' is missing`, + range: workflowDocument.getDefaultRange(), + severity: this.severity, + }); + } + return Promise.resolve(result); + } +}