Add feature flag for Python model editor (#3351)

This commit is contained in:
Shati Patel
2024-02-13 14:02:13 +00:00
committed by GitHub
parent 923a480ddd
commit 70b8ddfa37
3 changed files with 20 additions and 2 deletions

View File

@@ -716,6 +716,7 @@ const LLM_GENERATION_DEV_ENDPOINT = new Setting(
MODEL_SETTING,
);
const EXTENSIONS_DIRECTORY = new Setting("extensionsDirectory", MODEL_SETTING);
const ENABLE_PYTHON = new Setting("enablePython", MODEL_SETTING);
const ENABLE_ACCESS_PATH_SUGGESTIONS = new Setting(
"enableAccessPathSuggestions",
MODEL_SETTING,
@@ -725,6 +726,7 @@ export interface ModelConfig {
flowGeneration: boolean;
llmGeneration: boolean;
getExtensionsDirectory(languageId: string): string | undefined;
enablePython: boolean;
enableAccessPathSuggestions: boolean;
}
@@ -763,6 +765,10 @@ export class ModelConfigListener extends ConfigListener implements ModelConfig {
});
}
public get enablePython(): boolean {
return !!ENABLE_PYTHON.getValue<boolean>();
}
public get enableAccessPathSuggestions(): boolean {
return !!ENABLE_ACCESS_PATH_SUGGESTIONS.getValue<boolean>();
}

View File

@@ -143,7 +143,10 @@ export class ModelEditorModule extends DisposableObject {
const language = db.language;
if (!isQueryLanguage(language) || !isSupportedLanguage(language)) {
if (
!isQueryLanguage(language) ||
!isSupportedLanguage(language, this.modelConfig)
) {
void showAndLogErrorMessage(
this.app.logger,
`The CodeQL Model Editor is not supported for ${language} databases.`,

View File

@@ -1,4 +1,5 @@
import { QueryLanguage } from "../common/query-language";
import type { ModelConfig } from "../config";
import { isCanary } from "../config";
/**
@@ -10,7 +11,10 @@ export const SUPPORTED_LANGUAGES: QueryLanguage[] = [
QueryLanguage.CSharp,
];
export function isSupportedLanguage(language: QueryLanguage) {
export function isSupportedLanguage(
language: QueryLanguage,
modelConfig: ModelConfig,
) {
if (SUPPORTED_LANGUAGES.includes(language)) {
return true;
}
@@ -20,5 +24,10 @@ export function isSupportedLanguage(language: QueryLanguage) {
return isCanary();
}
if (language === QueryLanguage.Python) {
// Python is only enabled when the config setting is set
return modelConfig.enablePython;
}
return false;
}