public RazorCompletionResolveEndpointTest()
 {
     LSPTagHelperTooltipFactory   = Mock.Of <LSPTagHelperTooltipFactory>(MockBehavior.Strict);
     VSLSPTagHelperTooltipFactory = Mock.Of <VSLSPTagHelperTooltipFactory>(MockBehavior.Strict);
     CompletionListCache          = new CompletionListCache();
     CompletionCapability         = new VSInternalCompletionSetting()
     {
         CompletionItem = new CompletionItemSetting()
         {
             DocumentationFormat = new[] { MarkupKind.PlainText, MarkupKind.Markdown },
         }
     };
     DefaultClientCapability = new VSInternalClientCapabilities()
     {
         TextDocument = new TextDocumentClientCapabilities()
         {
             Completion = CompletionCapability,
         },
     };
     VSClientCapability = new VSInternalClientCapabilities()
     {
         TextDocument = new TextDocumentClientCapabilities()
         {
             Completion = CompletionCapability,
         },
         SupportsVisualStudioExtensions = true,
     };
 }
        // Internal for benchmarking and testing
        internal static CompletionList CreateLSPCompletionList(
            IReadOnlyList <RazorCompletionItem> razorCompletionItems,
            CompletionListCache completionListCache,
            IReadOnlyList <ExtendedCompletionItemKinds> supportedItemKinds)
        {
            var resultId        = completionListCache.Set(razorCompletionItems);
            var completionItems = new List <CompletionItem>();

            foreach (var razorCompletionItem in razorCompletionItems)
            {
                if (TryConvert(razorCompletionItem, supportedItemKinds, out var completionItem))
                {
                    // The completion items are cached and can be retrieved via this result id to enable the "resolve" completion functionality.
                    completionItem.SetCompletionListResultId(resultId);
                    completionItems.Add(completionItem);
                }
            }

            var completionList = new CompletionList(completionItems, isIncomplete: false);

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

            return(optimizedCompletionList);
        }
Exemple #3
0
        public RazorCompletionEndpointTest()
        {
            // Working around strong naming restriction.
            var tagHelperFactsService      = new DefaultTagHelperFactsService();
            var tagHelperCompletionService = new LanguageServerTagHelperCompletionService(tagHelperFactsService);
            var completionProviders        = new RazorCompletionItemProvider[]
            {
                new DirectiveCompletionItemProvider(),
                new DirectiveAttributeCompletionItemProvider(tagHelperFactsService),
                new DirectiveAttributeParameterCompletionItemProvider(tagHelperFactsService),
                new TagHelperCompletionProvider(tagHelperCompletionService, new DefaultHtmlFactsService(), tagHelperFactsService)
            };

            CompletionFactsService = new DefaultRazorCompletionFactsService(completionProviders);
            CompletionListCache    = new CompletionListCache();
            ClientCapabilities     = new VSInternalClientCapabilities()
            {
                TextDocument = new TextDocumentClientCapabilities()
                {
                    Completion = new VSInternalCompletionSetting()
                    {
                        CompletionItemKind = new CompletionItemKindSetting()
                        {
                            ValueSet = new[] { CompletionItemKind.TagHelper }
                        },
                        CompletionList = new VSInternalCompletionListSetting()
                        {
                            CommitCharacters = true,
                            Data             = true,
                        }
                    }
                }
            };
        }
        public RazorCompletionEndpoint(
            ForegroundDispatcher foregroundDispatcher,
            DocumentResolver documentResolver,
            RazorCompletionFactsService completionFactsService,
            TagHelperTooltipFactory tagHelperTooltipFactory,
            ILoggerFactory loggerFactory)
        {
            if (foregroundDispatcher == null)
            {
                throw new ArgumentNullException(nameof(foregroundDispatcher));
            }

            if (documentResolver == null)
            {
                throw new ArgumentNullException(nameof(documentResolver));
            }

            if (completionFactsService == null)
            {
                throw new ArgumentNullException(nameof(completionFactsService));
            }

            if (tagHelperTooltipFactory == null)
            {
                throw new ArgumentNullException(nameof(tagHelperTooltipFactory));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _foregroundDispatcher    = foregroundDispatcher;
            _documentResolver        = documentResolver;
            _completionFactsService  = completionFactsService;
            _tagHelperTooltipFactory = tagHelperTooltipFactory;
            _logger = loggerFactory.CreateLogger <RazorCompletionEndpoint>();
            _completionListCache = new CompletionListCache();
        }