public override Task <ImmutableArray <SymbolDisplayPart> > GetDescriptionAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            var descriptionTask = CompletionItem.GetDescriptionAsync(cancellationToken);

            var updatedDescriptionTask = descriptionTask.SafeContinueWithFromAsync(async task =>
            {
                var parts = task.Result;
                var note  = await _completionService.GetSnippetExpansionNoteForCompletionItemAsync(CompletionItem, _workspace).ConfigureAwait(false);

                if (!string.IsNullOrEmpty(note))
                {
                    if (parts.Any())
                    {
                        parts = parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.LineBreak, null, Environment.NewLine));
                    }

                    parts = parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Text, null, note));
                }

                return(parts);
            },
                                                                                   cancellationToken,
                                                                                   TaskContinuationOptions.OnlyOnRanToCompletion,
                                                                                   TaskScheduler.Default);

            return(updatedDescriptionTask);
        }
Пример #2
0
            public CancellableContentControl(ToolTipProvider toolTipProvider, CompletionItem completionItem)
            {
                Debug.Assert(_foregroundObject.IsForeground());
                _toolTipProvider = toolTipProvider;

                // Set our content to be "..." initially.
                this.Content = toolTipProvider._defaultTextBlock;

                // Kick off the task to produce the new content.  When it completes, call back on
                // the UI thread to update the display.
                var scheduler = TaskScheduler.FromCurrentSynchronizationContext();

                completionItem.GetDescriptionAsync(_cancellationTokenSource.Token)
                .ContinueWith(ProcessDescription, _cancellationTokenSource.Token,
                              TaskContinuationOptions.OnlyOnRanToCompletion, scheduler);

                // If we get unloaded (i.e. the user scrolls down in the completion list and VS
                // dismisses the existing tooltip), then cancel the work we're doing
                this.Unloaded += (s, e) => _cancellationTokenSource.Cancel();
            }