private DefaultRazorProximityExpressionResolver(
            FileUriProvider fileUriProvider,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            CodeAnalysis.Workspace workspace)
        {
            if (fileUriProvider is null)
            {
                throw new ArgumentNullException(nameof(fileUriProvider));
            }

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

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

            _fileUriProvider    = fileUriProvider;
            _documentManager    = documentManager;
            _projectionProvider = projectionProvider;
            _workspace          = workspace;

            // 10 is a magic number where this effectively represents our ability to cache the last 10 "hit" breakpoint locations
            // corresponding proximity expressions which enables us not to go "async" in those re-hit scenarios.
            _cache = new MemoryCache <CacheKey, IReadOnlyList <string> >(sizeLimit: 10);
        }
Ejemplo n.º 2
0
        private RazorProximityExpressionResolver CreateResolverWith(
            FileUriProvider uriProvider              = null,
            LSPDocumentManager documentManager       = null,
            LSPProjectionProvider 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 <LSPProjectionProvider>(MockBehavior.Strict).Object;
                Mock.Get(projectionProvider).Setup(projectionProvider => projectionProvider.GetProjectionAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), CancellationToken.None))
                .Returns(Task.FromResult <ProjectionResult>(null));
            }
            var razorProximityExpressionResolver = DefaultRazorProximityExpressionResolver.CreateTestInstance(
                uriProvider,
                documentManager,
                projectionProvider);

            return(razorProximityExpressionResolver);
        }
        public DefaultRazorProximityExpressionResolver(
            FileUriProvider fileUriProvider,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            CSharpProximityExpressionResolver csharpProximityExpressionResolver)
        {
            if (fileUriProvider is null)
            {
                throw new ArgumentNullException(nameof(fileUriProvider));
            }

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

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

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

            _fileUriProvider    = fileUriProvider;
            _documentManager    = documentManager;
            _projectionProvider = projectionProvider;
            _csharpProximityExpressionResolver = csharpProximityExpressionResolver;
        }
Ejemplo n.º 4
0
        private RazorBreakpointResolver CreateResolverWith(
            FileUriProvider uriProvider                        = null,
            LSPDocumentManager documentManager                 = null,
            LSPProjectionProvider projectionProvider           = null,
            LSPDocumentMappingProvider documentMappingProvider = null)
        {
            var documentUri = DocumentUri;

            uriProvider ??= Mock.Of <FileUriProvider>(provider => provider.TryGet(HostTextbuffer, out documentUri) == true);
            var csharpDocumentUri                = new Uri(DocumentUri.OriginalString + ".g.cs", UriKind.Absolute);
            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);
            projectionProvider ??= Mock.Of <LSPProjectionProvider>();
            documentMappingProvider ??= Mock.Of <LSPDocumentMappingProvider>();
            var csharpBreakpointResolver = new DefaultCSharpBreakpointResolver();
            var razorBreakpointResolver  = new DefaultRazorBreakpointResolver(
                uriProvider,
                documentManager,
                projectionProvider,
                documentMappingProvider,
                csharpBreakpointResolver);

            return(razorBreakpointResolver);
        }
        private RazorProximityExpressionResolver CreateResolverWith(
            FileUriProvider uriProvider              = null,
            LSPDocumentManager documentManager       = null,
            LSPProjectionProvider 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 csharpDocumentUri                = new Uri(DocumentUri.OriginalString + ".g.cs", UriKind.Absolute);
            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 <LSPProjectionProvider>(MockBehavior.Strict).Object;
                Mock.Get(projectionProvider).Setup(projectionProvider => projectionProvider.GetProjectionAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), CancellationToken.None))
                .Returns(Task.FromResult <ProjectionResult>(null));
            }
            CodeAnalysis.Workspace workspace     = null;
            var workspaceAccessor                = Mock.Of <VisualStudioWorkspaceAccessor>(accessor => accessor.TryGetWorkspace(It.IsAny <ITextBuffer>(), out workspace) == false, MockBehavior.Strict);
            var razorProximityExpressionResolver = new DefaultRazorProximityExpressionResolver(
                uriProvider,
                documentManager,
                projectionProvider,
                workspaceAccessor);

            return(razorProximityExpressionResolver);
        }
 public DefaultRazorProximityExpressionResolver(
     FileUriProvider fileUriProvider,
     LSPDocumentManager documentManager,
     LSPProjectionProvider projectionProvider,
     VisualStudioWorkspace workspace) : this(fileUriProvider, documentManager, projectionProvider, (CodeAnalysis.Workspace)workspace)
 {
     if (workspace is null)
     {
         throw new ArgumentNullException(nameof(workspace));
     }
 }
        public DefaultRazorBreakpointResolver(
            FileUriProvider fileUriProvider,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            LSPDocumentMappingProvider documentMappingProvider,
            VisualStudioWorkspaceAccessor workspaceAccessor)
        {
            if (fileUriProvider is null)
            {
                throw new ArgumentNullException(nameof(fileUriProvider));
            }

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

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

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

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

            _fileUriProvider         = fileUriProvider;
            _documentManager         = documentManager;
            _projectionProvider      = projectionProvider;
            _documentMappingProvider = documentMappingProvider;
            _workspaceAccessor       = workspaceAccessor;

            // 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);
        }
Ejemplo n.º 8
0
        private RazorBreakpointResolver CreateResolverWith(
            FileUriProvider uriProvider                        = null,
            LSPDocumentManager documentManager                 = null,
            LSPProjectionProvider projectionProvider           = null,
            LSPDocumentMappingProvider documentMappingProvider = 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 csharpDocumentUri                = new Uri(DocumentUri.OriginalString + ".g.cs", UriKind.Absolute);
            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 <LSPProjectionProvider>(MockBehavior.Strict).Object;
                Mock.Get(projectionProvider).Setup(projectionProvider => projectionProvider.GetProjectionAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), CancellationToken.None))
                .Returns(Task.FromResult <ProjectionResult>(null));
            }

            if (documentMappingProvider is null)
            {
                documentMappingProvider = new Mock <LSPDocumentMappingProvider>(MockBehavior.Strict).Object;
                Mock.Get(documentMappingProvider).Setup(p => p.MapToDocumentRangesAsync(It.IsAny <RazorLanguageKind>(), It.IsAny <Uri>(), It.IsAny <Range[]>(), CancellationToken.None))
                .Returns(Task.FromResult <RazorMapToDocumentRangesResponse>(null));
            }

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

            return(razorBreakpointResolver);
        }
        public DefaultRazorBreakpointResolver(
            FileUriProvider fileUriProvider,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            LSPDocumentMappingProvider documentMappingProvider,
            CSharpBreakpointResolver csharpBreakpointResolver)
        {
            if (fileUriProvider is null)
            {
                throw new ArgumentNullException(nameof(fileUriProvider));
            }

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

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

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

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

            _fileUriProvider          = fileUriProvider;
            _documentManager          = documentManager;
            _projectionProvider       = projectionProvider;
            _documentMappingProvider  = documentMappingProvider;
            _csharpBreakpointResolver = csharpBreakpointResolver;
        }
 public static DefaultRazorProximityExpressionResolver CreateTestInstance(
     FileUriProvider fileUriProvider,
     LSPDocumentManager documentManager,
     LSPProjectionProvider projectionProvider) => new DefaultRazorProximityExpressionResolver(fileUriProvider, documentManager, projectionProvider, (CodeAnalysis.Workspace)null);
Ejemplo n.º 11
0
 public static DefaultRazorBreakpointResolver CreateTestInstance(
     FileUriProvider fileUriProvider,
     LSPDocumentManager documentManager,
     LSPProjectionProvider projectionProvider,
     LSPDocumentMappingProvider documentMappingProvider) => new(fileUriProvider, documentManager, projectionProvider, documentMappingProvider, (CodeAnalysis.Workspace)null);