private RazorContentTypeChangeListener CreateListener(
            TrackingLSPDocumentManager lspDocumentManager      = null,
            LSPEditorFeatureDetector lspEditorFeatureDetector  = null,
            IFileToContentTypeService fileToContentTypeService = null)
        {
            var textDocumentFactory = new Mock <ITextDocumentFactoryService>(MockBehavior.Strict).Object;

            Mock.Get(textDocumentFactory).Setup(f => f.TryGetTextDocument(It.IsAny <ITextBuffer>(), out It.Ref <ITextDocument> .IsAny)).Returns(false);

            lspDocumentManager ??= Mock.Of <TrackingLSPDocumentManager>(MockBehavior.Strict);
            lspEditorFeatureDetector ??= Mock.Of <LSPEditorFeatureDetector>(detector => detector.IsLSPEditorAvailable(It.IsAny <string>(), null) == true && detector.IsRemoteClient() == false, MockBehavior.Strict);
            fileToContentTypeService ??= Mock.Of <IFileToContentTypeService>(detector => detector.GetContentTypeForFilePath(It.IsAny <string>()) == RazorContentType, MockBehavior.Strict);
            var textManager = new Mock <IVsTextManager2>(MockBehavior.Strict);

            textManager.Setup(m => m.GetUserPreferences2(null, null, It.IsAny <LANGPREFERENCES2[]>(), null)).Returns(VSConstants.E_NOTIMPL);
            var listener = new RazorContentTypeChangeListener(
                textDocumentFactory,
                lspDocumentManager,
                lspEditorFeatureDetector,
                Mock.Of <SVsServiceProvider>(s => s.GetService(It.IsAny <Type>()) == textManager.Object, MockBehavior.Strict),
                Mock.Of <IEditorOptionsFactoryService>(s => s.GetOptions(It.IsAny <ITextBuffer>()) == Mock.Of <IEditorOptions>(MockBehavior.Strict), MockBehavior.Strict),
                fileToContentTypeService);

            return(listener);
        }
        public DefaultRazorLanguageServerCustomMessageTarget(
            LSPDocumentManager documentManager,
            JoinableTaskContext joinableTaskContext,
            LSPRequestInvoker requestInvoker)
        {
            if (documentManager is null)
            {
                throw new ArgumentNullException(nameof(documentManager));
            }

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

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

            _documentManager = documentManager as TrackingLSPDocumentManager;

            if (_documentManager is null)
            {
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
                throw new ArgumentException("The LSP document manager should be of type " + typeof(TrackingLSPDocumentManager).FullName, nameof(_documentManager));
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
            }

            _joinableTaskFactory       = joinableTaskContext.Factory;
            _requestInvoker            = requestInvoker;
            _updateCSharpSemaphoreSlim = new SingleThreadedFIFOSemaphoreSlim();
            _updateHtmlSemaphoreSlim   = new SingleThreadedFIFOSemaphoreSlim();
        }
Ejemplo n.º 3
0
        // Testing constructor
        internal DefaultRazorLanguageServerCustomMessageTarget(
            LSPDocumentManager documentManager,
            JoinableTaskContext joinableTaskContext,
            LSPRequestInvoker requestInvoker,
            RazorUIContextManager uIContextManager,
            IDisposable razorReadyListener,
            RazorLSPClientOptionsMonitor clientOptionsMonitor,
            LSPDocumentSynchronizer documentSynchronizer)
        {
            if (documentManager is null)
            {
                throw new ArgumentNullException(nameof(documentManager));
            }

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

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

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

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

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

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

            _documentManager = documentManager as TrackingLSPDocumentManager;

            if (_documentManager is null)
            {
                throw new ArgumentException("The LSP document manager should be of type " + typeof(TrackingLSPDocumentManager).FullName, nameof(_documentManager));
            }

            _joinableTaskFactory  = joinableTaskContext.Factory;
            _requestInvoker       = requestInvoker;
            _uIContextManager     = uIContextManager;
            _razorReadyListener   = razorReadyListener;
            _clientOptionsMonitor = clientOptionsMonitor;
            _documentSynchronizer = documentSynchronizer;
        }
        public RazorLSPTextDocumentCreatedListener(
            ITextDocumentFactoryService textDocumentFactory,
            IContentTypeRegistryService contentTypeRegistry,
            LSPDocumentManager lspDocumentManager,
            LSPEditorFeatureDetector lspEditorFeatureDetector,
            SVsServiceProvider serviceProvider,
            IEditorOptionsFactoryService editorOptionsFactory)
        {
            if (textDocumentFactory is null)
            {
                throw new ArgumentNullException(nameof(textDocumentFactory));
            }

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

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

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

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

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

            _lspDocumentManager = lspDocumentManager as TrackingLSPDocumentManager;

            if (_lspDocumentManager is null)
            {
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
                throw new ArgumentException("The LSP document manager should be of type " + typeof(TrackingLSPDocumentManager).FullName, nameof(_lspDocumentManager));
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
            }

            _textDocumentFactory      = textDocumentFactory;
            _lspEditorFeatureDetector = lspEditorFeatureDetector;
            _serviceProvider          = serviceProvider;
            _editorOptionsFactory     = editorOptionsFactory;

            _textDocumentFactory.TextDocumentCreated  += TextDocumentFactory_TextDocumentCreated;
            _textDocumentFactory.TextDocumentDisposed += TextDocumentFactory_TextDocumentDisposed;
            _razorLSPContentType = contentTypeRegistry.GetContentType(RazorLSPContentTypeDefinition.Name);
        }
Ejemplo n.º 5
0
        public RazorContentTypeChangeListener(
            ITextDocumentFactoryService textDocumentFactory,
            LSPDocumentManager lspDocumentManager,
            LSPEditorFeatureDetector lspEditorFeatureDetector,
            SVsServiceProvider serviceProvider,
            IEditorOptionsFactoryService editorOptionsFactory,
            IFileToContentTypeService fileToContentTypeService)
        {
            if (textDocumentFactory is null)
            {
                throw new ArgumentNullException(nameof(textDocumentFactory));
            }

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

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

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

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

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

            _lspDocumentManager = lspDocumentManager as TrackingLSPDocumentManager;

            if (_lspDocumentManager is null)
            {
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
                throw new ArgumentException("The LSP document manager should be of type " + typeof(TrackingLSPDocumentManager).FullName, nameof(_lspDocumentManager));
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
            }

            _textDocumentFactory      = textDocumentFactory;
            _lspEditorFeatureDetector = lspEditorFeatureDetector;
            _serviceProvider          = serviceProvider;
            _editorOptionsFactory     = editorOptionsFactory;
            _fileToContentTypeService = fileToContentTypeService;
        }
Ejemplo n.º 6
0
        private RazorContentTypeChangeListener CreateListener(
            TrackingLSPDocumentManager lspDocumentManager     = null,
            LSPEditorFeatureDetector lspEditorFeatureDetector = null)
        {
            var textDocumentFactory = Mock.Of <ITextDocumentFactoryService>();

            lspDocumentManager ??= Mock.Of <TrackingLSPDocumentManager>();
            lspEditorFeatureDetector ??= Mock.Of <LSPEditorFeatureDetector>(detector => detector.IsLSPEditorAvailable(It.IsAny <string>(), null) == true);
            var listener = new RazorContentTypeChangeListener(
                textDocumentFactory,
                lspDocumentManager,
                lspEditorFeatureDetector,
                Mock.Of <SVsServiceProvider>(s => s.GetService(It.IsAny <Type>()) == Mock.Of <IVsTextManager2>()),
                Mock.Of <IEditorOptionsFactoryService>(s => s.GetOptions(It.IsAny <ITextBuffer>()) == Mock.Of <IEditorOptions>()));

            return(listener);
        }
        // Testing constructor
        internal DefaultRazorLanguageServerCustomMessageTarget(
            LSPDocumentManager documentManager,
            JoinableTaskContext joinableTaskContext,
            LSPRequestInvoker requestInvoker,
            RazorUIContextManager uIContextManager,
            IDisposable razorReadyListener)
        {
            if (documentManager is null)
            {
                throw new ArgumentNullException(nameof(documentManager));
            }

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

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

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

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

            _documentManager = documentManager as TrackingLSPDocumentManager;

            if (_documentManager is null)
            {
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
                throw new ArgumentException("The LSP document manager should be of type " + typeof(TrackingLSPDocumentManager).FullName, nameof(_documentManager));
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
            }

            _joinableTaskFactory = joinableTaskContext.Factory;
            _requestInvoker      = requestInvoker;
            _uIContextManager    = uIContextManager;
            _razorReadyListener  = razorReadyListener;
        }
        public RazorContentTypeChangeListener(
            ITextDocumentFactoryService textDocumentFactory,
            LSPDocumentManager lspDocumentManager,
            LSPEditorFeatureDetector lspEditorFeatureDetector,
            IEditorOptionsFactoryService editorOptionsFactory,
            IFileToContentTypeService fileToContentTypeService)
        {
            if (textDocumentFactory is null)
            {
                throw new ArgumentNullException(nameof(textDocumentFactory));
            }

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

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

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

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

            if (lspDocumentManager is not TrackingLSPDocumentManager tracking)
            {
                throw new ArgumentException("The LSP document manager should be of type " + typeof(TrackingLSPDocumentManager).FullName, nameof(_lspDocumentManager));
            }

            _lspDocumentManager = tracking;

            _textDocumentFactory      = textDocumentFactory;
            _lspEditorFeatureDetector = lspEditorFeatureDetector;
            _editorOptionsFactory     = editorOptionsFactory;
            _fileToContentTypeService = fileToContentTypeService;
        }
 // Testing constructor
 internal DefaultRazorLanguageServerCustomMessageTarget(TrackingLSPDocumentManager documentManager)
 {
     _documentManager = documentManager;
 }
Ejemplo n.º 10
0
        // Testing constructor
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
        internal DefaultRazorLanguageServerCustomMessageTarget(TrackingLSPDocumentManager documentManager)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
        {
            _documentManager = documentManager;
        }