File tree Expand file tree Collapse file tree 3 files changed +16
-7
lines changed
Expand file tree Collapse file tree 3 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -111,15 +111,18 @@ public override IEnumerable<Location> Locations
111111 }
112112 }
113113
114- private static IEnumerable < Microsoft . CodeAnalysis . Location > GetLocations ( INamedTypeSymbol type )
114+ private IEnumerable < Microsoft . CodeAnalysis . Location > GetLocations ( INamedTypeSymbol type )
115115 {
116- return type . Locations
117- . Where ( l => l . IsInMetadata )
118- . Concat ( type . DeclaringSyntaxReferences
116+ var metadataLocations = type . Locations
117+ . Where ( l => l . IsInMetadata ) ;
118+ var sourceLocations = type . DeclaringSyntaxReferences
119119 . Select ( loc => loc . GetSyntax ( ) )
120120 . OfType < CSharpSyntaxNode > ( )
121121 . Select ( l => l . FixedLocation ( ) )
122- ) ;
122+ . Where ( Context . IsLocationInContext ) ;
123+
124+ return metadataLocations
125+ . Concat ( sourceLocations ) ;
123126 }
124127
125128 public override Microsoft . CodeAnalysis . Location ? ReportingLocation => GetLocations ( Symbol ) . BestOrDefault ( ) ;
Original file line number Diff line number Diff line change @@ -26,9 +26,12 @@ public override void Populate(TextWriter trapFile)
2626 var parentNs = Namespace . Create ( Context , Symbol . TypeParameterKind == TypeParameterKind . Method ? Context . Compilation . GlobalNamespace : Symbol . ContainingNamespace ) ;
2727 trapFile . parent_namespace ( this , parentNs ) ;
2828
29- foreach ( var l in Symbol . Locations )
29+ if ( Context . ExtractLocation ( Symbol ) )
3030 {
31- WriteLocationToTrap ( trapFile . type_location , this , Context . CreateLocation ( l ) ) ;
31+ foreach ( var l in Symbol . Locations )
32+ {
33+ WriteLocationToTrap ( trapFile . type_location , this , Context . CreateLocation ( l ) ) ;
34+ }
3235 }
3336
3437 if ( IsSourceDeclaration )
Original file line number Diff line number Diff line change @@ -554,6 +554,9 @@ public bool ExtractLocation(ISymbol symbol) =>
554554 SymbolEqualityComparer . Default . Equals ( symbol , symbol . OriginalDefinition ) &&
555555 scope . InScope ( symbol ) ;
556556
557+ public bool IsLocationInContext ( Location location ) =>
558+ location . SourceTree == SourceTree ;
559+
557560 /// <summary>
558561 /// Runs the given action <paramref name="a"/>, guarding for trap duplication
559562 /// based on key <paramref name="key"/>.
You can’t perform that action at this time.
0 commit comments