Skip to content

Commit

Permalink
Merge pull request #74595 from CyrusNajmabadi/lastModel
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Jul 30, 2024
2 parents f0228de + 7874c71 commit 1633d21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.CodeAnalysis.Editor;

internal class NavigationBarSelectedTypeAndMember(
internal sealed class NavigationBarSelectedTypeAndMember(
NavigationBarItem? typeItem,
bool showTypeItemGrayed,
NavigationBarItem? memberItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigationBar;

using LastPresentedInfo = (ImmutableArray<NavigationBarProjectItem> projectItems, NavigationBarProjectItem? selectedProjectItem, NavigationBarModel? model, NavigationBarSelectedTypeAndMember selectedInfo);

/// <summary>
/// The controller for navigation bars.
/// </summary>
Expand All @@ -47,7 +49,7 @@ internal partial class NavigationBarController : IDisposable
/// skip doing that as the UI will already know about this. This is only ever read or written from <see
/// cref="_selectItemQueue"/>. So we don't need to worry about any synchronization over it.
/// </summary>
private (ImmutableArray<NavigationBarProjectItem> projectItems, NavigationBarProjectItem? selectedProjectItem, NavigationBarModel? model, NavigationBarSelectedTypeAndMember selectedInfo) _lastPresentedInfo;
private LastPresentedInfo _lastPresentedInfo;

/// <summary>
/// Source of events that should cause us to update the nav bar model with new information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ private async ValueTask SelectItemAsync(ImmutableSegmentedList<int> positions, C
return;

var model = await modelTask.ConfigureAwait(false);

// If we didn't get a new model (which can happen if the work to do it was canceled), use the last one we
// computed. This ensures that we still update the project info if needed, and we don't unintentionally
// clear our the type/member info from the last time we computed it.
model ??= lastPresentedInfo.model;
var currentSelectedItem = ComputeSelectedTypeAndMember(model, lastCaretPosition, cancellationToken);

var (projectItems, selectedProjectItem) = GetProjectItems();
Expand Down

0 comments on commit 1633d21

Please sign in to comment.