public TService GetService <TService>() where TService : class
        {
            if (_documentContainer == null)
            {
                return(this as TService);
            }

            if (typeof(TService) == typeof(IRazorSpanMappingService))
            {
                if (_spanMappingService == null)
                {
                    lock (_lock)
                    {
                        if (_spanMappingService == null)
                        {
                            _spanMappingService = _documentContainer.GetMappingService();
                        }
                    }
                }

                return((TService)_spanMappingService);
            }

            if (typeof(TService) == typeof(IRazorDocumentExcerptService))
            {
                if (_excerptService == null)
                {
                    lock (_lock)
                    {
                        if (_excerptService == null)
                        {
                            _excerptService = _documentContainer.GetExcerptService();
                        }
                    }
                }

                return((TService)_excerptService);
            }

            if (typeof(TService) == typeof(IRazorDocumentPropertiesService))
            {
                if (_documentPropertiesService == null)
                {
                    lock (_lock)
                    {
                        if (_documentPropertiesService == null)
                        {
                            _documentPropertiesService = _documentContainer.GetDocumentPropertiesService();
                        }
                    }
                }

                return((TService)_documentPropertiesService);
            }

            return(this as TService);
        }
Example #2
0
        // Called by us to promote a background document (i.e. assign to a client name). Promoting a background
        // document will allow it to be recognized by the C# server.
        public void PromoteBackgroundDocument(Uri documentUri, IRazorDocumentPropertiesService propertiesService)
        {
            if (documentUri is null)
            {
                throw new ArgumentNullException(nameof(documentUri));
            }

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

            var filePath = documentUri.GetAbsoluteOrUNCPath().Replace('/', '\\');

            if (!TryGetKeyAndEntry(filePath, out var associatedKvp))
            {
                return;
            }

            var associatedKey   = associatedKvp.Value.Key;
            var associatedEntry = associatedKvp.Value.Value;

            var filename = associatedKey.FilePath + ".g.cs";

            // To promote the background document, we just need to add the passed in properties service to
            // the dynamic file info. The properties service contains the client name and allows the C#
            // server to recognize the document.
            var documentServiceProvider = associatedEntry.Current.DocumentServiceProvider;
            var excerptService          = documentServiceProvider.GetService <IRazorDocumentExcerptService>();
            var mappingService          = documentServiceProvider.GetService <IRazorSpanMappingService>();
            var emptyContainer          = new PromotedDynamicDocumentContainer(
                documentUri, propertiesService, excerptService, mappingService, associatedEntry.Current.TextLoader);

            lock (associatedEntry.Lock)
            {
                associatedEntry.Current = new RazorDynamicFileInfo(
                    filename, associatedEntry.Current.SourceCodeKind, associatedEntry.Current.TextLoader, _factory.Create(emptyContainer));
            }

            Updated?.Invoke(this, filePath);
        }
 public RazorDocumentPropertiesServiceWrapper(IRazorDocumentPropertiesService razorDocumentPropertiesService)
 {
     DiagnosticsLspClientName = razorDocumentPropertiesService.DiagnosticsLspClientName;
 }
Example #4
0
 public RazorDocumentPropertiesServiceWrapper(IRazorDocumentPropertiesService razorDocumentPropertiesService)
 {
     DesignTimeOnly           = razorDocumentPropertiesService.DesignTimeOnly;
     DiagnosticsLspClientName = razorDocumentPropertiesService.DiagnosticsLspClientName;
 }