From ccb5092939a06c4e349096fb88ac1fcbe977dccb Mon Sep 17 00:00:00 2001 From: Hellebore Date: Tue, 26 Sep 2023 09:31:09 +0100 Subject: [PATCH] add commands to ask sourcery menu --- src/ask-sourcery.ts | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/ask-sourcery.ts b/src/ask-sourcery.ts index fee93b0a..2226766f 100644 --- a/src/ask-sourcery.ts +++ b/src/ask-sourcery.ts @@ -3,8 +3,13 @@ import { Recipe } from "./chat"; export function askSourceryCommand(recipes: Recipe[], contextRange?) { showAskSourceryQuickPick(recipes).then((result: any) => { + if (result.type === "command") { + vscode.commands.executeCommand(result.id); + return; + } + let message; - if ("id" in result) { + if (result.type === "recipe") { // the user selected a specific recipe message = { target: "languageServer", @@ -24,12 +29,6 @@ export function askSourceryCommand(recipes: Recipe[], contextRange?) { }; } - // Open the chat window. - // This command is automatically generated by the extension based on the - // views in the package.json file. It's used here to make sure that the - // chat window opens after we've "Ask[ed] Sourcery" for something. - vscode.commands.executeCommand("sourcery.chat.focus"); - vscode.commands.executeCommand("sourcery.coding_assistant", { message, ideState: { @@ -44,15 +43,27 @@ export function askSourceryCommand(recipes: Recipe[], contextRange?) { export function showAskSourceryQuickPick(recipes: Recipe[]) { return new Promise((resolve) => { const recipeNames = recipes.map((item) => item.name); - const recipeItems = recipes.map((item) => ({ + const quickPickItems = recipes.map((item) => ({ label: item.name, id: item.id, + type: "recipe", })); + quickPickItems.push({ + label: "Sourcery: Login", + type: "command", + id: "sourcery.login", + }); + quickPickItems.push({ + label: "Sourcery: Toggle Code Lens for Coding Assistant", + type: "command", + id: "sourcery.chat.toggleCodeLens", + }); + const quickPick = vscode.window.createQuickPick(); quickPick.placeholder = - "Ask Sourcery a question or choose one of these recipes"; - quickPick.items = recipeItems; + "Ask Sourcery a question or choose one of these options"; + quickPick.items = quickPickItems; quickPick.onDidAccept(() => { const selection = quickPick.activeItems[0]; @@ -63,7 +74,10 @@ export function showAskSourceryQuickPick(recipes: Recipe[]) { quickPick.onDidChangeValue(() => { // add what the user has typed to the pick list as the first item if (!recipeNames.includes(quickPick.value)) { - const newItems = [{ label: quickPick.value }, ...recipeItems]; + const newItems = [ + { label: quickPick.value, type: "chat" }, + ...quickPickItems, + ]; quickPick.items = newItems; } });