Skip to content

Commit 46a15bf

Browse files
authored
Add dummy model evaluation buttons to model editor (github#3381)
1 parent 3598b18 commit 46a15bf

File tree

6 files changed

+103
-1
lines changed

6 files changed

+103
-1
lines changed

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/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/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/view/model-editor/ModelEditor.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,50 @@ const ButtonsContainer = styled.div`
7474
margin-top: 1rem;
7575
`;
7676

77+
const ModelEvaluation = ({
78+
viewState,
79+
modeledMethods,
80+
modifiedSignatures,
81+
onStartEvaluation,
82+
onStopEvaluation,
83+
evaluationInProgress,
84+
}: {
85+
viewState: ModelEditorViewState;
86+
modeledMethods: Record<string, ModeledMethod[]>;
87+
modifiedSignatures: Set<string>;
88+
onStartEvaluation: () => void;
89+
onStopEvaluation: () => void;
90+
evaluationInProgress: boolean;
91+
}) => {
92+
if (!viewState.showEvaluationUi) {
93+
return null;
94+
}
95+
96+
if (!evaluationInProgress) {
97+
const customModelsExist = Object.values(modeledMethods).some(
98+
(methods) => methods.filter((m) => m.type !== "none").length > 0,
99+
);
100+
101+
const unsavedChanges = modifiedSignatures.size > 0;
102+
103+
return (
104+
<VSCodeButton
105+
onClick={onStartEvaluation}
106+
appearance="secondary"
107+
disabled={!customModelsExist || unsavedChanges}
108+
>
109+
Evaluate
110+
</VSCodeButton>
111+
);
112+
} else {
113+
return (
114+
<VSCodeButton onClick={onStopEvaluation} appearance="secondary">
115+
Stop evaluation
116+
</VSCodeButton>
117+
);
118+
}
119+
};
120+
77121
type Props = {
78122
initialViewState?: ModelEditorViewState;
79123
initialMethods?: Method[];
@@ -114,6 +158,8 @@ export function ModelEditor({
114158
string | null
115159
>(null);
116160

161+
const [evaluationInProgress, setEvaluationInProgress] = useState(false);
162+
117163
useEffect(() => {
118164
vscode.postMessage({
119165
t: "hideModeledMethods",
@@ -254,6 +300,20 @@ export function ModelEditor({
254300
[selectedSignatures],
255301
);
256302

303+
const onStartEvaluation = useCallback(() => {
304+
setEvaluationInProgress(true);
305+
vscode.postMessage({
306+
t: "startModelEvaluation",
307+
});
308+
}, []);
309+
310+
const onStopEvaluation = useCallback(() => {
311+
setEvaluationInProgress(false);
312+
vscode.postMessage({
313+
t: "stopModelEvaluation",
314+
});
315+
}, []);
316+
257317
const onGenerateFromSourceClick = useCallback(() => {
258318
vscode.postMessage({
259319
t: "generateMethod",
@@ -373,6 +433,14 @@ export function ModelEditor({
373433
Generate
374434
</VSCodeButton>
375435
)}
436+
<ModelEvaluation
437+
viewState={viewState}
438+
modeledMethods={modeledMethods}
439+
modifiedSignatures={modifiedSignatures}
440+
onStartEvaluation={onStartEvaluation}
441+
onStopEvaluation={onStopEvaluation}
442+
evaluationInProgress={evaluationInProgress}
443+
/>
376444
</ButtonsContainer>
377445
</HeaderRow>
378446
</HeaderColumn>

extensions/ql-vscode/test/factories/model-editor/view-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export function createMockModelEditorViewState(
1111
mode: Mode.Application,
1212
showGenerateButton: false,
1313
showLlmButton: false,
14+
showEvaluationUi: false,
1415
showModeSwitchButton: true,
1516
extensionPack: createMockExtensionPack(),
1617
sourceArchiveAvailable: true,

0 commit comments

Comments
 (0)