зеркало из https://github.com/dotnet/razor.git
Make sure we use the right project in the updated project snapshot
This seems like the cause of https://github.com/dotnet/razor/issues/10865
This commit is contained in:
Родитель
f929020b39
Коммит
19860435fc
|
@ -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> projectSnapshotFactory, IFilePathService filePathService)
|
||||
internal class DocumentSnapshotFactory(Lazy<ProjectSnapshotFactory> projectSnapshotFactory)
|
||||
{
|
||||
private static readonly ConditionalWeakTable<TextDocument, RemoteDocumentSnapshot> s_documentSnapshots = new();
|
||||
|
||||
private readonly Lazy<ProjectSnapshotFactory> _projectSnapshotFactory = projectSnapshotFactory;
|
||||
private readonly IFilePathService _filePathService = filePathService;
|
||||
|
||||
public RemoteDocumentSnapshot GetOrCreate(TextDocument textDocument)
|
||||
{
|
||||
|
@ -23,8 +21,9 @@ internal class DocumentSnapshotFactory(Lazy<ProjectSnapshotFactory> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче