From 5229e65962236ef83003c9906b3d246d1992792d Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Wed, 24 Oct 2018 20:04:15 -0700 Subject: [PATCH] Add GeneratedDocumentTextLoader --- .../GeneratedDocumentTextLoader.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/GeneratedDocumentTextLoader.cs diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/GeneratedDocumentTextLoader.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/GeneratedDocumentTextLoader.cs new file mode 100644 index 0000000000..3aa5124572 --- /dev/null +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/GeneratedDocumentTextLoader.cs @@ -0,0 +1,36 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.CodeAnalysis.Razor.ProjectSystem +{ + internal class GeneratedDocumentTextLoader : TextLoader + { + private readonly DocumentSnapshot _document; + private readonly string _filePath; + private readonly VersionStamp _version; + + public GeneratedDocumentTextLoader(DocumentSnapshot document, string filePath) + { + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + + _document = document; + _filePath = filePath; + _version = VersionStamp.Create(); + } + + public override async Task LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) + { + var output = await _document.GetGeneratedOutputAsync().ConfigureAwait(false); + return TextAndVersion.Create(SourceText.From(output.GetCSharpDocument().GeneratedCode), _version, _filePath); + } + } +}