Exemplo n.º 1
0
        private CompletionList MergeAndPruneCompletionLists(
            IEnumerable <CompletionContext> completionLists, TextSpan contextSpan, bool isExclusive)
        {
            var            displayNameToItemsMap = new Dictionary <string, List <CompletionItem> >();
            CompletionItem suggestionModeItem    = null;

            foreach (var completionList in completionLists)
            {
                Contract.Assert(completionList != null);

                foreach (var item in completionList.Items)
                {
                    Contract.Assert(item != null);
                    AddToDisplayMap(item, displayNameToItemsMap);
                }

                // first one wins
                suggestionModeItem = suggestionModeItem ?? completionList.SuggestionModeItem;
            }

            if (displayNameToItemsMap.Count == 0)
            {
                return(CompletionList.Empty);
            }

            // TODO(DustinCa): Revisit performance of this.
            var totalItems = displayNameToItemsMap.Values.Flatten().ToList();

            totalItems.Sort();

            return(CompletionList.Create(
                       contextSpan, totalItems.ToImmutableArray(), this.GetRules(), suggestionModeItem,
                       isExclusive));
        }
        private CompletionList MergeAndPruneCompletionLists(
            IEnumerable <CompletionContext> completionContexts,
            TextSpan defaultSpan,
            bool isExclusive)
        {
            // See if any contexts changed the completion list span.  If so, the first context that
            // changed it 'wins' and picks the span that will be used for all items in the completion
            // list.  If no contexts changed it, then just use the default span provided by the service.
            var finalCompletionListSpan = completionContexts.FirstOrDefault(c => c.CompletionListSpan != defaultSpan)?.CompletionListSpan ?? defaultSpan;

            var            displayNameToItemsMap = new Dictionary <string, List <CompletionItem> >();
            CompletionItem suggestionModeItem    = null;

            foreach (var context in completionContexts)
            {
                Contract.Assert(context != null);

                foreach (var item in context.Items)
                {
                    Contract.Assert(item != null);
                    AddToDisplayMap(item, displayNameToItemsMap);
                }

                // first one wins
                suggestionModeItem = suggestionModeItem ?? context.SuggestionModeItem;
            }

            if (displayNameToItemsMap.Count == 0)
            {
                return(CompletionList.Empty);
            }

            // TODO(DustinCa): Revisit performance of this.
            var totalItems = displayNameToItemsMap.Values.Flatten().ToList();

            totalItems.Sort();

            return(CompletionList.Create(
                       finalCompletionListSpan,
                       totalItems.ToImmutableArray(),
                       this.GetRules(),
                       suggestionModeItem,
                       isExclusive));
        }