@@ -38,20 +38,7 @@ public ValueTask<ImmutableArray<RazorMappedSpanResult>> MapSpansAsync(RazorPinne
38
38
39
39
private async ValueTask < ImmutableArray < RazorMappedSpanResult > > MapSpansAsync ( Solution solution , DocumentId generatedDocumentId , ImmutableArray < TextSpan > spans , CancellationToken cancellationToken )
40
40
{
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 ) ;
55
42
if ( razorDocument is null )
56
43
{
57
44
return [ ] ;
@@ -92,20 +79,7 @@ private async ValueTask<ImmutableArray<RazorMappedEditResult>> MapTextChangesAsy
92
79
{
93
80
try
94
81
{
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 ) ;
109
83
if ( razorDocument is null )
110
84
{
111
85
return [ ] ;
@@ -135,4 +109,23 @@ private async ValueTask<ImmutableArray<RazorMappedEditResult>> MapTextChangesAsy
135
109
return [ ] ;
136
110
}
137
111
}
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
+ }
138
131
}
0 commit comments