Use `showTypeModels` setting instead of canary mode
This commit is contained in:
Родитель
32d981ace4
Коммит
7dceded98c
|
@ -70,7 +70,7 @@ export type ModelsAsDataLanguagePredicate<T> = {
|
|||
|
||||
export type GenerationContext = {
|
||||
mode: Mode;
|
||||
isCanary: boolean;
|
||||
config: ModelConfig;
|
||||
};
|
||||
|
||||
type ParseGenerationResults = (
|
||||
|
|
|
@ -12,7 +12,7 @@ export function parseGenerateModelResults(
|
|||
bqrs: DecodedBqrs,
|
||||
modelsAsDataLanguage: ModelsAsDataLanguage,
|
||||
logger: BaseLogger,
|
||||
{ isCanary }: GenerationContext,
|
||||
{ config }: GenerationContext,
|
||||
): ModeledMethod[] {
|
||||
const modeledMethods: ModeledMethod[] = [];
|
||||
|
||||
|
@ -20,10 +20,10 @@ export function parseGenerateModelResults(
|
|||
if (
|
||||
resultSetName ===
|
||||
modelsAsDataLanguage.predicates.type?.extensiblePredicate &&
|
||||
!isCanary
|
||||
!config.showTypeModels
|
||||
) {
|
||||
// Don't load generated type results in non-canary mode. These are already automatically
|
||||
// generated on start-up.
|
||||
// Don't load generated type results when type models are hidden. These are already
|
||||
// automatically generated on start-up.
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -209,8 +209,9 @@ export const ruby: ModelsAsDataLanguage = {
|
|||
},
|
||||
];
|
||||
},
|
||||
// Only enabled for framework mode in non-canary
|
||||
enabled: ({ mode, isCanary }) => mode === Mode.Framework && !isCanary,
|
||||
// Only enabled for framework mode when type models are hidden
|
||||
enabled: ({ mode, config }) =>
|
||||
mode === Mode.Framework && !config.showTypeModels,
|
||||
},
|
||||
accessPathSuggestions: {
|
||||
queryConstraints: (mode) => ({
|
||||
|
|
|
@ -40,7 +40,6 @@ import type { Method } from "./method";
|
|||
import type { ModeledMethod } from "./modeled-method";
|
||||
import type { ExtensionPack } from "./shared/extension-pack";
|
||||
import type { ModelConfigListener } from "../config";
|
||||
import { isCanary } from "../config";
|
||||
import { Mode } from "./shared/mode";
|
||||
import {
|
||||
GENERATED_MODELS_SUFFIX,
|
||||
|
@ -273,6 +272,7 @@ export class ModelEditorView extends AbstractWebview<
|
|||
modeledMethods,
|
||||
mode,
|
||||
this.cliServer,
|
||||
this.modelConfig,
|
||||
this.app.logger,
|
||||
);
|
||||
|
||||
|
@ -490,6 +490,7 @@ export class ModelEditorView extends AbstractWebview<
|
|||
this.extensionPack,
|
||||
this.language,
|
||||
this.cliServer,
|
||||
this.modelConfig,
|
||||
this.app.logger,
|
||||
);
|
||||
this.modelingStore.setModeledMethods(this.databaseItem, modeledMethods);
|
||||
|
@ -663,7 +664,7 @@ export class ModelEditorView extends AbstractWebview<
|
|||
this.app.logger,
|
||||
{
|
||||
mode,
|
||||
isCanary: isCanary(),
|
||||
config: this.modelConfig,
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -701,7 +702,7 @@ export class ModelEditorView extends AbstractWebview<
|
|||
|
||||
if (
|
||||
autoModelGeneration.enabled &&
|
||||
!autoModelGeneration.enabled({ mode, isCanary: isCanary() })
|
||||
!autoModelGeneration.enabled({ mode, config: this.modelConfig })
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import { load as loadYaml } from "js-yaml";
|
|||
import type { CodeQLCliServer } from "../codeql-cli/cli";
|
||||
import { pathsEqual } from "../common/files";
|
||||
import type { QueryLanguage } from "../common/query-language";
|
||||
import { isCanary } from "../config";
|
||||
import type { ModelConfig } from "./languages";
|
||||
|
||||
export const GENERATED_MODELS_SUFFIX = ".model.generated.yml";
|
||||
|
||||
|
@ -23,12 +23,14 @@ export async function saveModeledMethods(
|
|||
modeledMethods: Readonly<Record<string, readonly ModeledMethod[]>>,
|
||||
mode: Mode,
|
||||
cliServer: CodeQLCliServer,
|
||||
modelConfig: ModelConfig,
|
||||
logger: NotificationLogger,
|
||||
): Promise<void> {
|
||||
const existingModeledMethods = await loadModeledMethodFiles(
|
||||
extensionPack,
|
||||
language,
|
||||
cliServer,
|
||||
modelConfig,
|
||||
logger,
|
||||
);
|
||||
|
||||
|
@ -51,9 +53,14 @@ async function loadModeledMethodFiles(
|
|||
extensionPack: ExtensionPack,
|
||||
language: QueryLanguage,
|
||||
cliServer: CodeQLCliServer,
|
||||
modelConfig: ModelConfig,
|
||||
logger: NotificationLogger,
|
||||
): Promise<Record<string, Record<string, ModeledMethod[]>>> {
|
||||
const modelFiles = await listModelFiles(extensionPack.path, cliServer);
|
||||
const modelFiles = await listModelFiles(
|
||||
extensionPack.path,
|
||||
cliServer,
|
||||
modelConfig,
|
||||
);
|
||||
|
||||
const modeledMethodsByFile: Record<
|
||||
string,
|
||||
|
@ -85,6 +92,7 @@ export async function loadModeledMethods(
|
|||
extensionPack: ExtensionPack,
|
||||
language: QueryLanguage,
|
||||
cliServer: CodeQLCliServer,
|
||||
modelConfig: ModelConfig,
|
||||
logger: NotificationLogger,
|
||||
): Promise<Record<string, ModeledMethod[]>> {
|
||||
const existingModeledMethods: Record<string, ModeledMethod[]> = {};
|
||||
|
@ -93,6 +101,7 @@ export async function loadModeledMethods(
|
|||
extensionPack,
|
||||
language,
|
||||
cliServer,
|
||||
modelConfig,
|
||||
logger,
|
||||
);
|
||||
for (const modeledMethods of Object.values(modeledMethodsByFile)) {
|
||||
|
@ -111,6 +120,7 @@ export async function loadModeledMethods(
|
|||
export async function listModelFiles(
|
||||
extensionPackPath: string,
|
||||
cliServer: CodeQLCliServer,
|
||||
modelConfig: ModelConfig,
|
||||
): Promise<Set<string>> {
|
||||
const result = await cliServer.resolveExtensions(
|
||||
extensionPackPath,
|
||||
|
@ -121,8 +131,11 @@ export async function listModelFiles(
|
|||
for (const [path, extensions] of Object.entries(result.data)) {
|
||||
if (pathsEqual(path, extensionPackPath)) {
|
||||
for (const extension of extensions) {
|
||||
// We only load generated models in canary mode
|
||||
if (!isCanary() && extension.file.endsWith(GENERATED_MODELS_SUFFIX)) {
|
||||
// We only load generated models when type models are shown
|
||||
if (
|
||||
!modelConfig.showTypeModels &&
|
||||
extension.file.endsWith(GENERATED_MODELS_SUFFIX)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { createMockLogger } from "../../../../__mocks__/loggerMock";
|
|||
import type { ModeledMethod } from "../../../../../src/model-editor/modeled-method";
|
||||
import { EndpointType } from "../../../../../src/model-editor/method";
|
||||
import { Mode } from "../../../../../src/model-editor/shared/mode";
|
||||
import { defaultModelConfig } from "../../../../../src/model-editor/languages";
|
||||
|
||||
describe("parseGenerateModelResults", () => {
|
||||
it("should return the results", async () => {
|
||||
|
@ -78,8 +79,11 @@ describe("parseGenerateModelResults", () => {
|
|||
ruby,
|
||||
createMockLogger(),
|
||||
{
|
||||
isCanary: true,
|
||||
mode: Mode.Framework,
|
||||
config: {
|
||||
...defaultModelConfig,
|
||||
showTypeModels: true,
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result).toEqual([
|
||||
|
|
|
@ -13,6 +13,7 @@ import { homedir, tmpdir } from "os";
|
|||
import { mkdir, rm } from "fs-extra";
|
||||
import { nanoid } from "nanoid";
|
||||
import { QueryLanguage } from "../../../../src/common/query-language";
|
||||
import { defaultModelConfig } from "../../../../src/model-editor/languages";
|
||||
|
||||
const dummyExtensionPackContents = `
|
||||
name: dummy/pack
|
||||
|
@ -135,7 +136,11 @@ describe("modeled-method-fs", () => {
|
|||
it("should return the empty set when the extension pack is empty", async () => {
|
||||
const extensionPackPath = writeExtensionPackFiles("extension-pack", []);
|
||||
|
||||
const modelFiles = await listModelFiles(extensionPackPath, cli);
|
||||
const modelFiles = await listModelFiles(
|
||||
extensionPackPath,
|
||||
cli,
|
||||
defaultModelConfig,
|
||||
);
|
||||
expect(modelFiles).toEqual(new Set());
|
||||
});
|
||||
|
||||
|
@ -145,7 +150,11 @@ describe("modeled-method-fs", () => {
|
|||
"library2.model.yml",
|
||||
]);
|
||||
|
||||
const modelFiles = await listModelFiles(extensionPackPath, cli);
|
||||
const modelFiles = await listModelFiles(
|
||||
extensionPackPath,
|
||||
cli,
|
||||
defaultModelConfig,
|
||||
);
|
||||
expect(modelFiles).toEqual(
|
||||
new Set([
|
||||
join("models", "library1.model.yml"),
|
||||
|
@ -154,13 +163,57 @@ describe("modeled-method-fs", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("should ignore generated type models when type models are hidden", async () => {
|
||||
const extensionPackPath = writeExtensionPackFiles("extension-pack", [
|
||||
"library1.model.yml",
|
||||
"library2.model.yml",
|
||||
"library.model.generated.yml",
|
||||
]);
|
||||
|
||||
const modelFiles = await listModelFiles(
|
||||
extensionPackPath,
|
||||
cli,
|
||||
defaultModelConfig,
|
||||
);
|
||||
expect(modelFiles).toEqual(
|
||||
new Set([
|
||||
join("models", "library1.model.yml"),
|
||||
join("models", "library2.model.yml"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("should include generated type models when type models are shown", async () => {
|
||||
const extensionPackPath = writeExtensionPackFiles("extension-pack", [
|
||||
"library1.model.yml",
|
||||
"library2.model.yml",
|
||||
"library.model.generated.yml",
|
||||
]);
|
||||
|
||||
const modelFiles = await listModelFiles(extensionPackPath, cli, {
|
||||
...defaultModelConfig,
|
||||
showTypeModels: true,
|
||||
});
|
||||
expect(modelFiles).toEqual(
|
||||
new Set([
|
||||
join("models", "library.model.generated.yml"),
|
||||
join("models", "library1.model.yml"),
|
||||
join("models", "library2.model.yml"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("should ignore model files from other extension packs", async () => {
|
||||
const extensionPackPath = writeExtensionPackFiles("extension-pack", [
|
||||
"library1.model.yml",
|
||||
]);
|
||||
writeExtensionPackFiles("another-extension-pack", ["library2.model.yml"]);
|
||||
|
||||
const modelFiles = await listModelFiles(extensionPackPath, cli);
|
||||
const modelFiles = await listModelFiles(
|
||||
extensionPackPath,
|
||||
cli,
|
||||
defaultModelConfig,
|
||||
);
|
||||
expect(modelFiles).toEqual(
|
||||
new Set([join("models", "library1.model.yml")]),
|
||||
);
|
||||
|
@ -177,6 +230,7 @@ describe("modeled-method-fs", () => {
|
|||
makeExtensionPack(extensionPackPath),
|
||||
QueryLanguage.Java,
|
||||
cli,
|
||||
defaultModelConfig,
|
||||
extLogger,
|
||||
);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import { ruby } from "../../../../src/model-editor/languages/ruby";
|
|||
import type { ModeledMethod } from "../../../../src/model-editor/modeled-method";
|
||||
import { EndpointType } from "../../../../src/model-editor/method";
|
||||
import { Mode } from "../../../../src/model-editor/shared/mode";
|
||||
import { defaultModelConfig } from "../../../../src/model-editor/languages";
|
||||
|
||||
describe("runGenerateQueries", () => {
|
||||
const modelsAsDataLanguage = ruby;
|
||||
|
@ -136,8 +137,11 @@ describe("runGenerateQueries", () => {
|
|||
modelsAsDataLanguage,
|
||||
createMockLogger(),
|
||||
{
|
||||
isCanary: true,
|
||||
mode: Mode.Framework,
|
||||
config: {
|
||||
...defaultModelConfig,
|
||||
showTypeModels: true,
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче