Exemplo n.º 1
0
        // Internal for testing
        internal void ClearClosedDocuments()
        {
            lock (_publishedDiagnostics)
            {
                var publishedDiagnostics = new Dictionary <string, IReadOnlyList <RazorDiagnostic> >(_publishedDiagnostics);
                foreach (var entry in publishedDiagnostics)
                {
                    if (!_projectManager.IsDocumentOpen(entry.Key))
                    {
                        // Document is now closed, we shouldn't track its diagnostics anymore.
                        _publishedDiagnostics.Remove(entry.Key);

                        // If the last published diagnostics for the document were > 0 then we need to clear them out so the user
                        // doesn't have a ton of closed document errors that they can't get rid of.
                        if (entry.Value.Count > 0)
                        {
                            PublishDiagnosticsForFilePath(entry.Key, Array.Empty <Diagnostic>());
                        }
                    }
                }

                _documentClosedTimer?.Dispose();
                _documentClosedTimer = null;

                if (_publishedDiagnostics.Count > 0)
                {
                    lock (_work)
                    {
                        // There's no way for us to know when a document is closed at this layer. Therefore, we need to poll every X seconds
                        // and check if the currently tracked documents are closed. In practice this work is super minimal.
                        StartDocumentClosedCheckTimer();
                    }
                }
            }
        }
        public override void DocumentProcessed(DocumentSnapshot document)
        {
            _foregroundDispatcher.AssertForegroundThread();

            if (!_projectManager.IsDocumentOpen(document.FilePath))
            {
                return;
            }

            if (!(document is DefaultDocumentSnapshot defaultDocument))
            {
                return;
            }

            if (!_documentVersionCache.TryGetDocumentVersion(document, out var syncVersion))
            {
                // Document is no longer important.
                return;
            }

            var latestSynchronizedDocument = defaultDocument.State.HostDocument.GeneratedCodeContainer.LatestDocument;

            if (latestSynchronizedDocument == null ||
                latestSynchronizedDocument == document)
            {
                // Already up-to-date
                return;
            }

            if (IdenticalOutputAfterParse(document, latestSynchronizedDocument, syncVersion))
            {
                // Documents are identical but we didn't synchronize them because they didn't need to be re-evaluated.

                var request = new UpdateCSharpBufferRequest()
                {
                    HostDocumentFilePath = document.FilePath,
                    Changes             = Array.Empty <TextChange>(),
                    HostDocumentVersion = syncVersion
                };

                _router.Client.SendRequest("updateCSharpBuffer", request);
            }
        }
Exemplo n.º 3
0
        public override void DocumentProcessed(DocumentSnapshot document)
        {
            _foregroundDispatcher.AssertForegroundThread();

            if (!_projectManager.IsDocumentOpen(document.FilePath))
            {
                return;
            }

            if (!(document is DefaultDocumentSnapshot defaultDocument))
            {
                return;
            }

            if (!_documentVersionCache.TryGetDocumentVersion(document, out var syncVersion))
            {
                // Document is no longer important.
                return;
            }

            var latestSynchronizedDocument = defaultDocument.State.HostDocument.GeneratedCodeContainer.LatestDocument;

            if (latestSynchronizedDocument == null ||
                latestSynchronizedDocument == document)
            {
                // Already up-to-date
                return;
            }

            if (IdenticalOutputAfterParse(document, latestSynchronizedDocument, syncVersion))
            {
                // Documents are identical but we didn't synchronize them because they didn't need to be re-evaluated.

                var result = document.TryGetText(out var latestText);
                Debug.Assert(result, "We just successfully retrieved the text version, this should always return true.");

                _csharpPublisher.Publish(document.FilePath, latestText, syncVersion);
            }
        }
Exemplo n.º 4
0
        public override void DocumentProcessed(DocumentSnapshot document)
        {
            _projectSnapshotManagerDispatcher.AssertDispatcherThread();

            if (!_projectManager.IsDocumentOpen(document.FilePath))
            {
                return;
            }

            if (document is not DefaultDocumentSnapshot defaultDocument)
            {
                return;
            }

            if (!_documentVersionCache.TryGetDocumentVersion(document, out var nullableSyncVersion))
            {
                // Document is no longer important.
                return;
            }

            var syncVersion = nullableSyncVersion.Value;

            var documentContainer          = defaultDocument.State.GeneratedDocumentContainer;
            var latestSynchronizedDocument = documentContainer.LatestDocument;

            if (latestSynchronizedDocument is null ||
                latestSynchronizedDocument == document)
            {
                // Already up-to-date
                return;
            }

            if (UnchangedHostDocument(document, latestSynchronizedDocument, syncVersion))
            {
                // Documents are identical but we didn't synchronize them because they didn't need to be re-evaluated.
                _generatedDocumentPublisher.PublishCSharp(document.FilePath, documentContainer.CSharpSourceTextContainer.CurrentText, syncVersion);
                _generatedDocumentPublisher.PublishHtml(document.FilePath, documentContainer.HtmlSourceTextContainer.CurrentText, syncVersion);
            }
        }