Exemplo n.º 1
0
        static async Task <CompletionModel> ComputeModelAsync(
            RoslynCompilationWorkspace compilationWorkspace,
            SourceText text,
            int position,
            CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();

            var completions = await compilationWorkspace.CompletionService.GetCompletionsAsync(
                compilationWorkspace.GetSubmissionDocument(text.Container),
                position,
                options : compilationWorkspace.Options,
                cancellationToken : ct).ConfigureAwait(false);

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

            // TODO: Default tracking span
            //var trackingSpan = await _completionService.GetDefaultTrackingSpanAsync(_documentOpt, _subjectBufferCaretPosition, cancellationToken).ConfigureAwait(false);

            return(CompletionModel.CreateModel(
                       text,
                       default(TextSpan),
                       completions.Items));
        }
Exemplo n.º 2
0
        void OnCompletionModelUpdated(CompletionModel model)
        {
            if (model == null)
            {
                StopComputation();
                return;
            }

            if (lastCompletionModel == model)
            {
                return;
            }

            lastCompletionModel = model;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Filter currentCompletionList according to the current filter text. Roslyn's completion does not
        /// handle this automatically.
        /// </summary>
        static async Task <CompletionModel> FilterModelAsync(
            RoslynCompilationWorkspace compilationWorkspace,
            SourceText sourceText,
            CompletionModel model,
            CompletionHelper helper,
            CancellationToken ct)
        {
            if (model == null)
            {
                return(null);
            }

            RoslynCompletionItem bestFilterMatch = null;
            var bestFilterMatchIndex             = 0;

            var document = compilationWorkspace.GetSubmissionDocument(sourceText.Container);
            var newFilteredCompletions = new List <RoslynCompletionItem> ();

            foreach (var item in model.TotalItems)
            {
                var completion = item;
                // TODO: Better range checking on delete before queuing up filtering (see TODO in HandleChange)
                if (completion.Span.Start > sourceText.Length)
                {
                    continue;
                }

                var filterText = GetFilterText(sourceText, completion);

                // CompletionRules.MatchesFilterText seems to always return false when filterText is
                // empty.
                if (filterText != String.Empty && !helper.MatchesPattern(
                        completion.FilterText,
                        filterText,
                        CultureInfo.CurrentCulture))
                {
                    continue;
                }

                var itemDetail = String.Empty;

                var symbols = await SymbolCompletionItem.GetSymbolsAsync(completion, document, ct)
                              .ConfigureAwait(false);

                var overloads = symbols.OfType <IMethodSymbol> ().ToArray();
                if (overloads.Length > 0)
                {
                    itemDetail = overloads [0].ToDisplayString(Constants.SymbolDisplayFormat);

                    if (overloads.Length > 1)
                    {
                        itemDetail += $" (+ {overloads.Length - 1} overload(s))";
                    }
                }

                completion = completion.AddProperty(ItemDetailPropertyName, itemDetail);

                newFilteredCompletions.Add(completion);

                if (bestFilterMatch == null || helper.CompareItems(
                        completion,
                        bestFilterMatch,
                        filterText,
                        CultureInfo.CurrentCulture) > 0)
                {
                    bestFilterMatch      = completion;
                    bestFilterMatchIndex = newFilteredCompletions.Count - 1;
                }
            }

            if (newFilteredCompletions.Count == 0)
            {
                return(null);
            }

            return(model
                   .WithFilteredItems(newFilteredCompletions)
                   .WithSelectedItem(bestFilterMatch, bestFilterMatchIndex)
                   .WithText(sourceText));
        }