using ZB.MOM.WW.OtOpcUa.Core.Scripting; namespace ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis; /// /// Which seam the editor analyses a script as (lmxopcua#1025). The deploy gate compiles each script as the seam that /// uses it, so the editor has to wrap the source the same way: a value script is /// object Run(ScriptGlobals<VirtualTagContext>) (VirtualTag and Calculation share it); a scripted-alarm /// predicate is bool Run(ScriptGlobals<AlarmPredicateContext>). A Calculation script compiles as a value /// script but is held to one more gate rule — no {{equip}} token (lmxopcua#1065) — so it has its own mode. /// Carried as a string on the wire; null, blank or anything unrecognised means . /// public static class ScriptAnalysisModes { /// A VirtualTag value script (the default). public const string Value = "value"; /// A scripted-alarm predicate: must return bool. public const string AlarmPredicate = "alarmPredicate"; /// A Calculation-tag script: the value shape, plus the Calculation-only refusal of {{equip}}. public const string Calculation = "calculation"; /// True when selects the predicate shape. /// The wire value. /// Whether it names . public static bool IsPredicate(string? mode) => string.Equals(mode, AlarmPredicate, StringComparison.OrdinalIgnoreCase); /// True when selects the Calculation rules. /// The wire value. /// Whether it names . public static bool IsCalculation(string? mode) => string.Equals(mode, Calculation, StringComparison.OrdinalIgnoreCase); /// The deploy-gate seam a mode analyses as — what the gate's checker is asked for the same script. /// The wire value. /// The seam. public static ScriptContextKind KindOf(string? mode) => IsPredicate(mode) ? ScriptContextKind.AlarmPredicate : IsCalculation(mode) ? ScriptContextKind.Calculation : ScriptContextKind.VirtualTag; /// The canonical wire value for (unrecognised means ). /// The wire value. /// One of the three constants. public static string Normalize(string? mode) => IsPredicate(mode) ? AlarmPredicate : IsCalculation(mode) ? Calculation : Value; } // EquipmentId (optional) carries the owning-equipment context the {{equip}}/ completion + // diagnostic need to resolve reference effective names. Null on the shared ScriptEdit page (no single // equipment) — the equip-ref features are then inert, matching the deploy gate (which only resolves per // owning equipment). Mode (optional) selects the seam the script is analysed as — see ScriptAnalysisModes. public record DiagnoseRequest(string Code, string? EquipmentId = null, string? Mode = null); public record DiagnoseResponse(IReadOnlyList Markers); public record DiagnosticMarker(int Severity, int StartLineNumber, int StartColumn, int EndLineNumber, int EndColumn, string Message, string Code); public record CompletionsRequest(string CodeText, int Line, int Column, string? EquipmentId = null, string? Mode = null); public record CompletionsResponse(IReadOnlyList Items); public record CompletionItem(string Label, string InsertText, string Detail, string Kind, int InsertTextRules = 0); public record HoverRequest(string CodeText, int Line, int Column, string? EquipmentId = null, string? Mode = null); public record HoverResponse(string? Markdown); public record SignatureHelpRequest(string CodeText, int Line, int Column, string? Mode = null); public record SignatureHelpResponse(string? Label, IReadOnlyList? Parameters, int ActiveParameter); public record SignatureHelpParameter(string Label, string? Documentation); public record FormatRequest(string Code); public record FormatResponse(string Code);