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);
        }
示例#2
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;
        }
        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;
        }
        /// <summary>
        /// Gets the content type associated with this type of physical files.
        /// </summary>
        public async Task <IContentType> GetContentTypeAsync()
        {
            IFileToContentTypeService fileToContentTypeService = await VS.GetMefServiceAsync <IFileToContentTypeService>();

            return(fileToContentTypeService.GetContentTypeForFileNameOrExtension(Text));
        }