コード例 #1
0
        // Internal for testing
        internal static bool TryConvert(RazorCompletionItem razorCompletionItem, out CompletionItem completionItem)
        {
            switch (razorCompletionItem.Kind)
            {
            case RazorCompletionItemKind.Directive:
            {
                // There's not a lot of calculation needed for Directives, go ahead and store the documentation/detail
                // on the completion item.
                var descriptionInfo         = razorCompletionItem.GetDirectiveCompletionDescription();
                var directiveCompletionItem = new CompletionItem()
                {
                    Label         = razorCompletionItem.DisplayText,
                    InsertText    = razorCompletionItem.InsertText,
                    FilterText    = razorCompletionItem.DisplayText,
                    SortText      = razorCompletionItem.DisplayText,
                    Detail        = descriptionInfo.Description,
                    Documentation = descriptionInfo.Description,
                    Kind          = CompletionItemKind.Struct,
                };

                if (razorCompletionItem == DirectiveAttributeTransitionCompletionItemProvider.TransitionCompletionItem)
                {
                    directiveCompletionItem.Command   = RetriggerCompletionCommand;
                    directiveCompletionItem.Kind      = CompletionItemKind.TypeParameter;
                    directiveCompletionItem.Preselect = true;
                }

                directiveCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind);
                completionItem = directiveCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.DirectiveAttribute:
            {
                var descriptionInfo = razorCompletionItem.GetAttributeCompletionDescription();

                var directiveAttributeCompletionItem = new CompletionItem()
                {
                    Label      = razorCompletionItem.DisplayText,
                    InsertText = razorCompletionItem.InsertText,
                    FilterText = razorCompletionItem.InsertText,
                    SortText   = razorCompletionItem.InsertText,
                    Kind       = CompletionItemKind.TypeParameter,
                };

                var indexerCompletion = razorCompletionItem.DisplayText.EndsWith("...");
                if (TryResolveDirectiveAttributeInsertionSnippet(razorCompletionItem.InsertText, indexerCompletion, descriptionInfo, out var snippetText))
                {
                    directiveAttributeCompletionItem.InsertText       = snippetText;
                    directiveAttributeCompletionItem.InsertTextFormat = InsertTextFormat.Snippet;
                }

                directiveAttributeCompletionItem.SetDescriptionInfo(descriptionInfo);
                directiveAttributeCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind);
                completionItem = directiveAttributeCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.DirectiveAttributeParameter:
            {
                var descriptionInfo         = razorCompletionItem.GetAttributeCompletionDescription();
                var parameterCompletionItem = new CompletionItem()
                {
                    Label      = razorCompletionItem.DisplayText,
                    InsertText = razorCompletionItem.InsertText,
                    FilterText = razorCompletionItem.InsertText,
                    SortText   = razorCompletionItem.InsertText,
                    Kind       = CompletionItemKind.TypeParameter,
                };

                parameterCompletionItem.SetDescriptionInfo(descriptionInfo);
                parameterCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind);
                completionItem = parameterCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.MarkupTransition:
            {
                var descriptionInfo = razorCompletionItem.GetMarkupTransitionCompletionDescription();
                var markupTransitionCompletionItem = new CompletionItem()
                {
                    Label            = razorCompletionItem.DisplayText,
                    InsertText       = razorCompletionItem.InsertText,
                    FilterText       = razorCompletionItem.DisplayText,
                    SortText         = razorCompletionItem.DisplayText,
                    Detail           = descriptionInfo.Description,
                    Documentation    = descriptionInfo.Description,
                    Kind             = CompletionItemKind.TypeParameter,
                    CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters)
                };

                completionItem = markupTransitionCompletionItem;
                return(true);
            }
            }

            completionItem = null;
            return(false);
        }
コード例 #2
0
        // Internal for testing
        internal static bool TryConvert(RazorCompletionItem razorCompletionItem, out CompletionItem completionItem)
        {
            if (razorCompletionItem is null)
            {
                throw new ArgumentNullException(nameof(razorCompletionItem));
            }

            switch (razorCompletionItem.Kind)
            {
            case RazorCompletionItemKind.Directive:
            {
                // There's not a lot of calculation needed for Directives, go ahead and store the documentation
                // on the completion item.
                var descriptionInfo         = razorCompletionItem.GetDirectiveCompletionDescription();
                var directiveCompletionItem = new VSLspCompletionItem()
                {
                    Label         = razorCompletionItem.DisplayText,
                    InsertText    = razorCompletionItem.InsertText,
                    FilterText    = razorCompletionItem.DisplayText,
                    SortText      = razorCompletionItem.DisplayText,
                    Documentation = descriptionInfo.Description,
                    Kind          = CompletionItemKind.Struct,
                };

                if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0)
                {
                    directiveCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters);
                }

                if (razorCompletionItem == DirectiveAttributeTransitionCompletionItemProvider.TransitionCompletionItem)
                {
                    directiveCompletionItem.Command = RetriggerCompletionCommand;
                    directiveCompletionItem.Kind    = CompletionItemKind.TypeParameter;
                    directiveCompletionItem.Icon    = VSLspCompletionItemIcons.TagHelper;
                }

                directiveCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind);
                completionItem = directiveCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.DirectiveAttribute:
            {
                var descriptionInfo = razorCompletionItem.GetAttributeCompletionDescription();

                var directiveAttributeCompletionItem = new VSLspCompletionItem()
                {
                    Label      = razorCompletionItem.DisplayText,
                    InsertText = razorCompletionItem.InsertText,
                    FilterText = razorCompletionItem.InsertText,
                    SortText   = razorCompletionItem.InsertText,
                    Kind       = CompletionItemKind.TypeParameter,
                    Icon       = VSLspCompletionItemIcons.TagHelper,
                };

                if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0)
                {
                    directiveAttributeCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters);
                }

                directiveAttributeCompletionItem.SetDescriptionInfo(descriptionInfo);
                directiveAttributeCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind);
                completionItem = directiveAttributeCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.DirectiveAttributeParameter:
            {
                var descriptionInfo         = razorCompletionItem.GetAttributeCompletionDescription();
                var parameterCompletionItem = new VSLspCompletionItem()
                {
                    Label      = razorCompletionItem.DisplayText,
                    InsertText = razorCompletionItem.InsertText,
                    FilterText = razorCompletionItem.InsertText,
                    SortText   = razorCompletionItem.InsertText,
                    Kind       = CompletionItemKind.TypeParameter,
                    Icon       = VSLspCompletionItemIcons.TagHelper,
                };

                parameterCompletionItem.SetDescriptionInfo(descriptionInfo);
                parameterCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind);
                completionItem = parameterCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.MarkupTransition:
            {
                var descriptionInfo = razorCompletionItem.GetMarkupTransitionCompletionDescription();
                var markupTransitionCompletionItem = new VSLspCompletionItem()
                {
                    Label         = razorCompletionItem.DisplayText,
                    InsertText    = razorCompletionItem.InsertText,
                    FilterText    = razorCompletionItem.DisplayText,
                    SortText      = razorCompletionItem.DisplayText,
                    Documentation = descriptionInfo.Description,
                    Kind          = CompletionItemKind.TypeParameter,
                    Icon          = VSLspCompletionItemIcons.TagHelper,
                };

                if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0)
                {
                    markupTransitionCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters);
                }

                completionItem = markupTransitionCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.TagHelperElement:
            {
                var tagHelperElementCompletionItem = new VSLspCompletionItem()
                {
                    Label      = razorCompletionItem.DisplayText,
                    InsertText = razorCompletionItem.InsertText,
                    FilterText = razorCompletionItem.InsertText,
                    SortText   = razorCompletionItem.InsertText,
                    Kind       = CompletionItemKind.TypeParameter,
                    Icon       = VSLspCompletionItemIcons.TagHelper,
                };

                if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0)
                {
                    tagHelperElementCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters);
                }

                var descriptionInfo = razorCompletionItem.GetTagHelperElementDescriptionInfo();
                tagHelperElementCompletionItem.SetDescriptionInfo(descriptionInfo);

                completionItem = tagHelperElementCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.TagHelperAttribute:
            {
                var tagHelperAttributeCompletionItem = new VSLspCompletionItem()
                {
                    Label      = razorCompletionItem.DisplayText,
                    InsertText = razorCompletionItem.InsertText,
                    FilterText = razorCompletionItem.InsertText,
                    SortText   = razorCompletionItem.InsertText,
                    Kind       = CompletionItemKind.TypeParameter,
                    Icon       = VSLspCompletionItemIcons.TagHelper,
                };

                if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0)
                {
                    tagHelperAttributeCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters);
                }

                var descriptionInfo = razorCompletionItem.GetTagHelperAttributeDescriptionInfo();
                tagHelperAttributeCompletionItem.SetDescriptionInfo(descriptionInfo);

                completionItem = tagHelperAttributeCompletionItem;
                return(true);
            }
            }

            completionItem = null;
            return(false);
        }