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));
        }
Example #2
0
        private static void AsserIsMatch(CompletionModel completionModel, string keyword)
        {
            var item = completionModel.Items.Single(i => i.InsertionText == keyword);

            Assert.Equal(Glyph.Keyword, item.Glyph);
            Assert.Equal(keyword, item.DisplayText);
            Assert.Equal(null, item.Description);
            Assert.Equal(null, item.Symbol);
        }
Example #3
0
        private void UpdateModel(CompletionModel model)
        {
            ApplicableTo = ToTrackingSpan(model.ApplicableSpan);

            var builders = model.Items.Where(item => item.IsBuilder);

            UpdateBuilders(builders);

            var completions = model.Items.Where(item1 => !item1.IsBuilder);

            UpdateCompletions(completions);
        }
        void OnCompletionModelUpdated(CompletionModel model)
        {
            if (model == null)
            {
                StopComputation();
                return;
            }

            if (lastCompletionModel == model)
            {
                return;
            }

            lastCompletionModel = model;
        }
        static dynamic ToMonacoCompletionItems(XCB.ScriptContext context, CompletionModel model)
        {
            dynamic arr = context.CreateArray();

            var filteredCompletions = model?.FilteredItems;

            if (filteredCompletions == null || filteredCompletions.Count == 0)
            {
                return(arr);
            }

            foreach (var completion in filteredCompletions)
            {
                if (completion.Span.End > model.Text.Length)
                {
                    continue;
                }

                var displayText = completion.ToString();

                // Check for the property added by the internal SymbolCompletionItem helper
                string insertionText;
                completion.Properties.TryGetValue("InsertionText", out insertionText);

                // Check for the property added by us during filtering
                string itemDetail;
                completion.Properties.TryGetValue(itemDetailPropertyName, out itemDetail);

                arr.push(context.CreateObject(o => {
                    o.label = displayText;
                    if (itemDetail != null)
                    {
                        o.detail = itemDetail;
                    }
                    if (insertionText != null)
                    {
                        o.insertText = insertionText;
                    }
                    o.kind = MonacoExtensions.ToMonacoCompletionItemKind(completion.Tags);
                }));
            }

            return(arr);
        }
        /// <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);
            }

            CompletionItem bestFilterMatch      = null;
            var            bestFilterMatchIndex = 0;

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

            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].ToMonacoSignatureString();

                    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));
        }