Skip to content

Commit 077fe0f

Browse files
committed
PR Feedback, and simplify
1 parent 7f7f932 commit 077fe0f

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/WrapWithTag/RemoteSpanMappingService.cs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,7 @@ public ValueTask<ImmutableArray<RazorMappedSpanResult>> MapSpansAsync(RazorPinne
3838

3939
private async ValueTask<ImmutableArray<RazorMappedSpanResult>> MapSpansAsync(Solution solution, DocumentId generatedDocumentId, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken)
4040
{
41-
var generatedDocument = await solution.GetSourceGeneratedDocumentAsync(generatedDocumentId, cancellationToken).ConfigureAwait(false);
42-
if (generatedDocument is null)
43-
{
44-
return [];
45-
}
46-
47-
if (!generatedDocument.Project.TryGetHintNameFromGeneratedDocumentUri(generatedDocument.CreateUri(), out var hintName))
48-
{
49-
return [];
50-
}
51-
52-
var projectSnapshot = _snapshotManager.GetSnapshot(generatedDocument.Project);
53-
54-
var razorDocument = await projectSnapshot.TryGetRazorDocumentFromGeneratedHintNameAsync(hintName, cancellationToken).ConfigureAwait(false);
41+
var razorDocument = await TryGetRazorDocumentForGeneratedDocumentIdAsync(generatedDocumentId, solution, cancellationToken).ConfigureAwait(false);
5542
if (razorDocument is null)
5643
{
5744
return [];
@@ -92,20 +79,7 @@ private async ValueTask<ImmutableArray<RazorMappedEditResult>> MapTextChangesAsy
9279
{
9380
try
9481
{
95-
var generatedDocument = await solution.GetSourceGeneratedDocumentAsync(generatedDocumentId, cancellationToken).ConfigureAwait(false);
96-
if (generatedDocument is null)
97-
{
98-
return [];
99-
}
100-
101-
if (!generatedDocument.Project.TryGetHintNameFromGeneratedDocumentUri(generatedDocument.CreateUri(), out var hintName))
102-
{
103-
return [];
104-
}
105-
106-
var projectSnapshot = _snapshotManager.GetSnapshot(generatedDocument.Project);
107-
108-
var razorDocument = await projectSnapshot.TryGetRazorDocumentFromGeneratedHintNameAsync(hintName, cancellationToken).ConfigureAwait(false);
82+
var razorDocument = await TryGetRazorDocumentForGeneratedDocumentIdAsync(generatedDocumentId, solution, cancellationToken).ConfigureAwait(false);
10983
if (razorDocument is null)
11084
{
11185
return [];
@@ -135,4 +109,23 @@ private async ValueTask<ImmutableArray<RazorMappedEditResult>> MapTextChangesAsy
135109
return [];
136110
}
137111
}
112+
113+
private async Task<TextDocument?> TryGetRazorDocumentForGeneratedDocumentIdAsync(DocumentId generatedDocumentId, Solution solution, CancellationToken cancellationToken)
114+
{
115+
var generatedDocument = await solution.GetSourceGeneratedDocumentAsync(generatedDocumentId, cancellationToken).ConfigureAwait(false);
116+
if (generatedDocument is null)
117+
{
118+
return null;
119+
}
120+
121+
var identity = RazorGeneratedDocumentIdentity.Create(generatedDocument);
122+
if (!identity.IsRazorSourceGeneratedDocument())
123+
{
124+
return null;
125+
}
126+
127+
var projectSnapshot = _snapshotManager.GetSnapshot(generatedDocument.Project);
128+
129+
return await projectSnapshot.TryGetRazorDocumentFromGeneratedHintNameAsync(identity.HintName, cancellationToken).ConfigureAwait(false);
130+
}
138131
}

0 commit comments

Comments
 (0)