Example #1
0
#pragma warning disable 618
        // Bug #512117: Remove compatibility shims for 2nd gen. Quick Info APIs.
        // ILegacyQuickInfoMetadata should be removed and switched out for IOrderableContentTypeMetadata.
        public AsyncQuickInfoSession(
            IEnumerable <Lazy <IAsyncQuickInfoSourceProvider, IOrderableContentTypeMetadata> > orderedSourceProviders,
            JoinableTaskContext joinableTaskContext,
            ITextView textView,
            ITrackingPoint triggerPoint,
            QuickInfoSessionOptions options,
            PropertyCollection propertyCollection = null)
        {
#pragma warning restore 618
            this.orderedSourceProviders = orderedSourceProviders ?? throw new ArgumentNullException(nameof(orderedSourceProviders));
            this.JoinableTaskContext    = joinableTaskContext ?? throw new ArgumentNullException(nameof(joinableTaskContext));
            this.TextView     = textView ?? throw new ArgumentNullException(nameof(textView));
            this.triggerPoint = triggerPoint ?? throw new ArgumentNullException(nameof(triggerPoint));
            this.Options      = options;

            // Bug #512117: Remove compatibility shims for 2nd gen. Quick Info APIs.
            // We can remove this null check once we remove the legacy APIs.
            this.Properties = propertyCollection ?? new PropertyCollection();

            // Trigger point must be a tracking point on the view's buffer.
            if (triggerPoint.TextBuffer != textView.TextBuffer)
            {
                throw new ArgumentException("The specified ITextSnapshot doesn't belong to the correct TextBuffer");
            }
        }
        public async Task <IAsyncQuickInfoSession> TriggerQuickInfoAsync(
            ITextView textView,
            ITrackingPoint triggerPoint,
            QuickInfoSessionOptions options,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Caret element requires UI thread.
            await this.joinableTaskContext.Factory.SwitchToMainThreadAsync();

            // We switched threads and there is some latency, so ensure that we're still not canceled.
            cancellationToken.ThrowIfCancellationRequested();

            // Dismiss any currently open session.
            var currentSession = this.GetSession(textView);

            if (currentSession != null)
            {
                await currentSession.DismissAsync();
            }

            // Get the trigger point from the caret if none is provided.
            triggerPoint = triggerPoint ?? textView.TextSnapshot.CreateTrackingPoint(
                textView.Caret.Position.BufferPosition,
                PointTrackingMode.Negative);

            var newSession = new AsyncQuickInfoSession(
                this.OrderedSourceProviders,
                this.guardedOperations,
                this.joinableTaskContext,
                this.toolTipService,
                textView,
                triggerPoint,
                options,
                null);

            // StartAsync() is responsible for dispatching a StateChange
            // event if canceled so no need to clean these up on cancellation.
            newSession.StateChanged += this.OnStateChanged;
            textView.Properties.AddProperty(typeof(AsyncQuickInfoSession), newSession);

            try
            {
                await newSession.StartAsync(cancellationToken);
            }
            catch (OperationCanceledException) when(!cancellationToken.IsCancellationRequested)
            {
                // Don't throw OperationCanceledException unless the caller canceled us.
                // This can happen if computation was canceled by a quick info source
                // dismissing the session during computation, which we want to consider
                // more of a 'N/A' than an error.
                return(null);
            }

            return(newSession);
        }
Example #3
0
 public Task <IAsyncQuickInfoSession> TriggerQuickInfoAsync(
     ITextView textView,
     ITrackingPoint triggerPoint,
     QuickInfoSessionOptions options,
     CancellationToken cancellationToken)
 {
     return(this.TriggerQuickInfoAsync(
                textView,
                triggerPoint,
                options,
                null,
                cancellationToken));
 }
Example #4
0
        // Bug #512117: Remove compatibility shims for 2nd gen. Quick Info APIs.
        // This overload exists only to expose additional functionality required
        // by the shims.
        #region ILegacyQuickInfoBrokerSupport

        public async Task <IAsyncQuickInfoSession> TriggerQuickInfoAsync(
            ITextView textView,
            ITrackingPoint triggerPoint,
            QuickInfoSessionOptions options,
            PropertyCollection propertyCollection,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Dismiss any currently open session.
            var currentSession = this.GetSession(textView);

            if (currentSession != null)
            {
                await currentSession.DismissAsync().ConfigureAwait(true);
            }

            triggerPoint = await this.ResolveAndMapUpTriggerPointAsync(textView, triggerPoint, cancellationToken).ConfigureAwait(false);

            if (triggerPoint == null)
            {
                return(null);
            }

            var newSession = new AsyncQuickInfoPresentationSession(
                this.OrderedSourceProviders,
                this.guardedOperations,
                this.joinableTaskContext,
                this.toolTipService,
                textView,
                triggerPoint,
                options,
                propertyCollection);

            // StartAsync() is responsible for dispatching a StateChange
            // event if canceled so no need to clean these up on cancellation.
            newSession.StateChanged += this.OnStateChanged;
            textView.Properties.AddProperty(typeof(AsyncQuickInfoPresentationSession), newSession);

            return(await StartQuickInfoSessionAsync(newSession, cancellationToken).ConfigureAwait(false));
        }
 public Task <IAsyncQuickInfoSession> TriggerQuickInfoAsync(ITextView textView, ITrackingPoint triggerPoint = null, QuickInfoSessionOptions options = QuickInfoSessionOptions.None, CancellationToken cancellationToken = new CancellationToken())
 {
     throw new NotImplementedException();
 }