Skip to content

Commit 1bad26a

Browse files
Merge branch 'main' into robertbrignull/automodel-sort-order
2 parents 95fd015 + db73cfe commit 1bad26a

21 files changed

Lines changed: 664 additions & 152 deletions

extensions/ql-vscode/src/common/interface-types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,14 @@ interface StopGeneratingMethodsFromLlmMessage {
590590
packageName: string;
591591
}
592592

593+
interface StartModelEvaluationMessage {
594+
t: "startModelEvaluation";
595+
}
596+
597+
interface StopModelEvaluationMessage {
598+
t: "stopModelEvaluation";
599+
}
600+
593601
interface ModelDependencyMessage {
594602
t: "modelDependency";
595603
}
@@ -648,7 +656,9 @@ export type FromModelEditorMessage =
648656
| StopGeneratingMethodsFromLlmMessage
649657
| ModelDependencyMessage
650658
| HideModeledMethodsMessage
651-
| SetMultipleModeledMethodsMessage;
659+
| SetMultipleModeledMethodsMessage
660+
| StartModelEvaluationMessage
661+
| StopModelEvaluationMessage;
652662

653663
interface RevealInEditorMessage {
654664
t: "revealInModelEditor";

extensions/ql-vscode/src/compare/sarif-diff.ts

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,75 @@
1-
import type { Result } from "sarif";
1+
import type { Location, Result } from "sarif";
2+
3+
function toCanonicalLocation(location: Location): Location {
4+
if (location.physicalLocation?.artifactLocation?.index !== undefined) {
5+
const canonicalLocation = {
6+
...location,
7+
};
8+
9+
canonicalLocation.physicalLocation = {
10+
...canonicalLocation.physicalLocation,
11+
};
12+
13+
canonicalLocation.physicalLocation.artifactLocation = {
14+
...canonicalLocation.physicalLocation.artifactLocation,
15+
};
16+
17+
// The index is dependent on the result of the SARIF file and usually doesn't really tell
18+
// us anything useful, so we remove it from the comparison.
19+
delete canonicalLocation.physicalLocation.artifactLocation.index;
20+
21+
return canonicalLocation;
22+
}
23+
24+
// Don't create a new object if we don't need to
25+
return location;
26+
}
227

328
function toCanonicalResult(result: Result): Result {
429
const canonicalResult = {
530
...result,
631
};
732

833
if (canonicalResult.locations) {
9-
canonicalResult.locations = canonicalResult.locations.map((location) => {
10-
if (location.physicalLocation?.artifactLocation?.index !== undefined) {
11-
const canonicalLocation = {
12-
...location,
13-
};
34+
canonicalResult.locations =
35+
canonicalResult.locations.map(toCanonicalLocation);
36+
}
1437

15-
canonicalLocation.physicalLocation = {
16-
...canonicalLocation.physicalLocation,
17-
};
38+
if (canonicalResult.relatedLocations) {
39+
canonicalResult.relatedLocations =
40+
canonicalResult.relatedLocations.map(toCanonicalLocation);
41+
}
1842

19-
canonicalLocation.physicalLocation.artifactLocation = {
20-
...canonicalLocation.physicalLocation.artifactLocation,
21-
};
43+
if (canonicalResult.codeFlows) {
44+
canonicalResult.codeFlows = canonicalResult.codeFlows.map((codeFlow) => {
45+
if (codeFlow.threadFlows) {
46+
return {
47+
...codeFlow,
48+
threadFlows: codeFlow.threadFlows.map((threadFlow) => {
49+
if (threadFlow.locations) {
50+
return {
51+
...threadFlow,
52+
locations: threadFlow.locations.map((threadFlowLocation) => {
53+
if (threadFlowLocation.location) {
54+
return {
55+
...threadFlowLocation,
56+
location: toCanonicalLocation(
57+
threadFlowLocation.location,
58+
),
59+
};
60+
}
2261

23-
// The index is dependent on the result of the SARIF file and usually doesn't really tell
24-
// us anything useful, so we remove it from the comparison.
25-
delete canonicalLocation.physicalLocation.artifactLocation.index;
62+
return threadFlowLocation;
63+
}),
64+
};
65+
}
2666

27-
return canonicalLocation;
67+
return threadFlow;
68+
}),
69+
};
2870
}
2971

30-
// Don't create a new object if we don't need to
31-
return location;
72+
return codeFlow;
3273
});
3374
}
3475

extensions/ql-vscode/src/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ const LLM_GENERATION_DEV_ENDPOINT = new Setting(
715715
"llmGenerationDevEndpoint",
716716
MODEL_SETTING,
717717
);
718+
const MODEL_EVALUATION = new Setting("evaluation", MODEL_SETTING);
718719
const EXTENSIONS_DIRECTORY = new Setting("extensionsDirectory", MODEL_SETTING);
719720
const ENABLE_PYTHON = new Setting("enablePython", MODEL_SETTING);
720721
const ENABLE_ACCESS_PATH_SUGGESTIONS = new Setting(
@@ -759,6 +760,10 @@ export class ModelConfigListener extends ConfigListener implements ModelConfig {
759760
return LLM_GENERATION_DEV_ENDPOINT.getValue<string | undefined>();
760761
}
761762

763+
public get modelEvaluation(): boolean {
764+
return !!MODEL_EVALUATION.getValue<boolean>();
765+
}
766+
762767
public getExtensionsDirectory(languageId: string): string | undefined {
763768
return EXTENSIONS_DIRECTORY.getValue<string>({
764769
languageId,

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ export class ModelEditorView extends AbstractWebview<
337337
this.setModeledMethods(msg.methodSignature, msg.modeledMethods);
338338
break;
339339
}
340+
case "startModelEvaluation":
341+
this.startModelEvaluation();
342+
break;
343+
case "stopModelEvaluation":
344+
this.stopModelEvaluation();
345+
break;
340346
case "telemetry":
341347
telemetryListener?.sendUIInteraction(msg.action);
342348
break;
@@ -402,6 +408,8 @@ export class ModelEditorView extends AbstractWebview<
402408
const showLlmButton =
403409
this.databaseItem.language === "java" && this.modelConfig.llmGeneration;
404410

411+
const showEvaluationUi = this.modelConfig.modelEvaluation;
412+
405413
const sourceArchiveAvailable =
406414
this.databaseItem.hasSourceArchiveInExplorer();
407415

@@ -416,6 +424,7 @@ export class ModelEditorView extends AbstractWebview<
416424
language: this.language,
417425
showGenerateButton,
418426
showLlmButton,
427+
showEvaluationUi,
419428
mode: this.modelingStore.getMode(this.databaseItem),
420429
showModeSwitchButton,
421430
sourceArchiveAvailable,
@@ -910,4 +919,12 @@ export class ModelEditorView extends AbstractWebview<
910919
);
911920
this.modelingStore.addModifiedMethod(this.databaseItem, signature);
912921
}
922+
923+
private startModelEvaluation() {
924+
// Do nothing for now. This will be fleshed out in the near future.
925+
}
926+
927+
private stopModelEvaluation() {
928+
// Do nothing for now. This will be fleshed out in the near future.
929+
}
913930
}

extensions/ql-vscode/src/model-editor/modeled-method.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,27 @@ export function modeledMethodSupportsProvenance(
111111
);
112112
}
113113

114-
export function isModelAccepted(
114+
export function isModelPending(
115115
modeledMethod: ModeledMethod | undefined,
116116
modelingStatus: ModelingStatus,
117+
processedByAutoModel?: boolean,
117118
): boolean {
118-
if (!modeledMethod) {
119+
if (
120+
(!modeledMethod || modeledMethod.type === "none") &&
121+
processedByAutoModel
122+
) {
119123
return true;
120124
}
121125

126+
if (!modeledMethod) {
127+
return false;
128+
}
129+
122130
return (
123-
modelingStatus !== "unsaved" ||
124-
modeledMethod.type === "none" ||
125-
!modeledMethodSupportsProvenance(modeledMethod) ||
126-
modeledMethod.provenance !== "ai-generated"
131+
modelingStatus === "unsaved" &&
132+
modeledMethod.type !== "none" &&
133+
modeledMethodSupportsProvenance(modeledMethod) &&
134+
modeledMethod.provenance === "ai-generated"
127135
);
128136
}
129137

extensions/ql-vscode/src/model-editor/shared/view-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface ModelEditorViewState {
77
language: QueryLanguage;
88
showGenerateButton: boolean;
99
showLlmButton: boolean;
10+
showEvaluationUi: boolean;
1011
mode: Mode;
1112
showModeSwitchButton: boolean;
1213
sourceArchiveAvailable: boolean;

extensions/ql-vscode/src/stories/method-modeling/MethodModelingInputs.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ export const ModelingNotAccepted = Template.bind({});
6666
ModelingNotAccepted.args = {
6767
method,
6868
modeledMethod: generatedModeledMethod,
69-
modelingStatus: "unsaved",
69+
modelPending: true,
7070
};

extensions/ql-vscode/src/view/method-modeling/MethodModelingInputs.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ModelOutputDropdown } from "../model-editor/ModelOutputDropdown";
77
import { ModelKindDropdown } from "../model-editor/ModelKindDropdown";
88
import { InProgressDropdown } from "../model-editor/InProgressDropdown";
99
import type { QueryLanguage } from "../../common/query-language";
10-
import type { ModelingStatus } from "../../model-editor/shared/modeling-status";
1110

1211
const Container = styled.div`
1312
padding-top: 0.5rem;
@@ -27,7 +26,7 @@ export type MethodModelingInputsProps = {
2726
language: QueryLanguage;
2827
method: Method;
2928
modeledMethod: ModeledMethod | undefined;
30-
modelingStatus: ModelingStatus;
29+
modelPending: boolean;
3130
isModelingInProgress: boolean;
3231
onChange: (modeledMethod: ModeledMethod) => void;
3332
};
@@ -36,15 +35,15 @@ export const MethodModelingInputs = ({
3635
language,
3736
method,
3837
modeledMethod,
39-
modelingStatus,
38+
modelPending,
4039
isModelingInProgress,
4140
onChange,
4241
}: MethodModelingInputsProps): React.JSX.Element => {
4342
const inputProps = {
4443
language,
4544
method,
4645
modeledMethod,
47-
modelingStatus,
46+
modelPending,
4847
onChange,
4948
};
5049

extensions/ql-vscode/src/view/method-modeling/MultipleModeledMethodsPanel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import type { Method } from "../../model-editor/method";
33
import type { ModeledMethod } from "../../model-editor/modeled-method";
4+
import { isModelPending } from "../../model-editor/modeled-method";
45
import {
56
canAddNewModeledMethod,
67
canRemoveModeledMethod,
@@ -156,7 +157,10 @@ export const MultipleModeledMethodsPanel = ({
156157
language={language}
157158
method={method}
158159
modeledMethod={modeledMethods[selectedIndex]}
159-
modelingStatus={modelingStatus}
160+
modelPending={isModelPending(
161+
modeledMethods[selectedIndex],
162+
modelingStatus,
163+
)}
160164
isModelingInProgress={isModelingInProgress}
161165
onChange={handleChange}
162166
/>
@@ -165,7 +169,7 @@ export const MultipleModeledMethodsPanel = ({
165169
language={language}
166170
method={method}
167171
modeledMethod={undefined}
168-
modelingStatus={modelingStatus}
172+
modelPending={false}
169173
isModelingInProgress={isModelingInProgress}
170174
onChange={handleChange}
171175
/>

extensions/ql-vscode/src/view/method-modeling/__tests__/MethodModelingInputs.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe(MethodModelingInputs.name, () => {
1717
const language = QueryLanguage.Java;
1818
const method = createMethod();
1919
const modeledMethod = createSinkModeledMethod();
20-
const modelingStatus = "unmodeled";
20+
const modelPending = false;
2121
const isModelingInProgress = false;
2222
const onChange = jest.fn();
2323

@@ -26,7 +26,7 @@ describe(MethodModelingInputs.name, () => {
2626
language,
2727
method,
2828
modeledMethod,
29-
modelingStatus,
29+
modelPending,
3030
isModelingInProgress,
3131
onChange,
3232
});
@@ -53,7 +53,7 @@ describe(MethodModelingInputs.name, () => {
5353
language,
5454
method,
5555
modeledMethod,
56-
modelingStatus,
56+
modelPending,
5757
isModelingInProgress,
5858
onChange,
5959
});
@@ -76,7 +76,7 @@ describe(MethodModelingInputs.name, () => {
7676
language,
7777
method,
7878
modeledMethod,
79-
modelingStatus,
79+
modelPending,
8080
isModelingInProgress,
8181
onChange,
8282
});
@@ -91,7 +91,7 @@ describe(MethodModelingInputs.name, () => {
9191
language={language}
9292
method={method}
9393
modeledMethod={updatedModeledMethod}
94-
modelingStatus={modelingStatus}
94+
modelPending={modelPending}
9595
isModelingInProgress={isModelingInProgress}
9696
onChange={onChange}
9797
/>,
@@ -121,7 +121,7 @@ describe(MethodModelingInputs.name, () => {
121121
language,
122122
method,
123123
modeledMethod,
124-
modelingStatus,
124+
modelPending,
125125
isModelingInProgress: true,
126126
onChange,
127127
});

0 commit comments

Comments
 (0)