Skip to content

Only store tracking spans in the editor side of nav bar items#53878

Merged
CyrusNajmabadi merged 4 commits intodotnet:mainfrom
CyrusNajmabadi:singleNavBarSpan
Jun 4, 2021
Merged

Only store tracking spans in the editor side of nav bar items#53878
CyrusNajmabadi merged 4 commits intodotnet:mainfrom
CyrusNajmabadi:singleNavBarSpan

Conversation

@CyrusNajmabadi
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Jun 4, 2021

This is part of a larger refactoring for navbars. The final form will be that a navbar item can store:

  1. teh full (tracking) span(s) in this document that will be used to determine if the item should be selected based on user position.
  2. the (tracking) span in the document to navigate to if the item is selected.
  3. the doc-id + span if the item should cause navigation to another file (for example, in partial cases).

this PR does '1'.

@CyrusNajmabadi CyrusNajmabadi requested a review from dibarbet June 4, 2021 06:10
@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners June 4, 2021 06:10
@ghost ghost added the Area-IDE label Jun 4, 2021
@CyrusNajmabadi CyrusNajmabadi marked this pull request as draft June 4, 2021 06:21
@CyrusNajmabadi CyrusNajmabadi changed the title Only store a single span in nav bar items Only store tracking spans in the editor side of nav bar items Jun 4, 2021

public async Task<IList<NavigationBarItem>?> GetItemsAsync(Document document, CancellationToken cancellationToken)
public async Task<ImmutableArray<NavigationBarItem>> GetItemsAsync(
Document document, ITextSnapshot textSnapshot, CancellationToken cancellationToken)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is the editor portion of the API. it does pass along the textsnaphsot now as the Editor portion returns navbaritems that have tracking spans in them. so this allows us to create those tracking spans at construction time, not some point in the future after. the feature api is of course oblivious to this.

}

public Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView textView, CancellationToken cancellationToken)
public Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView textView, ITextSnapshot textSnapshot, CancellationToken cancellationToken)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

navigation also takes in the text snapshot so we can determine teh locatin of an item at the point that we navigate. However, currently only TS and F# use this. Roslyn always goes back to symbols to navigate. that will be fixed in one of the followup prs coming shortly.

/// Returns <see langword="true"/> if navigation (or generation) happened. <see langword="false"/> otherwise.
/// </summary>
Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken);
Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, ITextSnapshot textSnapshot, CancellationToken cancellationToken);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these apis are EA, so it's fine to change them.

public ImmutableArray<NavigationBarItem> ChildItems { get; }

public ImmutableArray<TextSpan> Spans { get; internal set; }
internal ImmutableArray<ITrackingSpan> TrackingSpans { get; set; } = ImmutableArray<ITrackingSpan>.Empty;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for 'Spans' anymore in the editor api. nothing uses that. ANd TRackingSpans is no longer mutable as it is provided at construction time.

{
var navBarService = document.GetRequiredLanguageService<INavigationBarItemService>();
var snapshot = _subjectBuffer.CurrentSnapshot;
item.Spans = item.TrackingSpans.SelectAsArray(ts => ts.GetSpan(snapshot).Span.ToTextSpan());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how we hackily used to do things.

: this(text, glyph, spans.ToImmutableArrayOrEmpty(), childItems.ToImmutableArrayOrEmpty(), indent, bolded, grayed)
{
}
public ImmutableArray<ITrackingSpan> TrackingSpans { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation on the purpose of these tracking spans would be useful (from the PR this looks to be the spans used to determine which item is selected based on caret location)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. It' in the next PR :)

@CyrusNajmabadi CyrusNajmabadi merged commit 252f621 into dotnet:main Jun 4, 2021
@ghost ghost added this to the Next milestone Jun 4, 2021
@CyrusNajmabadi CyrusNajmabadi deleted the singleNavBarSpan branch June 4, 2021 20:12
@RikkiGibson RikkiGibson modified the milestones: Next, 17.0.P2 Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants