示例#1
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);
        }
示例#2
0
        public GoToDefinitionHandler(
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            LSPDocumentMappingProvider documentMappingProvider)
        {
            if (requestInvoker is null)
            {
                throw new ArgumentNullException(nameof(requestInvoker));
            }

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

            _requestInvoker          = requestInvoker;
            _documentManager         = documentManager;
            _projectionProvider      = projectionProvider;
            _documentMappingProvider = documentMappingProvider;
        }
        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);
        }
        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 CompletionHandler(
            JoinableTaskContext joinableTaskContext,
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider)
        {
            if (joinableTaskContext is null)
            {
                throw new ArgumentNullException(nameof(joinableTaskContext));
            }

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

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

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

            _joinableTaskFactory = joinableTaskContext.Factory;
            _requestInvoker      = requestInvoker;
            _documentManager     = documentManager;
            _projectionProvider  = projectionProvider;
        }
示例#6
0
        public SignatureHelpHandler(
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            HTMLCSharpLanguageServerLogHubLoggerProvider loggerProvider)
        {
            if (requestInvoker is null)
            {
                throw new ArgumentNullException(nameof(requestInvoker));
            }

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

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

            _requestInvoker     = requestInvoker;
            _documentManager    = documentManager;
            _projectionProvider = projectionProvider;

            _logger = loggerProvider.CreateLogger(nameof(SignatureHelpHandler));
        }
示例#7
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 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);
        }
        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;
        }
        public DocumentPullDiagnosticsHandler(
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPDocumentSynchronizer documentSynchronizer,
            LSPDiagnosticsTranslator diagnosticsProvider)
        {
            if (requestInvoker is null)
            {
                throw new ArgumentNullException(nameof(requestInvoker));
            }

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

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

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

            _requestInvoker       = requestInvoker;
            _documentManager      = documentManager;
            _documentSynchronizer = documentSynchronizer;
            _diagnosticsProvider  = diagnosticsProvider;
        }
        public CompletionHandler(
            JoinableTaskContext joinableTaskContext,
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            ITextStructureNavigatorSelectorService textStructureNavigator,
            CompletionRequestContextCache completionRequestContextCache,
            FormattingOptionsProvider formattingOptionsProvider,
            HTMLCSharpLanguageServerLogHubLoggerProvider loggerProvider)
        {
            if (joinableTaskContext is null)
            {
                throw new ArgumentNullException(nameof(joinableTaskContext));
            }

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

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

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

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

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

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

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

            _joinableTaskFactory           = joinableTaskContext.Factory;
            _requestInvoker                = requestInvoker;
            _documentManager               = documentManager;
            _projectionProvider            = projectionProvider;
            _textStructureNavigator        = textStructureNavigator;
            _completionRequestContextCache = completionRequestContextCache;
            _formattingOptionsProvider     = formattingOptionsProvider;
            _logger = loggerProvider.CreateLogger(nameof(CompletionHandler));
        }
 public DefaultLSPDiagnosticsTranslator(
     LSPDocumentManager documentManager,
     LSPRequestInvoker requestInvoker,
     HTMLCSharpLanguageServerLogHubLoggerProvider loggerProvider)
 {
     _documentManager = documentManager;
     _requestInvoker  = requestInvoker;
     _loggerProvider  = loggerProvider;
 }
 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 TestOnTypeFormattingHandler(
     JoinableTaskContext joinableTaskContext,
     LSPDocumentManager documentManager,
     LSPRequestInvoker requestInvoker,
     LSPProjectionProvider projectionProvider,
     LSPDocumentMappingProvider documentMappingProvider,
     LSPEditorService editorService) : base(
         joinableTaskContext,
         documentManager,
         requestInvoker,
         projectionProvider,
         documentMappingProvider,
         editorService)
 {
 }
示例#15
0
        public CompletionResolveHandler(
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPDocumentMappingProvider documentMappingProvider,
            FormattingOptionsProvider formattingOptionsProvider,
            CompletionRequestContextCache completionRequestContextCache,
            HTMLCSharpLanguageServerLogHubLoggerProvider loggerProvider)
        {
            if (requestInvoker is null)
            {
                throw new ArgumentNullException(nameof(requestInvoker));
            }

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

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

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

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

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

            _requestInvoker                = requestInvoker;
            _documentManager               = documentManager;
            _documentMappingProvider       = documentMappingProvider;
            _formattingOptionsProvider     = formattingOptionsProvider;
            _completionRequestContextCache = completionRequestContextCache;

            _logger = loggerProvider.CreateLogger(nameof(CompletionResolveHandler));
        }
        public FindAllReferencesHandler(
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            LSPDocumentMappingProvider documentMappingProvider,
            LSPProgressListener lspProgressListener,
            HTMLCSharpLanguageServerLogHubLoggerProvider loggerProvider)
        {
            if (requestInvoker is null)
            {
                throw new ArgumentNullException(nameof(requestInvoker));
            }

            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 (lspProgressListener is null)
            {
                throw new ArgumentNullException(nameof(lspProgressListener));
            }

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

            _requestInvoker          = requestInvoker;
            _documentManager         = documentManager;
            _projectionProvider      = projectionProvider;
            _documentMappingProvider = documentMappingProvider;
            _lspProgressListener     = lspProgressListener;

            _logger = loggerProvider.CreateLogger(nameof(FindAllReferencesHandler));
        }
        public OnTypeFormattingHandler(
            JoinableTaskContext joinableTaskContext,
            LSPDocumentManager documentManager,
            LSPRequestInvoker requestInvoker,
            LSPProjectionProvider projectionProvider,
            LSPDocumentMappingProvider documentMappingProvider,
            LSPEditorService editorService)
        {
            if (joinableTaskContext is null)
            {
                throw new ArgumentNullException(nameof(joinableTaskContext));
            }

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

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

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

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

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

            _joinableTaskFactory     = joinableTaskContext.Factory;
            _documentManager         = documentManager;
            _requestInvoker          = requestInvoker;
            _projectionProvider      = projectionProvider;
            _documentMappingProvider = documentMappingProvider;
            _editorService           = editorService;
        }
示例#18
0
        public CompletionHandler(
            JoinableTaskContext joinableTaskContext,
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            ITextStructureNavigatorSelectorService textStructureNavigator,
            CompletionRequestContextCache completionRequestContextCache)
        {
            if (joinableTaskContext is null)
            {
                throw new ArgumentNullException(nameof(joinableTaskContext));
            }

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

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

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

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

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

            _joinableTaskFactory           = joinableTaskContext.Factory;
            _requestInvoker                = requestInvoker;
            _documentManager               = documentManager;
            _projectionProvider            = projectionProvider;
            _textStructureNavigator        = textStructureNavigator;
            _completionRequestContextCache = completionRequestContextCache;
        }
        private RazorProximityExpressionResolver CreateResolverWith(
            FileUriProvider uriProvider        = null,
            LSPDocumentManager documentManager = 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);

            var razorProximityExpressionResolver = new DefaultRazorProximityExpressionResolver(
                uriProvider,
                documentManager,
                TestLSPProximityExpressionProvider.Instance);

            return(razorProximityExpressionResolver);
        }
        public static bool TryGetDocument(this LSPDocumentManager documentManager, string filePath, out LSPDocumentSnapshot lspDocumentSnapshot)
        {
            if (documentManager is null)
            {
                throw new ArgumentNullException(nameof(documentManager));
            }

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

            if (filePath.StartsWith("/", StringComparison.Ordinal) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                filePath = filePath.Substring(1);
            }

            var uri = new Uri(filePath, UriKind.Absolute);

            return(documentManager.TryGetDocument(uri, out lspDocumentSnapshot));
        }
        public DocumentPullDiagnosticsHandler(
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPDocumentSynchronizer documentSynchronizer,
            LSPDiagnosticsTranslator diagnosticsProvider,
            HTMLCSharpLanguageServerLogHubLoggerProvider loggerProvider)
        {
            if (requestInvoker is null)
            {
                throw new ArgumentNullException(nameof(requestInvoker));
            }

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

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

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

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

            _requestInvoker       = requestInvoker;
            _documentManager      = documentManager;
            _documentSynchronizer = documentSynchronizer;
            _diagnosticsProvider  = diagnosticsProvider;

            _logger = loggerProvider.CreateLogger(nameof(DocumentPullDiagnosticsHandler));
        }
示例#22
0
        public FindAllReferencesHandler(
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider,
            LSPDocumentMappingProvider documentMappingProvider,
            LSPProgressListener lspProgressListener)
        {
            if (requestInvoker is null)
            {
                throw new ArgumentNullException(nameof(requestInvoker));
            }

            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 (lspProgressListener is null)
            {
                throw new ArgumentNullException(nameof(lspProgressListener));
            }

            _requestInvoker          = requestInvoker;
            _documentManager         = documentManager;
            _projectionProvider      = projectionProvider;
            _documentMappingProvider = documentMappingProvider;
            _lspProgressListener     = lspProgressListener;
        }
        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;
        }
示例#24
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);
        }
示例#25
0
        public SignatureHelpHandler(
            LSPRequestInvoker requestInvoker,
            LSPDocumentManager documentManager,
            LSPProjectionProvider projectionProvider)
        {
            if (requestInvoker is null)
            {
                throw new ArgumentNullException(nameof(requestInvoker));
            }

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

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

            _requestInvoker     = requestInvoker;
            _documentManager    = documentManager;
            _projectionProvider = projectionProvider;
        }
 public static DefaultRazorProximityExpressionResolver CreateTestInstance(
     FileUriProvider fileUriProvider,
     LSPDocumentManager documentManager,
     LSPProjectionProvider projectionProvider) => new DefaultRazorProximityExpressionResolver(fileUriProvider, documentManager, projectionProvider, (CodeAnalysis.Workspace)null);
示例#27
0
 public static DefaultRazorBreakpointResolver CreateTestInstance(
     FileUriProvider fileUriProvider,
     LSPDocumentManager documentManager,
     LSPProjectionProvider projectionProvider,
     LSPDocumentMappingProvider documentMappingProvider) => new(fileUriProvider, documentManager, projectionProvider, documentMappingProvider, (CodeAnalysis.Workspace)null);
 public abstract void Initialize(LSPDocumentManager documentManager);
        public static async Task <VSInternalReferenceItem[]> RemapReferenceItemsAsync(VSInternalReferenceItem[] result, LSPDocumentMappingProvider documentMappingProvider, LSPDocumentManager documentManager, CancellationToken cancellationToken)
        {
            var remappedLocations = new List <VSInternalReferenceItem>();

            foreach (var referenceItem in result)
            {
                if (referenceItem?.Location is null || referenceItem.Text is null)
                {
                    continue;
                }

                // Temporary fix for codebehind leaking through
                // Revert when https://github.com/dotnet/aspnetcore/issues/22512 is resolved
                referenceItem.DefinitionText = FilterReferenceDisplayText(referenceItem.DefinitionText);
                referenceItem.Text           = FilterReferenceDisplayText(referenceItem.Text);

                // Indicates the reference item is directly available in the code
                referenceItem.Origin = VSInternalItemOrigin.Exact;

                if (!RazorLSPConventions.IsVirtualCSharpFile(referenceItem.Location.Uri) &&
                    !RazorLSPConventions.IsVirtualHtmlFile(referenceItem.Location.Uri))
                {
                    // This location doesn't point to a virtual cs file. No need to remap.
                    remappedLocations.Add(referenceItem);
                    continue;
                }

                var razorDocumentUri = RazorLSPConventions.GetRazorDocumentUri(referenceItem.Location.Uri);
                var languageKind     = RazorLSPConventions.IsVirtualCSharpFile(referenceItem.Location.Uri) ? RazorLanguageKind.CSharp : RazorLanguageKind.Html;
                var mappingResult    = await documentMappingProvider.MapToDocumentRangesAsync(
                    languageKind,
                    razorDocumentUri,
                    new[] { referenceItem.Location.Range },
                    cancellationToken).ConfigureAwait(false);

                if (mappingResult is null ||
                    mappingResult.Ranges[0].IsUndefined() ||
                    (documentManager.TryGetDocument(razorDocumentUri, out var mappedDocumentSnapshot) &&
                     mappingResult.HostDocumentVersion != mappedDocumentSnapshot.Version))
                {
                    // Couldn't remap the location or the document changed in the meantime. Discard this location.
                    continue;
                }

                referenceItem.Location.Uri   = razorDocumentUri;
                referenceItem.DisplayPath    = razorDocumentUri.AbsolutePath;
                referenceItem.Location.Range = mappingResult.Ranges[0];

                remappedLocations.Add(referenceItem);
            }

            return(remappedLocations.ToArray());
        }