Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ protected void ExtractCompilerGenerated(TextWriter trapFile)
/// The location which is stored in the database and is used when highlighting source code.
/// It's generally short, e.g. a method name.
/// </summary>
public override Microsoft.CodeAnalysis.Location? ReportingLocation => Symbol.Locations.BestOrDefault();
public override Microsoft.CodeAnalysis.Location? ReportingLocation => Context.GetMsLocations(Symbol).BestOrDefault();

/// <summary>
/// The full text span of the entity, e.g. for binding comments.
/// </summary>
public virtual Microsoft.CodeAnalysis.Location? FullLocation => Symbol.Locations.BestOrDefault();
public virtual Microsoft.CodeAnalysis.Location? FullLocation => Context.GetMsLocations(Symbol).BestOrDefault();

public virtual IEnumerable<Location> Locations
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ public override void Populate(TextWriter trapFile)
var type = Type.Create(Context, Symbol.Type);
trapFile.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent!, Original);

foreach (var l in Symbol.Locations)
{
WriteLocationToTrap(trapFile.param_location, this, Context.CreateLocation(l));
}
var locations = Context.GetLocations(Symbol);

WriteLocationsToTrap(trapFile.param_location, this, locations);

if (!Symbol.Locations.Any() &&
Symbol.ContainingSymbol is IMethodSymbol ms &&
Expand Down
14 changes: 12 additions & 2 deletions csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,20 @@ public bool ExtractLocation(ISymbol symbol) =>
/// <param name="symbol">The symbol</param>
/// <returns>List of locations</returns>
public IEnumerable<Entities.Location> GetLocations(ISymbol symbol) =>
symbol.Locations
.Where(l => !l.IsInSource || IsLocationInContext(l))
GetMsLocations(symbol)
.Select(CreateLocation);

/// <summary>
/// Gets the locations of the symbol that are either
/// (1) In assemblies.
/// (2) In the current context.
/// </summary>
/// <param name="symbol">The symbol</param>
/// <returns>List of locations</returns>
public IEnumerable<Location> GetMsLocations(ISymbol symbol) =>
symbol.Locations
.Where(l => !l.IsInSource || IsLocationInContext(l));

public bool IsLocationInContext(Location location) =>
location.SourceTree == SourceTree;

Expand Down