public abstract PublishCSharp ( string filePath, SourceText sourceText, int hostDocumentVersion ) : void | ||
filePath | string | |
sourceText | SourceText | |
hostDocumentVersion | int | |
return | void |
private ReferenceOutputCapturingContainer Create(string filePath) { var documentContainer = new ReferenceOutputCapturingContainer(); documentContainer.GeneratedCSharpChanged += (sender, args) => { var generatedDocumentContainer = (GeneratedDocumentContainer)sender; var latestDocument = generatedDocumentContainer.LatestDocument; _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() => { if (!_projectSnapshotManager.IsDocumentOpen(filePath)) { // Document isn't opened, no need to notify the client return; } if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var nullableHostDocumentVersion)) { // Cache entry doesn't exist, document most likely was evicted from the cache/too old. return; } var hostDocumentVersion = nullableHostDocumentVersion.Value; _generatedDocumentPublisher.PublishCSharp(filePath, args.NewText, hostDocumentVersion); }, CancellationToken.None); }; documentContainer.GeneratedHtmlChanged += (sender, args) => { var generatedDocumentContainer = (GeneratedDocumentContainer)sender; var latestDocument = generatedDocumentContainer.LatestDocument; _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() => { if (!_projectSnapshotManager.IsDocumentOpen(filePath)) { // Document isn't opened, no need to notify the client return; } if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var nullableHostDocumentVersion)) { // Cache entry doesn't exist, document most likely was evicted from the cache/too old. return; } var hostDocumentVersion = nullableHostDocumentVersion.Value; _generatedDocumentPublisher.PublishHtml(filePath, args.NewText, hostDocumentVersion); }, CancellationToken.None); }; return(documentContainer); }
private GeneratedDocumentContainer Create(string filePath) { var documentContainer = new GeneratedDocumentContainer(); documentContainer.GeneratedCSharpChanged += (sender, args) => { var generatedDocumentContainer = (GeneratedDocumentContainer)sender; var latestDocument = generatedDocumentContainer.LatestDocument; Task.Factory.StartNew(() => { if (!_projectSnapshotManager.IsDocumentOpen(filePath)) { // Document isn't opened, no need to notify the client return; } if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var nullableHostDocumentVersion)) { // Cache entry doesn't exist, document most likely was evicted from the cache/too old. return; } var hostDocumentVersion = nullableHostDocumentVersion.Value; _generatedDocumentPublisher.PublishCSharp(filePath, args.NewText, hostDocumentVersion); }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler); }; documentContainer.GeneratedHtmlChanged += (sender, args) => { var generatedDocumentContainer = (GeneratedDocumentContainer)sender; var latestDocument = generatedDocumentContainer.LatestDocument; Task.Factory.StartNew(() => { if (!_projectSnapshotManager.IsDocumentOpen(filePath)) { // Document isn't opened, no need to notify the client return; } if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var nullableHostDocumentVersion)) { // Cache entry doesn't exist, document most likely was evicted from the cache/too old. return; } var hostDocumentVersion = nullableHostDocumentVersion.Value; _generatedDocumentPublisher.PublishHtml(filePath, args.NewText, hostDocumentVersion); }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler); }; return(documentContainer); }
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); } }