Ejemplo n.º 1
0
        public DefaultRazorProjectChangePublisher(
            JoinableTaskContext joinableTaskContext,
            LSPEditorFeatureDetector lSPEditorFeatureDetector,
            RazorLogger logger)
        {
            if (joinableTaskContext is null)
            {
                throw new ArgumentNullException(nameof(joinableTaskContext));
            }

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

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

            _deferredPublishTasks    = new Dictionary <string, Task>(FilePathComparer.Instance);
            _pendingProjectPublishes = new Dictionary <string, ProjectSnapshot>(FilePathComparer.Instance);
            _publishLock             = new object();

            _lspEditorFeatureDetector = lSPEditorFeatureDetector;

            _logger = logger;

            _serializer.Converters.Add(TagHelperDescriptorJsonConverter.Instance);
            _serializer.Converters.Add(RazorConfigurationJsonConverter.Instance);
            _serializer.Converters.Add(CodeAnalysis.Razor.Workspaces.Serialization.ProjectSnapshotJsonConverter.Instance);
            _joinableTaskContext = joinableTaskContext;
        }
        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);
        }
Ejemplo n.º 3
0
        public LSPRazorProjectHost(
            JoinableTaskContext joinableTaskContext,
            LSPEditorFeatureDetector featureDetector,
            Lazy <ILanguageClientBroker> languageClientBroker,
            [ImportMany] IEnumerable <Lazy <ILanguageClient, IDictionary <string, object> > > languageClients)
        {
            if (joinableTaskContext is null)
            {
                throw new ArgumentNullException(nameof(joinableTaskContext));
            }

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

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

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

            _joinableTaskFactory       = joinableTaskContext.Factory;
            _featureDetector           = featureDetector;
            _languageClientBroker      = languageClientBroker;
            _applicableLanguageClients = GetApplicableClients(languageClients);
        }
Ejemplo n.º 4
0
        public VSLanguageServerFeatureOptions(LSPEditorFeatureDetector lspEditorFeatureDetector)
        {
            if (lspEditorFeatureDetector is null)
            {
                throw new ArgumentNullException(nameof(lspEditorFeatureDetector));
            }

            _lspEditorFeatureDetector = lspEditorFeatureDetector;
        }
        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.º 6
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 RazorFilePathToContentTypeProviderBase(
            IContentTypeRegistryService contentTypeRegistryService,
            LSPEditorFeatureDetector lspEditorFeatureDetector)
        {
            if (contentTypeRegistryService is null)
            {
                throw new ArgumentNullException(nameof(contentTypeRegistryService));
            }

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

            _contentTypeRegistryService = contentTypeRegistryService;
            _lspEditorFeatureDetector   = lspEditorFeatureDetector;
        }
Ejemplo n.º 8
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);
        }
        public RazorLSPTextViewConnectionListener(
            IVsEditorAdaptersFactoryService editorAdaptersFactory,
            LSPEditorFeatureDetector editorFeatureDetector)
        {
            if (editorAdaptersFactory is null)
            {
                throw new ArgumentNullException(nameof(editorAdaptersFactory));
            }

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

            _editorAdaptersFactory = editorAdaptersFactory;
            _editorFeatureDetector = editorFeatureDetector;
        }
        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;
        }
Ejemplo n.º 11
0
        public DefaultRazorProjectChangePublisher(
            LSPEditorFeatureDetector lSPEditorFeatureDetector,
            ProjectConfigurationFilePathStore projectConfigurationFilePathStore,
            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
            RazorLogger logger)
        {
            if (lSPEditorFeatureDetector is null)
            {
                throw new ArgumentNullException(nameof(lSPEditorFeatureDetector));
            }

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

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

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

            _deferredPublishTasks    = new Dictionary <string, Task>(FilePathComparer.Instance);
            _pendingProjectPublishes = new Dictionary <string, ProjectSnapshot>(FilePathComparer.Instance);
            _publishLock             = new object();

            _lspEditorFeatureDetector          = lSPEditorFeatureDetector;
            _projectConfigurationFilePathStore = projectConfigurationFilePathStore;
            _logger = logger;

            _serializer.Converters.Add(TagHelperDescriptorJsonConverter.Instance);
            _serializer.Converters.Add(RazorConfigurationJsonConverter.Instance);
            _serializer.Converters.Add(CodeAnalysis.Razor.Workspaces.Serialization.ProjectSnapshotJsonConverter.Instance);

            if (serviceProvider.GetService(typeof(SVsOperationProgress)) is IVsOperationProgressStatusService service)
            {
                _operationProgressStatusService = service;
            }
        }
 public CSHTMLFilePathToContentTypeProvider(
     IContentTypeRegistryService contentTypeRegistryService,
     LSPEditorFeatureDetector lspEditorFeatureDetector) : base(contentTypeRegistryService, lspEditorFeatureDetector)
 {
 }
        public RazorEditorFactory(AsyncPackage package) : base(package)
        {
            var componentModel = (IComponentModel)AsyncPackage.GetGlobalService(typeof(SComponentModel));

            _lspEditorFeatureDetector = componentModel.GetService <LSPEditorFeatureDetector>();
        }