Use selected language when creating query
This will change the "Create new query" command to use the selected language when creating a new query. If no language is selected, it will still prompt the user to pick a language.
This commit is contained in:
Родитель
0a75a0e835
Коммит
8b5329fe08
|
@ -930,6 +930,7 @@ async function activateWithInstalledDistribution(
|
|||
databaseUI,
|
||||
localQueryResultsView,
|
||||
queryStorageDir,
|
||||
languageContext,
|
||||
);
|
||||
ctx.subscriptions.push(localQueries);
|
||||
|
||||
|
|
|
@ -67,4 +67,12 @@ export class LanguageContextStore extends DisposableObject {
|
|||
this.languageFilter === language
|
||||
);
|
||||
}
|
||||
|
||||
public get selectedLanguage(): QueryLanguage | undefined {
|
||||
if (this.languageFilter === "All") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return this.languageFilter;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ import { createMultiSelectionCommand } from "../common/vscode/selection-commands
|
|||
import { findLanguage } from "../codeql-cli/query-language";
|
||||
import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
|
||||
import { tryGetQueryLanguage } from "../common/query-language";
|
||||
import { LanguageContextStore } from "../language-context-store";
|
||||
|
||||
interface DatabaseQuickPickItem extends QuickPickItem {
|
||||
databaseItem: DatabaseItem;
|
||||
|
@ -71,6 +72,7 @@ export class LocalQueries extends DisposableObject {
|
|||
private readonly databaseUI: DatabaseUI,
|
||||
private readonly localQueryResultsView: ResultsView,
|
||||
private readonly queryStorageDir: string,
|
||||
private readonly languageContextStore: LanguageContextStore,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
@ -323,6 +325,7 @@ export class LocalQueries extends DisposableObject {
|
|||
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||
const contextStoragePath =
|
||||
this.app.workspaceStoragePath || this.app.globalStoragePath;
|
||||
const language = this.languageContextStore.selectedLanguage;
|
||||
const skeletonQueryWizard = new SkeletonQueryWizard(
|
||||
this.cliServer,
|
||||
progress,
|
||||
|
@ -330,6 +333,7 @@ export class LocalQueries extends DisposableObject {
|
|||
this.app.logger,
|
||||
this.databaseManager,
|
||||
contextStoragePath,
|
||||
language,
|
||||
);
|
||||
await skeletonQueryWizard.execute();
|
||||
},
|
||||
|
|
|
@ -41,7 +41,6 @@ export const QUERY_LANGUAGE_TO_DATABASE_REPO: QueryLanguagesToDatabaseMap = {
|
|||
};
|
||||
|
||||
export class SkeletonQueryWizard {
|
||||
private language: QueryLanguage | undefined;
|
||||
private fileName = "example.ql";
|
||||
private qlPackStoragePath: string | undefined;
|
||||
|
||||
|
@ -52,6 +51,7 @@ export class SkeletonQueryWizard {
|
|||
private readonly logger: BaseLogger,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseStoragePath: string | undefined,
|
||||
private language: QueryLanguage | undefined = undefined,
|
||||
) {}
|
||||
|
||||
private get folderName() {
|
||||
|
@ -59,8 +59,11 @@ export class SkeletonQueryWizard {
|
|||
}
|
||||
|
||||
public async execute() {
|
||||
// show quick pick to choose language
|
||||
this.language = await this.chooseLanguage();
|
||||
if (!this.language) {
|
||||
// show quick pick to choose language
|
||||
this.language = await this.chooseLanguage();
|
||||
}
|
||||
|
||||
if (!this.language) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import * as databaseFetcher from "../../../../src/databases/database-fetcher";
|
|||
import { createMockDB } from "../../../factories/databases/databases";
|
||||
import { asError } from "../../../../src/common/helpers-pure";
|
||||
import { Setting } from "../../../../src/config";
|
||||
import { QueryLanguage } from "../../../../src/common/query-language";
|
||||
|
||||
describe("SkeletonQueryWizard", () => {
|
||||
let mockCli: CodeQLCliServer;
|
||||
|
@ -134,6 +135,27 @@ describe("SkeletonQueryWizard", () => {
|
|||
expect(quickPickSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("with language", () => {
|
||||
beforeEach(() => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
extLogger,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
QueryLanguage.Swift,
|
||||
);
|
||||
});
|
||||
|
||||
it("should not prompt for language", async () => {
|
||||
await wizard.execute();
|
||||
|
||||
expect(mockCli.getSupportedLanguages).not.toHaveBeenCalled();
|
||||
expect(quickPickSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("if QL pack doesn't exist", () => {
|
||||
beforeEach(() => {
|
||||
jest
|
||||
|
|
Загрузка…
Ссылка в новой задаче