Exemple #1
0
                private async Task <Model> DoInBackgroundAsync(CancellationToken cancellationToken)
                {
                    //using (Logger.LogBlock(FunctionId.Completion_ModelComputer_DoInBackground, cancellationToken))
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        if (_completionService == null || _options == null)
                        {
                            // both completionService and options can be null if given buffer is not registered to workspace yet.
                            // could happen in razor more frequently
                            return(null);
                        }

                        // get partial solution from background thread.
                        _documentOpt = await _text.GetDocumentWithFrozenPartialSemanticsAsync(cancellationToken).ConfigureAwait(false);

                        // TODO(cyrusn): We're calling into extensions, we need to make ourselves resilient
                        // to the extension crashing.
                        var completionList = await GetCompletionListAsync(_completionService, _trigger, cancellationToken).ConfigureAwait(false);

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

                        var suggestionMode = _useSuggestionMode || completionList.SuggestionModeItem != null;
                        return(Model.CreateModel(
                                   _documentOpt,
                                   _disconnectedBufferGraph,
                                   completionList,
                                   useSuggestionMode: suggestionMode,
                                   trigger: _trigger));
                    }
                }
                private async Task <Model> DoInBackgroundAsync(CancellationToken cancellationToken)
                {
                    using (Logger.LogBlock(FunctionId.Completion_ModelComputer_DoInBackground, cancellationToken))
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        if (_completionService == null || _options == null)
                        {
                            // both completionService and options can be null if given buffer is not registered to workspace yet.
                            // could happen in razor more frequently
                            return(null);
                        }

                        // get partial solution from background thread.
                        _documentOpt = await _text.GetDocumentWithFrozenPartialSemanticsAsync(cancellationToken).ConfigureAwait(false);

                        // TODO(cyrusn): We're calling into extensions, we need to make ourselves resilient
                        // to the extension crashing.
                        var groups = await GetGroupsAsync(_completionService, _triggerInfo, cancellationToken).ConfigureAwait(false);

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

                        groups.Do(AddGroupToMap);
                        if (_displayNameToItemsMap.Count == 0)
                        {
                            return(null);
                        }

                        var totalItems = _displayNameToItemsMap.Values.Flatten().ToList();
                        totalItems.Sort();

                        var trackingSpan = await _completionService.GetDefaultTrackingSpanAsync(_documentOpt, _subjectBufferCaretPosition, cancellationToken).ConfigureAwait(false);

                        return(Model.CreateModel(
                                   _disconnectedBufferGraph,
                                   trackingSpan,
                                   totalItems,
                                   selectedItem: totalItems.First(),
                                   isHardSelection: false,
                                   isUnique: false,
                                   useSuggestionCompletionMode: _includeBuilder,
                                   builder: _builder,
                                   triggerInfo: _triggerInfo,
                                   completionService: _completionService,
                                   workspace: _documentOpt != null ? _documentOpt.Project.Solution.Workspace : null));
                    }
                }