Use language display name when asking for language
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
import { CodeQLCliServer } from "./cli";
|
import { CodeQLCliServer } from "./cli";
|
||||||
import { Uri, window } from "vscode";
|
import { Uri, window } from "vscode";
|
||||||
import { isQueryLanguage, QueryLanguage } from "../common/query-language";
|
import {
|
||||||
|
getLanguageDisplayName,
|
||||||
|
isQueryLanguage,
|
||||||
|
QueryLanguage,
|
||||||
|
} from "../common/query-language";
|
||||||
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
||||||
import { extLogger } from "../common/logging/vscode";
|
import { extLogger } from "../common/logging/vscode";
|
||||||
import { UserCancellationException } from "../common/vscode/progress";
|
import { UserCancellationException } from "../common/vscode/progress";
|
||||||
@@ -46,14 +50,22 @@ export async function askForLanguage(
|
|||||||
cliServer: CodeQLCliServer,
|
cliServer: CodeQLCliServer,
|
||||||
throwOnEmpty = true,
|
throwOnEmpty = true,
|
||||||
): Promise<QueryLanguage | undefined> {
|
): Promise<QueryLanguage | undefined> {
|
||||||
const language = await window.showQuickPick(
|
const supportedLanguages = await cliServer.getSupportedLanguages();
|
||||||
await cliServer.getSupportedLanguages(),
|
|
||||||
{
|
const items = supportedLanguages
|
||||||
placeHolder: "Select target language for your query",
|
.filter((language) => isQueryLanguage(language))
|
||||||
ignoreFocusOut: true,
|
.map((language) => ({
|
||||||
},
|
label: getLanguageDisplayName(language),
|
||||||
);
|
description: language,
|
||||||
if (!language) {
|
language,
|
||||||
|
}))
|
||||||
|
.sort((a, b) => a.label.localeCompare(b.label));
|
||||||
|
|
||||||
|
const selectedItem = await window.showQuickPick(items, {
|
||||||
|
placeHolder: "Select target language for your query",
|
||||||
|
ignoreFocusOut: true,
|
||||||
|
});
|
||||||
|
if (!selectedItem) {
|
||||||
// This only happens if the user cancels the quick pick.
|
// This only happens if the user cancels the quick pick.
|
||||||
if (throwOnEmpty) {
|
if (throwOnEmpty) {
|
||||||
throw new UserCancellationException("Cancelled.");
|
throw new UserCancellationException("Cancelled.");
|
||||||
@@ -66,6 +78,8 @@ export async function askForLanguage(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const language = selectedItem.language;
|
||||||
|
|
||||||
if (!isQueryLanguage(language)) {
|
if (!isQueryLanguage(language)) {
|
||||||
void showAndLogErrorMessage(
|
void showAndLogErrorMessage(
|
||||||
extLogger,
|
extLogger,
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
mockCli = mockedObject<CodeQLCliServer>({
|
mockCli = mockedObject<CodeQLCliServer>({
|
||||||
resolveLanguages: jest
|
getSupportedLanguages: jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockResolvedValue([
|
.mockResolvedValue([
|
||||||
"ruby",
|
"ruby",
|
||||||
@@ -76,7 +76,6 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
"csharp",
|
"csharp",
|
||||||
"cpp",
|
"cpp",
|
||||||
]),
|
]),
|
||||||
getSupportedLanguages: jest.fn(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mockDatabaseManager = mockedObject<DatabaseManager>({
|
mockDatabaseManager = mockedObject<DatabaseManager>({
|
||||||
@@ -102,9 +101,12 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
},
|
},
|
||||||
] as WorkspaceFolder[]);
|
] as WorkspaceFolder[]);
|
||||||
|
|
||||||
quickPickSpy = jest
|
quickPickSpy = jest.spyOn(window, "showQuickPick").mockResolvedValueOnce(
|
||||||
.spyOn(window, "showQuickPick")
|
mockedQuickPickItem({
|
||||||
.mockResolvedValueOnce(mockedQuickPickItem(chosenLanguage));
|
label: chosenLanguage,
|
||||||
|
language: chosenLanguage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
showInputBoxSpy = jest
|
showInputBoxSpy = jest
|
||||||
.spyOn(window, "showInputBox")
|
.spyOn(window, "showInputBox")
|
||||||
.mockResolvedValue(storagePath);
|
.mockResolvedValue(storagePath);
|
||||||
|
|||||||
@@ -79,9 +79,12 @@ describe("Variant Analysis Manager", () => {
|
|||||||
).fsPath;
|
).fsPath;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jest
|
jest.spyOn(window, "showQuickPick").mockResolvedValueOnce(
|
||||||
.spyOn(window, "showQuickPick")
|
mockedQuickPickItem({
|
||||||
.mockResolvedValueOnce(mockedQuickPickItem("javascript"));
|
label: "JavaScript",
|
||||||
|
language: "javascript",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
cancellationTokenSource = new CancellationTokenSource();
|
cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,12 @@ describe("Variant Analysis Submission Integration", () => {
|
|||||||
await showQlDocument("query.ql");
|
await showQlDocument("query.ql");
|
||||||
|
|
||||||
// Select target language for your query
|
// Select target language for your query
|
||||||
quickPickSpy.mockResolvedValueOnce(mockedQuickPickItem("javascript"));
|
quickPickSpy.mockResolvedValueOnce(
|
||||||
|
mockedQuickPickItem({
|
||||||
|
label: "JavaScript",
|
||||||
|
language: "javascript",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
await commandManager.execute("codeQL.runVariantAnalysis");
|
await commandManager.execute("codeQL.runVariantAnalysis");
|
||||||
|
|
||||||
@@ -106,7 +111,12 @@ describe("Variant Analysis Submission Integration", () => {
|
|||||||
await showQlDocument("query.ql");
|
await showQlDocument("query.ql");
|
||||||
|
|
||||||
// Select target language for your query
|
// Select target language for your query
|
||||||
quickPickSpy.mockResolvedValueOnce(mockedQuickPickItem("javascript"));
|
quickPickSpy.mockResolvedValueOnce(
|
||||||
|
mockedQuickPickItem({
|
||||||
|
label: "JavaScript",
|
||||||
|
language: "javascript",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
await commandManager.execute("codeQL.runVariantAnalysis");
|
await commandManager.execute("codeQL.runVariantAnalysis");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user