Skip to content

Commit f02c007

Browse files
author
Dave Bartolomeo
authored
Merge pull request #3677 from github/dbartol/provenance-builtin
Display non-MaD provenance in results view
2 parents 1a59467 + 6687482 commit f02c007

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

extensions/ql-vscode/src/view/results/locations/TaxaLocations.tsx

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ import { SarifLocation } from "./SarifLocation";
1010

1111
/** The definition of a taxon for a data extension model row. */
1212
interface ModelTaxon {
13+
kind: "model";
1314
location: SarifLogLocation;
1415
}
1516

17+
/** A taxon for a built-in model, such as `AdditionalFlowStep`. */
18+
interface BuiltInTaxon {
19+
kind: "string";
20+
text: string;
21+
}
22+
23+
type TaxonDefinition = ModelTaxon | BuiltInTaxon;
24+
1625
/** Resolve an `ArtifactLocation` that might contain a relative reference instead of an absolute
1726
* URI.
1827
*/
@@ -49,12 +58,33 @@ function getLocalPackUri(extension: ToolComponent): URL | undefined {
4958
return new URL(localPackLocation.uri);
5059
}
5160

52-
/** Resolve a `ReportingDescriptorReference` to the `ReportingDescriptor` for the taxon that it
53-
* refers to.
61+
/** Resolve a `ReportingDescriptorReference` to the built-in taxon it refers to, or `undefined` if
62+
* it is not a built-in taxon.
5463
*/
55-
function resolveTaxonDefinition(
56-
run: Run,
64+
function resolveBuiltInTaxon(
5765
taxonRef: ReportingDescriptorReference,
66+
): BuiltInTaxon | undefined {
67+
if (
68+
taxonRef.id !== undefined &&
69+
taxonRef.index === undefined &&
70+
taxonRef.toolComponent === undefined
71+
) {
72+
return {
73+
kind: "string",
74+
text: taxonRef.id,
75+
};
76+
} else {
77+
return undefined;
78+
}
79+
}
80+
81+
/**
82+
* Resolve a `ReportingDescriptorReference` to the MaD taxon definition it refers to, or
83+
* `undefined` if it does not refer to a MaD model.
84+
*/
85+
function resolveModelTaxon(
86+
taxonRef: ReportingDescriptorReference,
87+
run: Run,
5888
): ModelTaxon | undefined {
5989
const extensions = run.tool.extensions;
6090
if (extensions === undefined) {
@@ -101,6 +131,7 @@ function resolveTaxonDefinition(
101131
}
102132

103133
return {
134+
kind: "model",
104135
location: {
105136
physicalLocation: {
106137
...location,
@@ -113,6 +144,14 @@ function resolveTaxonDefinition(
113144
};
114145
}
115146

147+
/** Resolve a `ReportingDescriptorReference` to the taxon definition it refers to. */
148+
function resolveTaxonDefinition(
149+
run: Run,
150+
taxonRef: ReportingDescriptorReference,
151+
): TaxonDefinition | undefined {
152+
return resolveModelTaxon(taxonRef, run) ?? resolveBuiltInTaxon(taxonRef);
153+
}
154+
116155
interface Props {
117156
taxa: ReportingDescriptorReference[] | undefined;
118157
run: Run | undefined;
@@ -148,8 +187,9 @@ export function TaxaLocations({
148187
<div key={index}>
149188
{`(${role}) `}
150189
<SarifLocation
151-
loc={taxonDef.location}
190+
loc={taxonDef.kind === "model" ? taxonDef.location : undefined}
152191
databaseUri={undefined}
192+
text={taxonDef.kind === "string" ? taxonDef.text : undefined}
153193
sourceLocationPrefix=""
154194
onClick={onClick}
155195
/>

0 commit comments

Comments
 (0)