예제 #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 = _text.GetDocumentWithFrozenPartialSemantics(cancellationToken);

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

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

                        var suggestionMode = _useSuggestionMode || completionList.SuggestionModeItem != null;
                        return(Model.CreateModel(
                                   _documentOpt,
                                   _disconnectedBufferGraph,
                                   completionList,
                                   useSuggestionMode: suggestionMode,
                                   trigger: _trigger));
                    }
                }