73f49eaf32
#1063: the Monaco diagnostics dropped every Roslyn error located in the synthesized wrapper as 'phantom', so CS0161 (not all code paths return a value, pinned on Run) passed the editor and failed the deploy gate. ScriptCompileRules (Core.Scripting) now states which diagnostics refuse (every Error, wherever located; LMX001/002 injection) and which sources skip the compile (blank/passthrough value scripts); ScriptEvaluator and the editor both use it, and the editor wraps with ScriptEvaluator.WrapperPreamble/ WrapperSuffix instead of its own copy. Wrapper-located refusals are drawn on the script's last line. EditorGateParityTests runs one corpus through editor and gate in all three modes. #1065: a Calculation tag is raw/device-level with no equipment and its seam never substitutes {{equip}}, so such a script deployed clean and read Bad forever. Refused rather than substituted: EquipTokenLiteralScanner.FindInCalculation is run by RoslynDeployScriptChecker for every Calculation use (before the passthrough shortcut, outside the shared VT/Calc cache) and by the editor in the new 'calculation' mode (Calculation tag editor; ScriptEdit defaults to it when a Calculation tag uses the script).
71 lines
4.3 KiB
C#
71 lines
4.3 KiB
C#
using ZB.MOM.WW.OtOpcUa.Core.Scripting;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis;
|
|
|
|
/// <summary>
|
|
/// 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
|
|
/// <c>object Run(ScriptGlobals<VirtualTagContext>)</c> (VirtualTag and Calculation share it); a scripted-alarm
|
|
/// predicate is <c>bool Run(ScriptGlobals<AlarmPredicateContext>)</c>. A Calculation script compiles as a value
|
|
/// script but is held to one more gate rule — no <c>{{equip}}</c> token (lmxopcua#1065) — so it has its own mode.
|
|
/// Carried as a string on the wire; null, blank or anything unrecognised means <see cref="Value"/>.
|
|
/// </summary>
|
|
public static class ScriptAnalysisModes
|
|
{
|
|
/// <summary>A VirtualTag value script (the default).</summary>
|
|
public const string Value = "value";
|
|
|
|
/// <summary>A scripted-alarm predicate: must return <c>bool</c>.</summary>
|
|
public const string AlarmPredicate = "alarmPredicate";
|
|
|
|
/// <summary>A Calculation-tag script: the value shape, plus the Calculation-only refusal of <c>{{equip}}</c>.</summary>
|
|
public const string Calculation = "calculation";
|
|
|
|
/// <summary>True when <paramref name="mode"/> selects the predicate shape.</summary>
|
|
/// <param name="mode">The wire value.</param>
|
|
/// <returns>Whether it names <see cref="AlarmPredicate"/>.</returns>
|
|
public static bool IsPredicate(string? mode) => string.Equals(mode, AlarmPredicate, StringComparison.OrdinalIgnoreCase);
|
|
|
|
/// <summary>True when <paramref name="mode"/> selects the Calculation rules.</summary>
|
|
/// <param name="mode">The wire value.</param>
|
|
/// <returns>Whether it names <see cref="Calculation"/>.</returns>
|
|
public static bool IsCalculation(string? mode) => string.Equals(mode, Calculation, StringComparison.OrdinalIgnoreCase);
|
|
|
|
/// <summary>The deploy-gate seam a mode analyses as — what the gate's checker is asked for the same script.</summary>
|
|
/// <param name="mode">The wire value.</param>
|
|
/// <returns>The seam.</returns>
|
|
public static ScriptContextKind KindOf(string? mode) =>
|
|
IsPredicate(mode) ? ScriptContextKind.AlarmPredicate
|
|
: IsCalculation(mode) ? ScriptContextKind.Calculation
|
|
: ScriptContextKind.VirtualTag;
|
|
|
|
/// <summary>The canonical wire value for <paramref name="mode"/> (unrecognised means <see cref="Value"/>).</summary>
|
|
/// <param name="mode">The wire value.</param>
|
|
/// <returns>One of the three constants.</returns>
|
|
public static string Normalize(string? mode) =>
|
|
IsPredicate(mode) ? AlarmPredicate : IsCalculation(mode) ? Calculation : Value;
|
|
}
|
|
|
|
// EquipmentId (optional) carries the owning-equipment context the {{equip}}/<RefName> 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<DiagnosticMarker> 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<CompletionItem> 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<SignatureHelpParameter>? Parameters, int ActiveParameter);
|
|
public record SignatureHelpParameter(string Label, string? Documentation);
|
|
|
|
public record FormatRequest(string Code);
|
|
public record FormatResponse(string Code);
|