Ejemplo n.º 1
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.
            var navigationSpan = item.TryGetNavigationSpan(textVersion);

            if (navigationSpan != null)
            {
                var span              = navigationSpan.Value;
                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, options: null, cancellationToken);
                }
                else
                {
                    var notificationService = workspace.Services.GetRequiredService <INotificationService>();
                    notificationService.SendNotification(EditorFeaturesResources.The_definition_of_the_object_is_hidden, severity: NotificationSeverity.Error);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public async Task<bool> TryNavigateToItemAsync(
            Document document, NavigationBarItem item, ITextView view, ITextVersion textVersion, CancellationToken cancellationToken)
        {
            var navigationSpan = item.TryGetNavigationSpan(textVersion);
            if (navigationSpan != null)
            {
                await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                var workspace = document.Project.Solution.Workspace;
                var navigationService = VSTypeScriptDocumentNavigationServiceWrapper.Create(workspace);
                navigationService.TryNavigateToPosition(
                    workspace, document.Id, navigationSpan.Value.Start,
                    virtualSpace: 0, options: null, cancellationToken: cancellationToken);
            }

            return true;
        }
Ejemplo n.º 3
0
        internal virtual Task <(DocumentId documentId, int position, int virtualSpace)> GetNavigationLocationAsync(
            Document document,
            NavigationBarItem item,
            SymbolItem symbolItem,
            ITextVersion textVersion,
            CancellationToken cancellationToken)
        {
            // If the item points to a location in this document, then just determine the current location
            // of that item and go directly to it.
            var navigationSpan = item.TryGetNavigationSpan(textVersion);

            if (navigationSpan != null)
            {
                return(Task.FromResult((document.Id, navigationSpan.Value.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)));
            }
        }