fix(scripting): #1083 a dynamic tag path is an editor error only where the gate refuses it (predicate), a warning in value/Calculation mode; #1093 Calculation-mode {{equip}} hover says it is refused
#1083: OTSCRIPT_DYNPATH was an error in every editor mode while the deploy gate refuses a non-literal tag path only for a scripted-alarm predicate (editor stricter than the gate). Decision: do not make the gate stricter (it would reject configurations that deploy today). ScriptCompileRules now owns the split — RefusesNonLiteralTagPaths(kind) and TagPathFindings(kind, source), each finding carrying Refuses — the gate refuses on exactly those findings and the editor draws them as errors (8) and the rest as warnings (4), whose text says what the path does at runtime (not a declared input: not subscribed, does not re-trigger, reads BadNodeIdUnknown unless also read literally). DependencyRejection gains Kind + MethodName for that wording. EditorGateParityTests carries dynamic / concatenated / interpolated / empty paths in all three modes (14 rows fail with the old always-error severity). #1093: hovering a {{equip}} path literal in Calculation mode showed the VirtualTag "resolves ... when deployed" text, contradicting the OTSCRIPT_EQUIPCALC marker on the same span. It now says the token is refused in a Calculation script and why (no owning equipment, never substituted, the gate refuses it). The {{equip}} hover no longer needs a tag catalog.
This commit is contained in:
@@ -121,8 +121,9 @@ public sealed class ScriptAnalysisService
|
||||
private static string Normalize(string? s) => (s ?? "").Replace("\r\n", "\n").Replace("\r", "\n");
|
||||
|
||||
/// <summary>Returns the markers for what the deploy gate would refuse — the runtime compile's own refusals (one
|
||||
/// shared authority, <see cref="ScriptCompileRules"/>), sandbox-policy violations, disallowed dynamic tag paths and
|
||||
/// the <c>{{equip}}</c> literal rules — plus advisory warnings.</summary>
|
||||
/// shared authority, <see cref="ScriptCompileRules"/>), sandbox-policy violations, dynamic tag paths where the seam
|
||||
/// refuses them (a predicate; a warning elsewhere, lmxopcua#1083) and the <c>{{equip}}</c> literal rules — plus
|
||||
/// advisory warnings.</summary>
|
||||
/// <param name="req">The diagnose request carrying the script source and the analysis mode.</param>
|
||||
/// <param name="ct">The request's cancellation token; a cancelled request throws <see cref="OperationCanceledException"/>.</param>
|
||||
/// <returns>The list of diagnostic markers, empty when the script is clean or analysis fails.</returns>
|
||||
@@ -159,9 +160,12 @@ public sealed class ScriptAnalysisService
|
||||
markers.Add(ToMarker(tree.GetMappedLineSpan(r.Span), 8, r.Message, "OTSCRIPT_FORBIDDEN"));
|
||||
}
|
||||
ct.ThrowIfCancellationRequested();
|
||||
// (3) DependencyExtractor — spans are offsets in the normalized user source; map directly.
|
||||
foreach (var r in DependencyExtractor.Extract(code).Rejections)
|
||||
markers.Add(ToUserMarker(code, r.Span, r.Message, "OTSCRIPT_DYNPATH"));
|
||||
// (3) Non-literal tag paths (DependencyExtractor) — spans are offsets in the normalized user source; map
|
||||
// directly. lmxopcua#1083: an ERROR only where the deploy gate refuses it (a scripted-alarm predicate), a
|
||||
// WARNING in value / Calculation mode, where the script deploys and the path is just not a declared input.
|
||||
// The split is ScriptCompileRules' (Refuses), the same flag the gate refuses on.
|
||||
foreach (var f in ScriptCompileRules.TagPathFindings(kind, code))
|
||||
markers.Add(ToUserMarker(code, f.Span, f.Message, "OTSCRIPT_DYNPATH", f.Refuses ? 8 : 4));
|
||||
if (kind == ScriptContextKind.Calculation)
|
||||
{
|
||||
// (3a) lmxopcua#1065: a Calculation tag has no equipment — {{equip}} in any path literal is refused by the
|
||||
@@ -311,11 +315,11 @@ public sealed class ScriptAnalysisService
|
||||
sev, span.StartLinePosition.Line + 1, span.StartLinePosition.Character + 1,
|
||||
span.EndLinePosition.Line + 1, span.EndLinePosition.Character + 1, msg, code);
|
||||
|
||||
private static DiagnosticMarker ToUserMarker(string userSource, Microsoft.CodeAnalysis.Text.TextSpan span, string msg, string code)
|
||||
private static DiagnosticMarker ToUserMarker(string userSource, Microsoft.CodeAnalysis.Text.TextSpan span, string msg, string code, int severity = 8)
|
||||
{
|
||||
var (sl, sc) = LineCol(userSource, span.Start);
|
||||
var (el, ec) = LineCol(userSource, span.End);
|
||||
return new DiagnosticMarker(8, sl, sc, el, ec, msg, code);
|
||||
return new DiagnosticMarker(severity, sl, sc, el, ec, msg, code);
|
||||
}
|
||||
|
||||
private static (int Line, int Col) LineCol(string code, int offset)
|
||||
@@ -445,6 +449,19 @@ public sealed class ScriptAnalysisService
|
||||
return new CompletionItem(symbol.Name, symbol.Name,
|
||||
symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), kind);
|
||||
}
|
||||
/// <summary>
|
||||
/// The hover for a <c>{{equip}}</c> path literal in a Calculation script (lmxopcua#1093): it says the token is
|
||||
/// refused there and why, matching the <c>OTSCRIPT_EQUIPCALC</c> marker on the same span (lmxopcua#1065).
|
||||
/// </summary>
|
||||
/// <param name="escapedPath">The literal's path, already backtick-escaped for markdown.</param>
|
||||
/// <returns>The hover markdown.</returns>
|
||||
internal static string CalculationEquipHover(string escapedPath) =>
|
||||
$"**`{{{{equip}}}}` is refused in a Calculation script** `{escapedPath}`\n\n" +
|
||||
"A Calculation tag is a raw, device-level tag: it has no owning equipment, so `{{equip}}` has nothing to " +
|
||||
"resolve to, and the Calculation seam never substitutes it. The deploy gate refuses the script " +
|
||||
"(`equip token in a Calculation script`). Read the source by its literal RawPath instead; " +
|
||||
"`{{equip}}/<RefName>` is for VirtualTags, which belong to an equipment.";
|
||||
|
||||
/// <summary>Computes hover information (tag-path info or C# symbol info) for the position under the caret.</summary>
|
||||
/// <param name="req">The hover request carrying the script source and caret position.</param>
|
||||
/// <param name="ct">The request's cancellation token; a cancelled request throws <see cref="OperationCanceledException"/>.</param>
|
||||
@@ -463,21 +480,27 @@ public sealed class ScriptAnalysisService
|
||||
// Tag-path hover takes priority over C# symbol resolution: when the caret sits on a
|
||||
// ctx.GetTag("…")/ctx.SetVirtualTag("…") path literal, show the resolved tag's info
|
||||
// (or note it's not a known configured tag path) instead of the string-literal symbol.
|
||||
if (_catalog is not null && TryGetTagPathLiteral(token, out var tagPath, out var isSetVirtualTag) && !string.IsNullOrEmpty(tagPath))
|
||||
if (TryGetTagPathLiteral(token, out var tagPath, out var isSetVirtualTag) && !string.IsNullOrEmpty(tagPath)
|
||||
&& (_catalog is not null || tagPath.Contains(EquipmentScriptPaths.EquipToken, StringComparison.Ordinal)))
|
||||
{
|
||||
static string Code(string s) => s.Replace("`", "\\`");
|
||||
// Equipment-relative literal (contains the {{equip}} token): it cannot resolve to a
|
||||
// configured path as-typed (the token is only substituted at deploy), so short-circuit
|
||||
// before GetTagInfoAsync and explain the token instead of warning "not a known path".
|
||||
// Needs no catalog, so it is answered even where none is wired.
|
||||
if (tagPath.Contains(EquipmentScriptPaths.EquipToken, StringComparison.Ordinal))
|
||||
{
|
||||
// lmxopcua#1093: in a Calculation script the token is refused (OTSCRIPT_EQUIPCALC, #1065), so the
|
||||
// VirtualTag explanation ("resolves … when deployed") would contradict the marker on the same span.
|
||||
if (ScriptAnalysisModes.KindOf(req.Mode) == ScriptContextKind.Calculation)
|
||||
return new HoverResponse(CalculationEquipHover(Code(tagPath)));
|
||||
return new HoverResponse(
|
||||
$"**Equipment-relative path** `{Code(tagPath)}`\n\n" +
|
||||
"`{{equip}}/<RefName>` resolves through the owning equipment's tag reference " +
|
||||
"(by effective name) to the backing raw tag's path when the VirtualTag is deployed.");
|
||||
}
|
||||
|
||||
var info = await _catalog.GetTagInfoAsync(tagPath, ct);
|
||||
var info = await _catalog!.GetTagInfoAsync(tagPath, ct);
|
||||
var tagMd = info is null
|
||||
? $"**Tag path** `{Code(tagPath)}`\n\n⚠ Not a known configured tag path."
|
||||
: $"**Tag path** `{Code(info.Path)}`\n\n{info.Kind} · Type **{info.DataType}**"
|
||||
|
||||
Reference in New Issue
Block a user