fix(ui): offload UnifiedDiffParser.Parse off the UI thread in DiffViewerViewModel
Both call sites (LoadFilesAsync, OnDisplayedDiffChanged) ran the parser synchronously on the dispatcher, freezing the window on a large diff. The Files-mode parse+tree-build now runs via Task.Run behind a ParseOp OperationStatus wired to the toolbar; the planning-mode parse is fire-and-forget with a generation counter so a fast second DisplayedDiff change can't write stale PlanningFiles.
This commit is contained in:
@@ -140,6 +140,33 @@ public class DiffViewerViewModelTests
|
||||
Assert.Equal("DIFF-B", vm.DisplayedDiff);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Planning_SelectSubtask_PopulatesPlanningFilesAsync()
|
||||
{
|
||||
const string diff = "diff --git a/foo.cs b/foo.cs\n" +
|
||||
"--- a/foo.cs\n" +
|
||||
"+++ b/foo.cs\n" +
|
||||
"@@ -1,1 +1,1 @@\n" +
|
||||
"-old\n" +
|
||||
"+new\n";
|
||||
var fake = new FakePlanningWorker
|
||||
{
|
||||
AggregateResult = new[] { new SubtaskDiffDto("s1", "First", "b1", "base1", "head1", null, diff) }
|
||||
};
|
||||
var vm = new DiffViewerViewModel(null!, fake, TestSettings());
|
||||
vm.ConfigurePlanning("plan-1", "main");
|
||||
|
||||
await vm.LoadAsync();
|
||||
|
||||
// OnDisplayedDiffChanged offloads the parse via Task.Run and writes PlanningFiles back
|
||||
// fire-and-forget, so it may not have landed yet when LoadAsync returns.
|
||||
var deadline = DateTime.UtcNow.AddSeconds(5);
|
||||
while (DateTime.UtcNow < deadline && vm.PlanningFiles.Count == 0) await Task.Delay(10);
|
||||
|
||||
var file = Assert.Single(vm.PlanningFiles);
|
||||
Assert.Equal("foo.cs", file.Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Planning_ToggleCombined_Success_DisplaysUnifiedDiff()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user