fix(adminui): Monaco text syncs on demand, diagnostics are sequenced, Problems list (D1)

R04:P1 - the editor no longer ships its full text JS->.NET on every keystroke. It reports
at blur, and ScriptEdit / the VirtualTag modal read the authoritative value with
MonacoEditor.GetValueAsync at Save (validation runs after the pull). The Blazor hub's
MaximumReceiveMessageSize is raised from 32 KB to 1 MB. The JS refuses a value that
would not fit instead of sending an oversize frame, and Save surfaces that refusal
rather than persisting stale source.

R04:P9 - diagnostics carry a generation counter and an AbortController. Every edit aborts
the in-flight request, and only the response for the current text is applied.

R04:S2 - the always-empty inlay-hints provider, endpoint, service method and contracts
are removed.

R04:S3 - MarkersChanged is typed (DiagnosticMarker) and feeds a new ScriptProblemsList.
Clicking a problem calls RevealLineAsync. Markers cross to .NET only when a list
subscribes.

Refs #745

Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
Joseph Doherty
2026-10-22 17:38:56 -04:00
parent 8e3bbf91fb
commit da2578833d
14 changed files with 514 additions and 61 deletions
@@ -7,6 +7,7 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Components.Forms
@using ZB.MOM.WW.OtOpcUa.AdminUI.Uns
@using ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis
@inject IUnsTreeService Svc
@if (Visible)
@@ -99,7 +100,9 @@
Editing shared script "<span class="mono">@_scriptName</span>" — used by
@_scriptUsageCount virtual tag(s). Changes affect all of them.
</div>
<MonacoEditor @bind-Value="_scriptSource" Height="300px" EquipmentId="@EquipmentId" />
<MonacoEditor @ref="_scriptEditor" @bind-Value="_scriptSource" Height="300px" EquipmentId="@EquipmentId"
MarkersChanged="OnScriptMarkersChanged" />
<ScriptProblemsList Markers="_scriptMarkers" OnSelect="RevealScriptProblemAsync" />
@if (!string.IsNullOrWhiteSpace(_scriptError))
{
<div class="text-danger small mt-2">@_scriptError</div>
@@ -217,6 +220,24 @@
private bool _scriptSaving;
private bool _scriptSaved;
private string? _scriptError;
private MonacoEditor? _scriptEditor;
private IReadOnlyList<DiagnosticMarker> _scriptMarkers = Array.Empty<DiagnosticMarker>();
private void OnScriptMarkersChanged(IReadOnlyList<DiagnosticMarker> markers) => _scriptMarkers = markers;
private Task RevealScriptProblemAsync(DiagnosticMarker m)
=> _scriptEditor is null ? Task.CompletedTask : _scriptEditor.RevealLineAsync(m.StartLineNumber, m.StartColumn);
// The inline editor reports its text only at blur; pull the authoritative current value before acting on it.
// Returns false (with _scriptError set) when the text could not be read, so nothing stale is saved.
private async Task<bool> PullScriptSourceAsync()
{
if (_scriptEditor is null) return true;
var read = await _scriptEditor.GetValueAsync();
if (!read.Ok) { _scriptError = $"Not saved: {read.Error}"; return false; }
_scriptSource = read.Value!;
return true;
}
// "New script" action state (shown only when no script is bound yet).
private bool _scriptCreating;
@@ -358,8 +379,16 @@
/// Toggles the inline script-source panel. Clears the stale "Script saved." banner when
/// (re)expanding so a collapse/expand cycle doesn't re-show a confirmation from an earlier save.
/// </summary>
private void ToggleScriptPanel()
private async Task ToggleScriptPanel()
{
if (_scriptExpanded)
{
// Collapsing disposes the editor: keep its unsaved text in _scriptSource so re-opening shows it.
// A failed read keeps the panel open (with the error) rather than discarding the edits.
if (!await PullScriptSourceAsync()) return;
_scriptEditor = null;
_scriptMarkers = Array.Empty<DiagnosticMarker>();
}
_scriptExpanded = !_scriptExpanded;
if (_scriptExpanded)
{
@@ -384,6 +413,7 @@
_scriptError = null;
try
{
if (!await PullScriptSourceAsync()) return;
var result = await Svc.UpdateScriptSourceAsync(_form.ScriptId, _scriptSource, _scriptRowVersion);
if (result.Ok)
{