Add database language check to data extensions editor

This will not allow the user to open the data extensions editor for a
database if it is not one of the supported languages. The supported
languages is a list of `string` rather than a list of `QueryLanguage`
because a database item's language is also a `string`.
This commit is contained in:
Koen Vlaswinkel
2023-04-17 14:38:15 +02:00
parent 1367d386db
commit 79c39a0826

View File

@@ -11,6 +11,8 @@ import { showAndLogErrorMessage } from "../helpers";
import { withProgress } from "../progress";
import { pickExtensionPackModelFile } from "./extension-pack-picker";
const SUPPORTED_LANGUAGES: string[] = ["java", "csharp"];
export class DataExtensionsEditorModule {
private readonly queryStorageDir: string;
@@ -51,15 +53,22 @@ export class DataExtensionsEditorModule {
public getCommands(): DataExtensionsEditorCommands {
return {
"codeQL.openDataExtensionsEditor": async () =>
withProgress(
async (progress, token) => {
const db = this.databaseManager.currentDatabaseItem;
if (!db) {
void showAndLogErrorMessage("No database selected");
return;
}
"codeQL.openDataExtensionsEditor": async () => {
const db = this.databaseManager.currentDatabaseItem;
if (!db) {
void showAndLogErrorMessage("No database selected");
return;
}
if (!SUPPORTED_LANGUAGES.includes(db.language)) {
void showAndLogErrorMessage(
`The data extensions editor is not supported for ${db.language} databases.`,
);
return;
}
return withProgress(
async (progress, token) => {
if (!(await this.cliServer.cliConstraints.supportsQlpacksKind())) {
void showAndLogErrorMessage(
`This feature requires CodeQL CLI version ${CliVersionConstraint.CLI_VERSION_WITH_QLPACKS_KIND.format()} or later.`,
@@ -92,7 +101,8 @@ export class DataExtensionsEditorModule {
{
title: "Opening Data Extensions Editor",
},
),
);
},
};
}