예제 #1
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);
        }
        // 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:
            {
                var directiveCompletionItem = new VSLspCompletionItem()
                {
                    Label      = razorCompletionItem.DisplayText,
                    InsertText = razorCompletionItem.InsertText,
                    FilterText = razorCompletionItem.DisplayText,
                    SortText   = razorCompletionItem.DisplayText,
                    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;
                }

                completionItem = directiveCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.DirectiveAttribute:
            {
                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);
                }

                completionItem = directiveAttributeCompletionItem;
                return(true);
            }

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

                completionItem = parameterCompletionItem;
                return(true);
            }

            case RazorCompletionItemKind.MarkupTransition:
            {
                var markupTransitionCompletionItem = new VSLspCompletionItem()
                {
                    Label      = razorCompletionItem.DisplayText,
                    InsertText = razorCompletionItem.InsertText,
                    FilterText = razorCompletionItem.DisplayText,
                    SortText   = razorCompletionItem.DisplayText,
                    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);
                }

                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);
                }

                completionItem = tagHelperAttributeCompletionItem;
                return(true);
            }
            }

            completionItem = null;
            return(false);
        }