@@ -178,12 +178,13 @@ public bool PortablePdbHasLocalSource(string module, out string firstNotFoundDoc
178
178
Document document = metadataReader . GetDocument ( docHandle ) ;
179
179
string docName = _sourceRootTranslator . ResolveFilePath ( metadataReader . GetString ( document . Name ) ) ;
180
180
Guid languageGuid = metadataReader . GetGuid ( document . Language ) ;
181
+
181
182
// We verify all docs and return false if not all are present in local
182
183
// We could have false negative if doc is not a source
183
184
// Btw check for all possible extension could be weak approach
184
185
// We exlude from the check the autogenerated source file(i.e. source generators)
185
186
// We exclude special F# construct https://github.com/coverlet-coverage/coverlet/issues/1145
186
- if ( ! _fileSystem . Exists ( docName ) && ! docName . EndsWith ( ".g.cs" ) &&
187
+ if ( ! _fileSystem . Exists ( docName ) && ! IsGeneratedDocumentName ( docName ) &&
187
188
! IsUnknownModuleInFSharpAssembly ( languageGuid , docName ) )
188
189
{
189
190
return ( false , docName ) ;
@@ -449,6 +450,35 @@ private static bool IsAssembly(string filePath)
449
450
}
450
451
}
451
452
453
+ // Follow the same rules that exist in Microsoft.CodeAnalysis
454
+ // https://sourceroslyn.io/#Microsoft.CodeAnalysis/InternalUtilities/GeneratedCodeUtilities.cs,55bff725ec9f1338,references
455
+ private static bool IsGeneratedDocumentName ( string docPath )
456
+ {
457
+ if ( ! string . IsNullOrEmpty ( docPath ) )
458
+ {
459
+ string fileName = Path . GetFileName ( docPath ) ;
460
+ if ( fileName . StartsWith ( "TemporaryGeneratedFile_" , StringComparison . OrdinalIgnoreCase ) )
461
+ {
462
+ return true ;
463
+ }
464
+
465
+ string extension = Path . GetExtension ( fileName ) ;
466
+ if ( ! string . IsNullOrEmpty ( extension ) )
467
+ {
468
+ string fileNameWithoutExtension = Path . GetFileNameWithoutExtension ( docPath ) ;
469
+ if ( fileNameWithoutExtension . EndsWith ( ".designer" , StringComparison . OrdinalIgnoreCase ) ||
470
+ fileNameWithoutExtension . EndsWith ( ".generated" , StringComparison . OrdinalIgnoreCase ) ||
471
+ fileNameWithoutExtension . EndsWith ( ".g" , StringComparison . OrdinalIgnoreCase ) ||
472
+ fileNameWithoutExtension . EndsWith ( ".g.i" , StringComparison . OrdinalIgnoreCase ) )
473
+ {
474
+ return true ;
475
+ }
476
+ }
477
+ }
478
+
479
+ return false ;
480
+ }
481
+
452
482
private static bool IsUnknownModuleInFSharpAssembly ( Guid languageGuid , string docName )
453
483
{
454
484
// https://github.com/dotnet/runtime/blob/main/docs/design/specs/PortablePdb-Metadata.md#document-table-0x30
0 commit comments