コード例 #1
0
        /// <summary>
        /// Given a list of completion items that match the current code typed by the user,
        /// returns the item that is considered the best match, and whether or not that
        /// item should be selected or not.
        ///
        /// itemToFilterText provides the values that each individual completion item should
        /// be filtered against.
        /// </summary>
        public virtual ImmutableArray <CompletionItem> FilterItems(
            Document document,
            ImmutableArray <CompletionItem> items,
            string filterText)
        {
            var helper = CompletionHelper.GetHelper(document);

            return(FilterItems(helper, items, filterText));
        }
コード例 #2
0
        internal static ImmutableArray <CompletionItem> FilterItems(
            CompletionHelper completionHelper,
            ImmutableArray <CompletionItem> items,
            string filterText)
        {
            var bestItems = ArrayBuilder <CompletionItem> .GetInstance();

            foreach (var item in items)
            {
                if (bestItems.Count == 0)
                {
                    // We've found no good items yet.  So this is the best item currently.
                    bestItems.Add(item);
                }
                else
                {
                    var comparison = completionHelper.CompareItems(item, bestItems.First(), filterText, CultureInfo.CurrentCulture);
                    if (comparison < 0)
                    {
                        // This item is strictly better than the best items we've found so far.
                        bestItems.Clear();
                        bestItems.Add(item);
                    }
                    else if (comparison == 0)
                    {
                        // This item is as good as the items we've been collecting.  We'll return
                        // it and let the controller decide what to do.  (For example, it will
                        // pick the one that has the best MRU index).
                        bestItems.Add(item);
                    }
                    // otherwise, this item is strictly worse than the ones we've been collecting.
                    // We can just ignore it.
                }
            }

            return(bestItems.ToImmutableAndFree());
        }
コード例 #3
0
 private void CreateInstances()
 {
     this._caseSensitiveInstance   = new CompletionHelper(isCaseSensitive: true);
     this._caseInsensitiveInstance = new CompletionHelper(isCaseSensitive: false);
 }