C#: Only scaffold assemblies in overlay mode, only extract expressions when not scaffolding and only extract attributes when they are in source code in overlay mode.

This commit is contained in:
Michael Nebel
2025-11-03 10:58:52 +01:00
parent 1d2f1545d6
commit 504bb9c4a1
3 changed files with 15 additions and 1 deletions

View File

@@ -57,6 +57,13 @@ namespace Semmle.Extraction.CSharp.Entities
public override void Populate(TextWriter trapFile)
{
// In this case, we don't extract the attribute again, as it was extracted using * ID
// originally and we re-use that.
if (Context.OnlyScaffold && (ReportingLocation is null || !ReportingLocation.IsInSource))
{
return;
}
var type = Type.Create(Context, Symbol.AttributeClass);
trapFile.attributes(this, kind, type.TypeRef, entity);

View File

@@ -34,6 +34,11 @@ namespace Semmle.Extraction.CSharp.Entities
protected sealed override void Populate(TextWriter trapFile)
{
if (Context.OnlyScaffold)
{
return;
}
var type = Type.HasValue ? Entities.Type.Create(Context, Type.Value) : NullType.Create(Context);
trapFile.expressions(this, Kind, type.TypeRef);
if (info.Parent.IsTopLevelParent)

View File

@@ -536,7 +536,9 @@ namespace Semmle.Extraction.CSharp
ShouldAddAssemblyTrapPrefix = shouldAddAssemblyTrapPrefix;
Compilation = c;
this.scope = scope;
OnlyScaffold = overlayInfo.IsOverlayMode && scope is SourceScope ss && overlayInfo.OnlyMakeScaffold(ss.SourceTree.FilePath);
OnlyScaffold = overlayInfo.IsOverlayMode && (
IsAssemblyScope
|| (scope is SourceScope ss && overlayInfo.OnlyMakeScaffold(ss.SourceTree.FilePath)));
}
public bool FromSource => scope is SourceScope;