public DefaultRazorBreakpointResolver(
            FileUriProvider fileUriProvider,
            LSPDocumentManager documentManager,
            LSPBreakpointSpanProvider breakpointSpanProvider)
        {
            if (fileUriProvider is null)
            {
                throw new ArgumentNullException(nameof(fileUriProvider));
            }

            if (documentManager is null)
            {
                throw new ArgumentNullException(nameof(documentManager));
            }

            if (breakpointSpanProvider is null)
            {
                throw new ArgumentNullException(nameof(breakpointSpanProvider));
            }

            _fileUriProvider        = fileUriProvider;
            _documentManager        = documentManager;
            _breakpointSpanProvider = breakpointSpanProvider;

            // 4 is a magic number that was determined based on the functionality of VisualStudio. Currently when you set or edit a breakpoint
            // we get called with two different locations for the same breakpoint. Because of this 2 time call our size must be at least 2,
            // we grow it to 4 just to be safe for lesser known scenarios.
            _cache = new MemoryCache <CacheKey, Range>(sizeLimit: 4);
        }
Пример #2
0
        private RazorBreakpointResolver CreateResolverWith(
            FileUriProvider uriProvider                  = null,
            LSPDocumentManager documentManager           = null,
            LSPBreakpointSpanProvider projectionProvider = null)
        {
            var documentUri = DocumentUri;

            uriProvider ??= Mock.Of <FileUriProvider>(provider => provider.TryGet(HostTextbuffer, out documentUri) == true && provider.TryGet(It.IsNotIn(HostTextbuffer), out It.Ref <Uri> .IsAny) == false, MockBehavior.Strict);
            var csharpVirtualDocumentSnapshot    = new CSharpVirtualDocumentSnapshot(CSharpDocumentUri, CSharpTextBuffer.CurrentSnapshot, hostDocumentSyncVersion: 0);
            LSPDocumentSnapshot documentSnapshot = new TestLSPDocumentSnapshot(DocumentUri, 0, csharpVirtualDocumentSnapshot);

            documentManager ??= Mock.Of <LSPDocumentManager>(manager => manager.TryGetDocument(DocumentUri, out documentSnapshot) == true, MockBehavior.Strict);
            if (projectionProvider is null)
            {
                projectionProvider = new Mock <LSPBreakpointSpanProvider>(MockBehavior.Strict).Object;
                Mock.Get(projectionProvider).Setup(projectionProvider => projectionProvider.GetBreakpointSpanAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), CancellationToken.None))
                .Returns(Task.FromResult <Range>(null));
            }

            var razorBreakpointResolver = new DefaultRazorBreakpointResolver(uriProvider, documentManager, projectionProvider);

            return(razorBreakpointResolver);
        }