Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DiffEngineTray.Tests/OwnedInlineHostTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public async Task DiscardAllEmptiesTheQueue()
owner.Queue();
owner.Queue(@"c:\repo\OtherTests.cs", 7);

owner.Host.DiscardAll();
owner.Host.DiscardAll(out _);

await Assert.That(owner.Host.List()).IsEmpty();
}
Expand Down
4 changes: 3 additions & 1 deletion src/DiffEngineTray.Tests/StubInlineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public bool AcceptAll(out string? message)
return AcceptAllSucceeds;
}

public void DiscardAll()
public bool DiscardAll(out string? message)
{
message = null;
return true;
}

public void Focus(PendingSnapshot snapshot)
Expand Down
6 changes: 5 additions & 1 deletion src/DiffEngineTray/IInlineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ interface IInlineHost

bool Discard(PendingSnapshot snapshot, out string? message);
bool AcceptAll(out string? message);
void DiscardAll();
/// <summary>
/// False when the queue owner could not be asked, so a caller clearing its own state knows not
/// to.
/// </summary>
bool DiscardAll(out string? message);

/// <summary>
/// Bring the window forward on this item, launching one if there is none.
Expand Down
8 changes: 6 additions & 2 deletions src/DiffEngineTray/OwnedInlineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,12 @@ public bool AcceptAll(out string? message)
}
}

public void DiscardAll() =>
((IQueueOwner) this).DiscardAll();
public bool DiscardAll(out string? message)
{
message = ((IQueueOwner) this).DiscardAll();
// Owned in this process, so there is nobody to fail to reach
return true;
}

public void Focus(PendingSnapshot snapshot) =>
Show(WindowCommand.Focus, snapshot.Key);
Expand Down
18 changes: 15 additions & 3 deletions src/DiffEngineTray/RemoteInlineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ public AcceptOutcome Accept(PendingSnapshot snapshot, out string? message)
: AcceptOutcome.Applied;
}

/// <summary>
/// On <see cref="acceptWait"/>, not the short timeout. Discarding is not a clock driven call
/// - it comes from the menu or a hot key - and the owner answering it may be busy inside
/// InlineApplier, which waits up to ten seconds on its cross process mutex. Half a second
/// turned a busy owner into "The snapshot viewer is not running."
/// </summary>
public bool Discard(PendingSnapshot snapshot, out string? message) =>
Send(ViewerVerb.Discard, snapshot.Key, ViewerClient.ShortTimeout, out message);
Send(ViewerVerb.Discard, snapshot.Key, acceptWait, out message);

/// <summary>
/// True only when the queue is empty afterwards, for the reason <see cref="Accept"/> gives —
Expand All @@ -110,8 +116,14 @@ public bool AcceptAll(out string? message) =>
Send(ViewerVerb.AcceptAll, null, acceptWait, out message) &&
List().Count == 0;

public void DiscardAll() =>
Send(ViewerVerb.DiscardAll, null, ViewerClient.ShortTimeout, out _);
/// <summary>
/// As <see cref="Discard"/>, and the outcome is returned rather than dropped. Discarded on a
/// busy owner used to do nothing at all while Tracker.Clear went ahead and emptied its own
/// snapshot list, so "Discard (n)" reported success and everything reappeared on the next
/// scan two seconds later.
/// </summary>
public bool DiscardAll(out string? message) =>
Send(ViewerVerb.DiscardAll, null, acceptWait, out message);

public void Focus(PendingSnapshot snapshot) =>
Send(ViewerVerb.Focus, snapshot.Key, ViewerClient.ShortTimeout, out _);
Expand Down
13 changes: 11 additions & 2 deletions src/DiffEngineTray/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,17 @@ public void Clear()
{
((ITrackedFiles) this).DiscardAll();

inline.DiscardAll();
snapshots = [];
// Only forget the cached snapshots when the owner actually discarded them. It used to be
// cleared regardless, so a discard the owner never received still emptied the menu - and
// everything came back on the next scan two seconds later
if (inline.DiscardAll(out var message))
{
snapshots = [];
}
else
{
Log.Error(message ?? "Could not discard the pending snapshots.");
}
}

/// <summary>
Expand Down
Loading