public async Task <bool> TryNavigateToItemAsync( Document document, NavigationBarItem item, ITextView view, ITextVersion textVersion, CancellationToken cancellationToken) { // Spans.First() is safe here as we filtered out any items with no spans above in ConvertItems. var navigationSpan = item.GetCurrentItemSpan(textVersion, item.Spans.First()); var workspace = document.Project.Solution.Workspace; var navigationService = workspace.Services.GetRequiredService <IDocumentNavigationService>(); return(await navigationService.TryNavigateToPositionAsync( _threadingContext, workspace, document.Id, navigationSpan.Start, virtualSpace : 0, NavigationOptions.Default, cancellationToken).ConfigureAwait(false)); }
public async Task <bool> TryNavigateToItemAsync( Document document, NavigationBarItem item, ITextView view, ITextVersion textVersion, CancellationToken cancellationToken) { // Spans.First() is safe here as we filtered out any items with no spans above in ConvertItems. var navigationSpan = item.GetCurrentItemSpan(textVersion, item.Spans.First()); await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var workspace = document.Project.Solution.Workspace; var navigationService = VSTypeScriptDocumentNavigationServiceWrapper.Create(workspace); navigationService.TryNavigateToPosition( workspace, document.Id, navigationSpan.Start, virtualSpace: 0, options: null, cancellationToken: cancellationToken); return(true); }
internal virtual Task <(DocumentId documentId, int position, int virtualSpace)> GetNavigationLocationAsync( Document document, NavigationBarItem item, SymbolItem symbolItem, ITextVersion textVersion, CancellationToken cancellationToken) { if (symbolItem.Location.InDocumentInfo != null) { // If the item points to a location in this document, then just determine the where that span currently // is (in case recent edits have moved it) and navigate there. var navigationSpan = item.GetCurrentItemSpan(textVersion, symbolItem.Location.InDocumentInfo.Value.navigationSpan); return(Task.FromResult((document.Id, navigationSpan.Start, 0))); } else { // Otherwise, the item pointed to a location in another document. Just return the position we // computed and stored for it. Contract.ThrowIfNull(symbolItem.Location.OtherDocumentInfo); var(documentId, span) = symbolItem.Location.OtherDocumentInfo.Value; return(Task.FromResult((documentId, span.Start, 0))); } }
public async Task <bool> TryNavigateToItemAsync( Document document, NavigationBarItem item, ITextView view, ITextVersion textVersion, CancellationToken cancellationToken) { // The logic here was ported from FSharp's implementation. The main reason was to avoid shimming INotificationService. // Spans.First() is safe here as we filtered down to only items that have spans in ConvertItems. var span = item.GetCurrentItemSpan(textVersion, item.Spans.First()); var workspace = document.Project.Solution.Workspace; var navigationService = workspace.Services.GetRequiredService <IFSharpDocumentNavigationService>(); await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); if (navigationService.CanNavigateToPosition(workspace, document.Id, span.Start, virtualSpace: 0, cancellationToken)) { navigationService.TryNavigateToPosition(workspace, document.Id, span.Start, virtualSpace: 0, cancellationToken); } else { var notificationService = workspace.Services.GetRequiredService <INotificationService>(); notificationService.SendNotification(EditorFeaturesResources.The_definition_of_the_object_is_hidden, severity: NotificationSeverity.Error); } return(true); }