コード例 #1
0
        public void Convert_CommitCharactersTrue_RemovesCommitCharactersFromItems()
        {
            // Arrange
            var commitCharacters = new[] { "<" };
            var completionList   = new VSInternalCompletionList()
            {
                Items = new[]
                {
                    new VSInternalCompletionItem()
                    {
                        Label = "Test",
                        VsCommitCharacters = commitCharacters
                    }
                }
            };
            var capabilities = new VSInternalCompletionSetting()
            {
                CompletionList = new VSInternalCompletionListSetting()
                {
                    CommitCharacters = true,
                }
            };

            // Act
            var vsCompletionList = CompletionListOptimizer.Optimize(completionList, capabilities);

            // Assert
            Assert.Collection(vsCompletionList.Items, (item) => Assert.Null(item.CommitCharacters));

            Assert.Collection(vsCompletionList.CommitCharacters.Value.First, (e) => Assert.Equal("<", e));
        }
コード例 #2
0
        public void Convert_DataFalse_DoesNotTouchData()
        {
            // Arrange
            var dataObject = new JObject()
            {
                ["resultId"] = 123
            };
            var completionList = new VSInternalCompletionList()
            {
                Items = new[]
                {
                    new VSInternalCompletionItem()
                    {
                        Label = "Test",
                        Data  = dataObject,
                    }
                }
            };
            var capabilities = new VSInternalCompletionSetting()
            {
                CompletionList = new VSInternalCompletionListSetting()
                {
                    Data = false,
                }
            };

            // Act
            var vsCompletionList = CompletionListOptimizer.Optimize(completionList, capabilities);

            // Assert
            Assert.Collection(vsCompletionList.Items, item => Assert.Same(dataObject, item.Data));
            Assert.Null(vsCompletionList.Data);
        }
コード例 #3
0
        public void Convert_CommitCharactersFalse_DoesNotTouchCommitCharacters()
        {
            // Arrange
            var commitCharacters = new[] { "<" };
            var completionList   = new VSInternalCompletionList()
            {
                Items = new[]
                {
                    new VSInternalCompletionItem()
                    {
                        Label = "Test",
                        VsCommitCharacters = commitCharacters
                    }
                }
            };
            var capabilities = new VSInternalCompletionSetting()
            {
                CompletionList = new VSInternalCompletionListSetting()
                {
                    CommitCharacters = false,
                }
            };

            // Act
            var vsCompletionList = CompletionListOptimizer.Optimize(completionList, capabilities);

            // Assert
            Assert.Collection(vsCompletionList.Items, item => Assert.Equal(commitCharacters, ((VSInternalCompletionItem)item).VsCommitCharacters));
            Assert.Null(vsCompletionList.CommitCharacters);
        }
コード例 #4
0
        private static VSInternalCompletionList OptimizeData(VSInternalCompletionList completionList, VSInternalCompletionSetting completionCapability)
        {
            var completionListCapability = completionCapability.CompletionList;

            if (completionListCapability?.Data != true)
            {
                return(completionList);
            }

            completionList = PromoteDataOntoList(completionList);

            return(completionList);
        }
コード例 #5
0
        private static VSInternalCompletionList OptimizeCommitCharacters(VSInternalCompletionList completionList, VSInternalCompletionSetting completionCapability)
        {
            var completionListCapability = completionCapability.CompletionList;

            if (completionListCapability?.CommitCharacters != true)
            {
                return(completionList);
            }

            // The commit characters capability is a VS capability with how we utilize it, therefore we want to promote onto the VS list.
            completionList = PromoteVSCommonCommitCharactersOntoList(completionList);
            return(completionList);
        }
コード例 #6
0
        public static VSInternalCompletionList Optimize(VSInternalCompletionList completionList, VSInternalCompletionSetting?completionCapability)
        {
            if (completionCapability is not null)
            {
                completionList = OptimizeCommitCharacters(completionList, completionCapability);
                completionList = OptimizeData(completionList, completionCapability);
            }

            // We wrap the pre-existing completion list with an optimized completion list to better control serialization/deserialization
            var optimizedCompletionList = new OptimizedVSCompletionList(completionList);

            return(optimizedCompletionList);
        }
コード例 #7
0
        private static VSInternalCompletionList PromoteDataOntoList(VSInternalCompletionList completionList)
        {
            // This piece makes a massive assumption that all completion items will have a resultId associated with them and their
            // data properties will all be the same. Therefore, we can inspect the first item and empty out the rest.
            var commonData = completionList.Items.FirstOrDefault()?.Data;

            if (commonData is null)
            {
                // No common data items, nothing to do
                return(completionList);
            }

            foreach (var completionItem in completionList.Items)
            {
                completionItem.Data = null;
            }

            completionList.Data = commonData;
            return(completionList);
        }
コード例 #8
0
        private static VSInternalCompletionList PromoteVSCommonCommitCharactersOntoList(VSInternalCompletionList completionList)
        {
            (AliasedVSCommitCharacters VsCommitCharacters, List <VSInternalCompletionItem> AssociatedCompletionItems)? mostUsedCommitCharacterToItems = null;
            var commitCharacterMap = new Dictionary <AliasedVSCommitCharacters, List <VSInternalCompletionItem> >(AliasedVSCommitCharactersComparer.Instance);

            foreach (var completionItem in completionList.Items)
            {
                if (completionItem is not VSInternalCompletionItem vsCompletionItem)
                {
                    continue;
                }

                var vsCommitCharactersHolder = vsCompletionItem.VsCommitCharacters;
                if (vsCommitCharactersHolder is null)
                {
                    continue;
                }

                var commitCharacters = vsCommitCharactersHolder.Value;
                if (!commitCharacterMap.TryGetValue(commitCharacters, out var associatedCompletionItems))
                {
                    associatedCompletionItems            = new List <VSInternalCompletionItem>();
                    commitCharacterMap[commitCharacters] = associatedCompletionItems;
                }

                associatedCompletionItems.Add(vsCompletionItem);

                if (mostUsedCommitCharacterToItems is null ||
                    associatedCompletionItems.Count > mostUsedCommitCharacterToItems.Value.AssociatedCompletionItems.Count)
                {
                    mostUsedCommitCharacterToItems = (commitCharacters, associatedCompletionItems);
                }
            }

            if (mostUsedCommitCharacterToItems is null)
            {
                return(completionList);
            }

            // Promote the most used commit characters onto the list and remove duplicates from child items.
            foreach (var completionItem in mostUsedCommitCharacterToItems.Value.AssociatedCompletionItems)
            {
                // Clear out the commit characters for all associated items
                completionItem.CommitCharacters   = null;
                completionItem.VsCommitCharacters = null;
            }

            completionList.CommitCharacters = mostUsedCommitCharacterToItems.Value.VsCommitCharacters;
            return(completionList);
        }