Ejemplo n.º 1
0
        internal static bool SendEnterThroughToEditor(CompletionRules rules, RoslynCompletionItem item, string textTypedSoFar)
        {
            var rule = item.Rules.EnterKeyRule;

            if (rule == EnterKeyRule.Default)
            {
                rule = rules.DefaultEnterKeyRule;
            }

            switch (rule)
            {
            default:
            case EnterKeyRule.Default:
            case EnterKeyRule.Never:
                return(false);

            case EnterKeyRule.Always:
                return(true);

            case EnterKeyRule.AfterFullyTypedWord:
                // textTypedSoFar is concatenated from individual chars typed.
                // '\n' is the enter char.
                // That is why, there is no need to check for '\r\n'.
                if (textTypedSoFar.LastOrDefault() == '\n')
                {
                    textTypedSoFar = textTypedSoFar.Substring(0, textTypedSoFar.Length - 1);
                }

                return(item.GetEntireDisplayText() == textTypedSoFar);
            }
        }
Ejemplo n.º 2
0
        private VSCompletionItem Convert(
            Document document,
            RoslynCompletionItem roslynItem,
            CompletionService completionService,
            Dictionary <string, AsyncCompletionData.CompletionFilter> filterCache)
        {
            var imageId = roslynItem.Tags.GetFirstGlyph().GetImageId();
            var filters = GetFilters(roslynItem, filterCache);

            // roslynItem generated by providers can contain an insertionText in a property bag.
            // We will not use it but other providers may need it.
            // We actually will calculate the insertion text once again when called TryCommit.
            if (!roslynItem.Properties.TryGetValue(InsertionText, out var insertionText))
            {
                insertionText = roslynItem.DisplayText;
            }

            var supportedPlatforms = SymbolCompletionItem.GetSupportedPlatforms(roslynItem, document.Project.Solution.Workspace);
            var attributeImages    = supportedPlatforms != null ? s_WarningImageAttributeImagesArray : ImmutableArray <ImageElement> .Empty;

            var item = new VSCompletionItem(
                displayText: roslynItem.GetEntireDisplayText(),
                source: this,
                icon: new ImageElement(new ImageId(imageId.Guid, imageId.Id), roslynItem.DisplayText),
                filters: filters,
                suffix: roslynItem.InlineDescription, // InlineDescription will be right-aligned in the selection popup
                insertText: insertionText,
                sortText: roslynItem.SortText,
                filterText: roslynItem.FilterText,
                attributeIcons: attributeImages);

            item.Properties.AddProperty(RoslynItem, roslynItem);
            return(item);
        }
        private void AddToDisplayMap(
            CompletionItem item,
            Dictionary <string, List <CompletionItem> > displayNameToItemsMap)
        {
            var sameNamedItems = displayNameToItemsMap.GetOrAdd(item.GetEntireDisplayText(), s_createList);

            // If two items have the same display text choose which one to keep.
            // If they don't actually match keep both.

            for (int i = 0; i < sameNamedItems.Count; i++)
            {
                var existingItem = sameNamedItems[i];

                Debug.Assert(item.GetEntireDisplayText() == existingItem.GetEntireDisplayText());

                if (ItemsMatch(item, existingItem))
                {
                    sameNamedItems[i] = GetBetterItem(item, existingItem);
                    return;
                }
            }

            sameNamedItems.Add(item);
        }
Ejemplo n.º 4
0
        private VSCompletionItem Convert(
            Document document,
            RoslynCompletionItem roslynItem)
        {
            if (roslynItem.IsCached && s_roslynItemToVsItem.TryGetValue(roslynItem, out var vsItem))
            {
                return(vsItem);
            }

            var imageId = roslynItem.Tags.GetFirstGlyph().GetImageId();
            var filters = GetFilters(roslynItem);

            // roslynItem generated by providers can contain an insertionText in a property bag.
            // We will not use it but other providers may need it.
            // We actually will calculate the insertion text once again when called TryCommit.
            if (!roslynItem.Properties.TryGetValue(InsertionText, out var insertionText))
            {
                insertionText = roslynItem.DisplayText;
            }

            var supportedPlatforms = SymbolCompletionItem.GetSupportedPlatforms(roslynItem, document.Project.Solution.Workspace);
            var attributeImages    = supportedPlatforms != null ? s_WarningImageAttributeImagesArray : ImmutableArray <ImageElement> .Empty;

            var item = new VSCompletionItem(
                displayText: roslynItem.GetEntireDisplayText(),
                source: this,
                icon: new ImageElement(new ImageId(imageId.Guid, imageId.Id), roslynItem.DisplayText),
                filters: filters,
                suffix: roslynItem.InlineDescription, // InlineDescription will be right-aligned in the selection popup
                insertText: insertionText,
                sortText: roslynItem.SortText,
                filterText: roslynItem.FilterText,
                attributeIcons: attributeImages);

            item.Properties.AddProperty(RoslynItem, roslynItem);

            // It doesn't make sense to cache VS item for those Roslyn items created from scratch for each session,
            // since CWT uses object identity for comparison.
            if (roslynItem.IsCached)
            {
                s_roslynItemToVsItem.Add(roslynItem, item);
            }

            return(item);
        }
Ejemplo n.º 5
0
        internal static bool SendEnterThroughToEditor(CompletionRules rules, RoslynCompletionItem item, string textTypedSoFar)
        {
            var rule = item.Rules.EnterKeyRule;

            if (rule == EnterKeyRule.Default)
            {
                rule = rules.DefaultEnterKeyRule;
            }

            switch (rule)
            {
            default:
            case EnterKeyRule.Default:
            case EnterKeyRule.Never:
                return(false);

            case EnterKeyRule.Always:
                return(true);

            case EnterKeyRule.AfterFullyTypedWord:
                return(item.GetEntireDisplayText() == textTypedSoFar);
            }
        }