fix(ui): show ParseOp indicator on the planning-mode diff parse too

ParseOp only covered LoadFilesAsync; OnDisplayedDiffChanged's parse (driven
by ToggleCombinedAsync and OnSelectedSubtaskChanged) had no visible
feedback even though the offload was already correct. Both call sites now
go through one ParseOffUiThreadAsync helper (Begin on the UI thread before
Task.Run, End via `using` regardless of a stale generation), so the
already-visible toolbar indicator covers the planning path without
duplicating the begin/offload/end ceremony.
This commit is contained in:
Mika Kuns
2026-08-12 13:41:05 +02:00
parent 9fc8ed391e
commit f6994f32d5
2 changed files with 98 additions and 10 deletions
@@ -153,6 +153,16 @@ public sealed partial class DiffViewerViewModel : ViewModelBase
public Task LoadAsync(CancellationToken ct = default) =>
Mode == DiffViewerMode.Planning ? LoadPlanningAsync() : LoadFilesAsync(ct);
// Shared by both parse call sites (LoadFilesAsync, ApplyParsedPlanningFilesAsync) so the
// ParseOp begin/offload/end ceremony isn't duplicated. Begin runs synchronously on the UI
// thread (the caller hasn't awaited anything yet), and the `using` guarantees End runs when
// the offloaded parse finishes — even if the caller's own result turns out to be stale.
private async Task<T> ParseOffUiThreadAsync<T>(Func<T> parse, CancellationToken ct = default)
{
using (ParseOp.Begin(Loc.T("ops.diff.parsing")))
return await Task.Run(parse, ct);
}
private async Task LoadFilesAsync(CancellationToken ct)
{
FileTree.Clear();
@@ -187,16 +197,11 @@ public sealed partial class DiffViewerViewModel : ViewModelBase
return;
}
List<DiffFileViewModel> files;
List<DiffTreeNodeViewModel> tree;
using (ParseOp.Begin(Loc.T("ops.diff.parsing")))
var (files, tree) = await ParseOffUiThreadAsync(() =>
{
(files, tree) = await Task.Run(() =>
{
var parsed = UnifiedDiffParser.Parse(raw);
return (parsed, DiffTree.Build(parsed));
}, ct);
}
var parsed = UnifiedDiffParser.Parse(raw);
return (parsed, DiffTree.Build(parsed));
}, ct);
foreach (var node in tree)
FileTree.Add(node);
@@ -285,7 +290,7 @@ public sealed partial class DiffViewerViewModel : ViewModelBase
private async Task ApplyParsedPlanningFilesAsync(string diff, int generation)
{
var files = await Task.Run(() => UnifiedDiffParser.Parse(diff));
var files = await ParseOffUiThreadAsync(() => UnifiedDiffParser.Parse(diff));
if (generation != _planningFilesGeneration) return;
PlanningFiles.Clear();