Skip to content

Commit d9ae0c6

Browse files
Disable the automodel button if there are no methods that can be modeled
1 parent dbdb561 commit d9ae0c6

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

extensions/ql-vscode/src/view/model-editor/LibraryRow.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "@vscode/webview-ui-toolkit/react";
1515
import type { ModelEditorViewState } from "../../model-editor/shared/view-state";
1616
import type { AccessPathSuggestionOptions } from "../../model-editor/suggestions";
17+
import { getCandidates } from "../../model-editor/auto-model";
1718

1819
const LibraryContainer = styled.div`
1920
background-color: var(--vscode-peekViewResult-background);
@@ -186,6 +187,17 @@ export const LibraryRow = ({
186187
return methods.some((method) => inProgressMethods.has(method.signature));
187188
}, [methods, inProgressMethods]);
188189

190+
const modelWithAIDisabled = useMemo(() => {
191+
return (
192+
getCandidates(
193+
viewState.mode,
194+
methods,
195+
modeledMethodsMap,
196+
processedByAutoModelMethods,
197+
).length === 0
198+
);
199+
}, [methods, modeledMethodsMap, processedByAutoModelMethods, viewState.mode]);
200+
189201
return (
190202
<LibraryContainer>
191203
<TitleContainer onClick={toggleExpanded} aria-expanded={isExpanded}>
@@ -205,7 +217,11 @@ export const LibraryRow = ({
205217
{hasUnsavedChanges ? <VSCodeTag>UNSAVED</VSCodeTag> : null}
206218
</NameContainer>
207219
{viewState.showLlmButton && !canStopAutoModeling && (
208-
<VSCodeButton appearance="icon" onClick={handleModelWithAI}>
220+
<VSCodeButton
221+
appearance="icon"
222+
disabled={modelWithAIDisabled}
223+
onClick={handleModelWithAI}
224+
>
209225
<Codicon name="lightbulb-autofix" label="Model with AI" />
210226
&nbsp;Model with AI
211227
</VSCodeButton>

0 commit comments

Comments
 (0)