Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add commands to ask sourcery menu #228

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/ask-sourcery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now handled by the back end

vscode.commands.executeCommand("sourcery.coding_assistant", {
message,
ideState: {
Expand All @@ -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];
Expand All @@ -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;
}
});
Expand Down
Loading