Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/ql-vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ export async function setAutogenerateQlPacks(choice: AutogenerateQLPacks) {
const MODEL_SETTING = new Setting("model", ROOT_SETTING);
const FLOW_GENERATION = new Setting("flowGeneration", MODEL_SETTING);
const LLM_GENERATION = new Setting("llmGeneration", MODEL_SETTING);
const SHOW_TYPE_MODELS = new Setting("showTypeModels", MODEL_SETTING);
const LLM_GENERATION_BATCH_SIZE = new Setting(
"llmGenerationBatchSize",
MODEL_SETTING,
Expand All @@ -743,6 +744,7 @@ const ENABLE_ACCESS_PATH_SUGGESTIONS = new Setting(
export interface ModelConfig {
flowGeneration: boolean;
llmGeneration: boolean;
showTypeModels: boolean;
getExtensionsDirectory(languageId: string): string | undefined;
enablePython: boolean;
enableAccessPathSuggestions: boolean;
Expand All @@ -761,6 +763,10 @@ export class ModelConfigListener extends ConfigListener implements ModelConfig {
return !!LLM_GENERATION.getValue<boolean>();
}

public get showTypeModels(): boolean {
return !!SHOW_TYPE_MODELS.getValue<boolean>();
}

/**
* Limits the number of candidates we send to the model in each request to avoid long requests.
* Note that the model may return fewer than this number of candidates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,37 @@ import type {
import type { BaseLogger } from "../../common/logging";
import type { AccessPathSuggestionRow } from "../suggestions";

// This is a subset of the model config that doesn't import the vscode module.
// It only includes settings that are actually used.
export type ModelConfig = {
showTypeModels: boolean;
};

/**
* This function creates a new model config object from the given model config object.
* The new model config object is a deep copy of the given model config object.
*
* @param modelConfig The model config object to create a new model config object from.
* In most cases, this is a `ModelConfigListener`.
*/
export function createModelConfig(modelConfig: ModelConfig): ModelConfig {
return {
showTypeModels: modelConfig.showTypeModels,
};
}

export const defaultModelConfig: ModelConfig = {
showTypeModels: false,
};

type GenerateMethodDefinition<T> = (method: T) => DataTuple[];
type ReadModeledMethod = (row: DataTuple[]) => ModeledMethod;

type IsHiddenContext = {
method: MethodDefinition;
config: ModelConfig;
};

export type ModelsAsDataLanguagePredicate<T> = {
extensiblePredicate: string;
supportedKinds?: string[];
Expand All @@ -30,6 +58,14 @@ export type ModelsAsDataLanguagePredicate<T> = {
supportedEndpointTypes?: EndpointType[];
generateMethodDefinition: GenerateMethodDefinition<T>;
readModeledMethod: ReadModeledMethod;

/**
* Controls whether this predicate is hidden for a certain method. This only applies to the UI.
* If not specified, the predicate is visible for all methods.
*
* @param method The method to check if the predicate is hidden for.
*/
isHidden?: (context: IsHiddenContext) => boolean;
};

type ParseGenerationResults = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export const ruby: ModelsAsDataLanguage = {
methodParameters: "",
};
},
isHidden: ({ config }) => !config.showTypeModels,
},
},
modelGeneration: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { DatabaseItem } from "../../databases/local-databases";
import type { ModelingEvents } from "../modeling-events";
import type { QueryLanguage } from "../../common/query-language";
import { tryGetQueryLanguage } from "../../common/query-language";
import { createModelConfig } from "../languages";

export class MethodModelingViewProvider extends AbstractWebviewViewProvider<
ToMethodModelingMessage,
Expand Down Expand Up @@ -46,6 +47,7 @@ export class MethodModelingViewProvider extends AbstractWebviewViewProvider<
t: "setMethodModelingPanelViewState",
viewState: {
language: this.language,
modelConfig: createModelConfig(this.modelConfig),
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { telemetryListener } from "../common/vscode/telemetry";
import type { ModelingStore } from "./modeling-store";
import type { ModelingEvents } from "./modeling-events";
import type { ModelsAsDataLanguage } from "./languages";
import { getModelsAsDataLanguage } from "./languages";
import { createModelConfig, getModelsAsDataLanguage } from "./languages";
import { runGenerateQueries } from "./generate";
import { ResponseError } from "vscode-jsonrpc";
import { LSPErrorCodes } from "vscode-languageclient";
Expand Down Expand Up @@ -456,6 +456,7 @@ export class ModelEditorView extends AbstractWebview<
mode: this.modelingStore.getMode(this.databaseItem),
showModeSwitchButton,
sourceArchiveAvailable,
modelConfig: createModelConfig(this.modelConfig),
},
});
}
Expand Down
3 changes: 3 additions & 0 deletions extensions/ql-vscode/src/model-editor/shared/view-state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ExtensionPack } from "./extension-pack";
import type { Mode } from "./mode";
import type { QueryLanguage } from "../../common/query-language";
import type { ModelConfig } from "../languages";

export interface ModelEditorViewState {
extensionPack: ExtensionPack;
Expand All @@ -11,8 +12,10 @@ export interface ModelEditorViewState {
mode: Mode;
showModeSwitchButton: boolean;
sourceArchiveAvailable: boolean;
modelConfig: ModelConfig;
}

export interface MethodModelingPanelViewState {
language: QueryLanguage | undefined;
modelConfig: ModelConfig;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createSinkModeledMethod } from "../../../test/factories/model-editor/mo
import { useState } from "react";
import type { ModeledMethod } from "../../model-editor/modeled-method";
import { QueryLanguage } from "../../common/query-language";
import { defaultModelConfig } from "../../model-editor/languages";

export default {
title: "Method Modeling/Method Modeling Inputs",
Expand Down Expand Up @@ -34,6 +35,7 @@ const Template: StoryFn<typeof MethodModelingInputsComponent> = (args) => {
language={QueryLanguage.Java}
modeledMethod={m}
onChange={onChange}
modelConfig={defaultModelConfig}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { VSCodeTag } from "@vscode/webview-ui-toolkit/react";
import { ReviewInEditorButton } from "./ReviewInEditorButton";
import { MultipleModeledMethodsPanel } from "./MultipleModeledMethodsPanel";
import type { QueryLanguage } from "../../common/query-language";
import type { ModelConfig } from "../../model-editor/languages";

const Container = styled.div`
padding-top: 0.5rem;
Expand Down Expand Up @@ -50,6 +51,7 @@ const UnsavedTag = ({ modelingStatus }: { modelingStatus: ModelingStatus }) => (

export type MethodModelingProps = {
language: QueryLanguage;
modelConfig: ModelConfig;
modelingStatus: ModelingStatus;
method: Method;
modeledMethods: ModeledMethod[];
Expand All @@ -60,6 +62,7 @@ export type MethodModelingProps = {

export const MethodModeling = ({
language,
modelConfig,
modelingStatus,
modeledMethods,
method,
Expand All @@ -80,6 +83,7 @@ export const MethodModeling = ({
</DependencyContainer>
<MultipleModeledMethodsPanel
language={language}
modelConfig={modelConfig}
method={method}
modeledMethods={modeledMethods}
isModelingInProgress={isModelingInProgress}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ModelOutputDropdown } from "../model-editor/ModelOutputDropdown";
import { ModelKindDropdown } from "../model-editor/ModelKindDropdown";
import { InProgressDropdown } from "../model-editor/InProgressDropdown";
import type { QueryLanguage } from "../../common/query-language";
import type { ModelConfig } from "../../model-editor/languages";

const Container = styled.div`
padding-top: 0.5rem;
Expand All @@ -24,6 +25,7 @@ const Name = styled.span`

export type MethodModelingInputsProps = {
language: QueryLanguage;
modelConfig: ModelConfig;
method: Method;
modeledMethod: ModeledMethod | undefined;
modelPending: boolean;
Expand All @@ -33,6 +35,7 @@ export type MethodModelingInputsProps = {

export const MethodModelingInputs = ({
language,
modelConfig,
method,
modeledMethod,
modelPending,
Expand All @@ -55,7 +58,7 @@ export const MethodModelingInputs = ({
{isModelingInProgress ? (
<InProgressDropdown />
) : (
<ModelTypeDropdown {...inputProps} />
<ModelTypeDropdown modelConfig={modelConfig} {...inputProps} />
)}
</Input>
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NotInModelingMode } from "./NotInModelingMode";
import { NoMethodSelected } from "./NoMethodSelected";
import type { MethodModelingPanelViewState } from "../../model-editor/shared/view-state";
import { MethodAlreadyModeled } from "./MethodAlreadyModeled";
import { defaultModelConfig } from "../../model-editor/languages";

type Props = {
initialViewState?: MethodModelingPanelViewState;
Expand Down Expand Up @@ -116,6 +117,7 @@ export function MethodModelingView({
return (
<MethodModeling
language={viewState?.language}
modelConfig={viewState?.modelConfig ?? defaultModelConfig}
modelingStatus={modelingStatus}
method={method}
modeledMethods={modeledMethods}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import type { QueryLanguage } from "../../common/query-language";
import { createEmptyModeledMethod } from "../../model-editor/modeled-method-empty";
import { sendTelemetry } from "../common/telemetry";
import type { ModelingStatus } from "../../model-editor/shared/modeling-status";
import type { ModelConfig } from "../../model-editor/languages";

export type MultipleModeledMethodsPanelProps = {
language: QueryLanguage;
modelConfig: ModelConfig;
method: Method;
modeledMethods: ModeledMethod[];
modelingStatus: ModelingStatus;
Expand Down Expand Up @@ -61,6 +63,7 @@ const ModificationActions = styled.div`

export const MultipleModeledMethodsPanel = ({
language,
modelConfig,
method,
modeledMethods,
modelingStatus,
Expand Down Expand Up @@ -157,6 +160,7 @@ export const MultipleModeledMethodsPanel = ({
{modeledMethods.length > 0 ? (
<MethodModelingInputs
language={language}
modelConfig={modelConfig}
method={method}
modeledMethod={modeledMethods[selectedIndex]}
modelPending={isModelPending(
Expand All @@ -170,6 +174,7 @@ export const MultipleModeledMethodsPanel = ({
) : (
<MethodModelingInputs
language={language}
modelConfig={modelConfig}
method={method}
modeledMethod={undefined}
modelPending={isModelPending(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MethodModeling } from "../MethodModeling";
import { createMethod } from "../../../../test/factories/model-editor/method-factories";
import { createSinkModeledMethod } from "../../../../test/factories/model-editor/modeled-method-factories";
import { QueryLanguage } from "../../../common/query-language";
import { defaultModelConfig } from "../../../model-editor/languages";

describe(MethodModeling.name, () => {
const render = (props: MethodModelingProps) =>
Expand All @@ -18,6 +19,7 @@ describe(MethodModeling.name, () => {

render({
language: QueryLanguage.Java,
modelConfig: defaultModelConfig,
modelingStatus: "saved",
method,
modeledMethods: [modeledMethod],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "../../../../test/factories/model-editor/modeled-method-factories";
import { QueryLanguage } from "../../../common/query-language";
import { createEmptyModeledMethod } from "../../../model-editor/modeled-method-empty";
import { defaultModelConfig } from "../../../model-editor/languages";

describe(MethodModelingInputs.name, () => {
const render = (props: MethodModelingInputsProps) =>
Expand All @@ -19,6 +20,7 @@ describe(MethodModelingInputs.name, () => {
const modeledMethod = createSinkModeledMethod();
const modelPending = false;
const isModelingInProgress = false;
const modelConfig = defaultModelConfig;
const onChange = jest.fn();

it("renders the method modeling inputs", () => {
Expand All @@ -28,6 +30,7 @@ describe(MethodModelingInputs.name, () => {
modeledMethod,
modelPending,
isModelingInProgress,
modelConfig,
onChange,
});

Expand Down Expand Up @@ -55,6 +58,7 @@ describe(MethodModelingInputs.name, () => {
modeledMethod,
modelPending,
isModelingInProgress,
modelConfig,
onChange,
});

Expand All @@ -78,6 +82,7 @@ describe(MethodModelingInputs.name, () => {
modeledMethod,
modelPending,
isModelingInProgress,
modelConfig,
onChange,
});

Expand All @@ -93,6 +98,7 @@ describe(MethodModelingInputs.name, () => {
modeledMethod={updatedModeledMethod}
modelPending={modelPending}
isModelingInProgress={isModelingInProgress}
modelConfig={modelConfig}
onChange={onChange}
/>,
);
Expand Down Expand Up @@ -123,6 +129,7 @@ describe(MethodModelingInputs.name, () => {
modeledMethod,
modelPending,
isModelingInProgress: true,
modelConfig,
onChange,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { userEvent } from "@testing-library/user-event";
import type { ModeledMethod } from "../../../model-editor/modeled-method";
import { QueryLanguage } from "../../../common/query-language";
import type { ModelingStatus } from "../../../model-editor/shared/modeling-status";
import { defaultModelConfig } from "../../../model-editor/languages";

describe(MultipleModeledMethodsPanel.name, () => {
const language = QueryLanguage.Java;
Expand All @@ -19,12 +20,14 @@ describe(MultipleModeledMethodsPanel.name, () => {
const isProcessedByAutoModel = false;
const modelingStatus: ModelingStatus = "unmodeled";
const onChange = jest.fn<void, [string, ModeledMethod[]]>();
const modelConfig = defaultModelConfig;

const baseProps = {
language,
method,
modelingStatus,
isModelingInProgress,
modelConfig,
isProcessedByAutoModel,
onChange,
};
Expand Down
Loading