Skip to content

Commit 70b8ddf

Browse files
authored
Add feature flag for Python model editor (#3351)
1 parent 923a480 commit 70b8ddf

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ const LLM_GENERATION_DEV_ENDPOINT = new Setting(
716716
MODEL_SETTING,
717717
);
718718
const EXTENSIONS_DIRECTORY = new Setting("extensionsDirectory", MODEL_SETTING);
719+
const ENABLE_PYTHON = new Setting("enablePython", MODEL_SETTING);
719720
const ENABLE_ACCESS_PATH_SUGGESTIONS = new Setting(
720721
"enableAccessPathSuggestions",
721722
MODEL_SETTING,
@@ -725,6 +726,7 @@ export interface ModelConfig {
725726
flowGeneration: boolean;
726727
llmGeneration: boolean;
727728
getExtensionsDirectory(languageId: string): string | undefined;
729+
enablePython: boolean;
728730
enableAccessPathSuggestions: boolean;
729731
}
730732

@@ -763,6 +765,10 @@ export class ModelConfigListener extends ConfigListener implements ModelConfig {
763765
});
764766
}
765767

768+
public get enablePython(): boolean {
769+
return !!ENABLE_PYTHON.getValue<boolean>();
770+
}
771+
766772
public get enableAccessPathSuggestions(): boolean {
767773
return !!ENABLE_ACCESS_PATH_SUGGESTIONS.getValue<boolean>();
768774
}

extensions/ql-vscode/src/model-editor/model-editor-module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ export class ModelEditorModule extends DisposableObject {
143143

144144
const language = db.language;
145145

146-
if (!isQueryLanguage(language) || !isSupportedLanguage(language)) {
146+
if (
147+
!isQueryLanguage(language) ||
148+
!isSupportedLanguage(language, this.modelConfig)
149+
) {
147150
void showAndLogErrorMessage(
148151
this.app.logger,
149152
`The CodeQL Model Editor is not supported for ${language} databases.`,

extensions/ql-vscode/src/model-editor/supported-languages.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { QueryLanguage } from "../common/query-language";
2+
import type { ModelConfig } from "../config";
23
import { isCanary } from "../config";
34

45
/**
@@ -10,7 +11,10 @@ export const SUPPORTED_LANGUAGES: QueryLanguage[] = [
1011
QueryLanguage.CSharp,
1112
];
1213

13-
export function isSupportedLanguage(language: QueryLanguage) {
14+
export function isSupportedLanguage(
15+
language: QueryLanguage,
16+
modelConfig: ModelConfig,
17+
) {
1418
if (SUPPORTED_LANGUAGES.includes(language)) {
1519
return true;
1620
}
@@ -20,5 +24,10 @@ export function isSupportedLanguage(language: QueryLanguage) {
2024
return isCanary();
2125
}
2226

27+
if (language === QueryLanguage.Python) {
28+
// Python is only enabled when the config setting is set
29+
return modelConfig.enablePython;
30+
}
31+
2332
return false;
2433
}

0 commit comments

Comments
 (0)