public async Task <QuickInfoItemsCollection> GetQuickInfoItemsAsync( ITextView textView, ITrackingPoint triggerPoint, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); triggerPoint = await this.ResolveAndMapUpTriggerPointAsync(textView, triggerPoint, cancellationToken).ConfigureAwait(false); if (triggerPoint != null) { var session = new AsyncQuickInfoSession( this.OrderedSourceProviders, this.joinableTaskContext, textView, triggerPoint, QuickInfoSessionOptions.None); var startedSession = await StartQuickInfoSessionAsync(session, cancellationToken).ConfigureAwait(false); if (startedSession != null) { var results = new QuickInfoItemsCollection(startedSession.Content, startedSession.ApplicableToSpan); await startedSession.DismissAsync().ConfigureAwait(false); return(results); } } return(null); }
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); }
private static async Task <IAsyncQuickInfoSession> StartQuickInfoSessionAsync(AsyncQuickInfoSession session, CancellationToken cancellationToken) { try { await session.UpdateAsync(allowUpdate : false, cancellationToken : cancellationToken).ConfigureAwait(false); } 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(session.State == QuickInfoSessionState.Dismissed ? null : session); }