diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/DocumentSnapshotFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/DocumentSnapshotFactory.cs index 853fe37386..86006985e3 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/DocumentSnapshotFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/DocumentSnapshotFactory.cs @@ -4,18 +4,16 @@ using System; using System.Composition; using System.Runtime.CompilerServices; -using Microsoft.CodeAnalysis.Razor.Workspaces; namespace Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem; [Export(typeof(DocumentSnapshotFactory)), Shared] [method: ImportingConstructor] -internal class DocumentSnapshotFactory(Lazy projectSnapshotFactory, IFilePathService filePathService) +internal class DocumentSnapshotFactory(Lazy projectSnapshotFactory) { private static readonly ConditionalWeakTable s_documentSnapshots = new(); private readonly Lazy _projectSnapshotFactory = projectSnapshotFactory; - private readonly IFilePathService _filePathService = filePathService; public RemoteDocumentSnapshot GetOrCreate(TextDocument textDocument) { @@ -23,8 +21,9 @@ internal class DocumentSnapshotFactory(Lazy projectSnaps { if (!s_documentSnapshots.TryGetValue(textDocument, out var documentSnapshot)) { - var projectSnapshot = _projectSnapshotFactory.Value.GetOrCreate(textDocument.Project); - documentSnapshot = new RemoteDocumentSnapshot(textDocument, projectSnapshot, _filePathService); + var projectSnapshotFactory = _projectSnapshotFactory.Value; + var projectSnapshot = projectSnapshotFactory.GetOrCreate(textDocument.Project); + documentSnapshot = new RemoteDocumentSnapshot(textDocument, projectSnapshot, projectSnapshotFactory); s_documentSnapshots.Add(textDocument, documentSnapshot); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteDocumentSnapshot.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteDocumentSnapshot.cs index b3e10ea6d8..ca24ebd01d 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteDocumentSnapshot.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteDocumentSnapshot.cs @@ -7,16 +7,15 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor; using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem; -internal class RemoteDocumentSnapshot(TextDocument textDocument, RemoteProjectSnapshot projectSnapshot, IFilePathService filePathService) : IDocumentSnapshot +internal class RemoteDocumentSnapshot(TextDocument textDocument, RemoteProjectSnapshot projectSnapshot, ProjectSnapshotFactory projectSnapshotFactory) : IDocumentSnapshot { private readonly TextDocument _textDocument = textDocument; private readonly RemoteProjectSnapshot _projectSnapshot = projectSnapshot; - private readonly IFilePathService _filePathService = filePathService; + private readonly ProjectSnapshotFactory _projectSnapshotFactory = projectSnapshotFactory; // TODO: Delete this field when the source generator is hooked up private Document? _generatedDocument; @@ -63,8 +62,10 @@ internal class RemoteDocumentSnapshot(TextDocument textDocument, RemoteProjectSn { var id = _textDocument.Id; var newDocument = _textDocument.Project.Solution.WithAdditionalDocumentText(id, text).GetAdditionalDocument(id).AssumeNotNull(); + var project = newDocument.Project; + var projectSnapshot = _projectSnapshotFactory.GetOrCreate(project); - return new RemoteDocumentSnapshot(newDocument, _projectSnapshot, _filePathService); + return new RemoteDocumentSnapshot(newDocument, projectSnapshot, _projectSnapshotFactory); } public bool TryGetGeneratedOutput([NotNullWhen(true)] out RazorCodeDocument? result)