Skip to content

Commit

Permalink
use multistep
Browse files Browse the repository at this point in the history
  • Loading branch information
dimacodota committed Dec 4, 2023
1 parent fc79ee4 commit a6a4c62
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
22 changes: 11 additions & 11 deletions src/tabnineChatWidget/extensionCommands/registerChatCommnmads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export function registerChatCommnmads(
commands.registerTextEditorCommand(
"tabnine.chat.commands.inline.action",
(textEditor: TextEditor) => {
const items = SLASH_COMANDS.map(({ label, description }) => ({
label,
description,
}));
const items = SLASH_COMANDS.map(
({ label, description, multistep, intent }) => ({
label,
description,
multistep,
intent,
})
);
void showInput(items).then((result) => {
const input =
SLASH_COMANDS.find(({ label }) => label === result)?.intent ||
result;

if (textEditor.selection.isEmpty) {
void getFuctionsSymbols(textEditor.document).then(
(relevantSymbols: SymbolInformation[]) => {
Expand All @@ -66,10 +66,10 @@ export function registerChatCommnmads(
}
}
);
}

if (input) {
void chatProvider.handleMessageSubmitted(input);
if (result) {
void chatProvider.handleMessageSubmitted(result);
}
}
});
}
Expand Down
53 changes: 39 additions & 14 deletions src/tabnineChatWidget/extensionCommands/showInput.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
import { window, QuickPickItem } from "vscode";
import { QuickPickItem, window } from "vscode";

export function showInput(
items: QuickPickItem[] = []
): Promise<string | undefined> {
export function showInput<
T extends QuickPickItem & { multistep: boolean; intent: string }
>(items: T[] = []): Promise<string | undefined> {
return new Promise((resolve) => {
const view = window.createQuickPick();
const view = window.createQuickPick<T>();
view.items = items;
view.placeholder = `Ask Tabnine ${
view.title = "Ask Tabnine";
view.canSelectMany = false;
view.ignoreFocusOut = true;
view.placeholder = `Type your question${
items.length ? " or select from the list" : ""
}`;
view.onDidAccept(() => {
view.dispose();
if (view.selectedItems.length) {
resolve(view.selectedItems[0].label);
}
resolve(view.value);
view.hide();
});

view.onDidHide(() => {
setImmediate(() => {
if (view.selectedItems.length) {
if (view.selectedItems[0].multistep) {
void window
.showInputBox({
placeHolder: view.selectedItems[0].description,
ignoreFocusOut: true,
})
.then(
(value) => {
if (value) {
resolve(`${view.selectedItems[0].intent} ${value}`);
} else {
resolve(undefined);
}
view.dispose();
},
() => {
resolve(undefined);
view.dispose();
}
);
} else {
resolve(view.selectedItems[0].intent);
view.dispose();
}
} else {
resolve(view.value);
view.dispose();
resolve(undefined);
});
}
});
view.show();
});
Expand Down
14 changes: 14 additions & 0 deletions src/tabnineChatWidget/extensionCommands/slashCommands.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
type SCOPE = "block" | "selection" | "none";
export type SlashCommand = {
label: string;
intent: string;
description: string;
scope: SCOPE[];
multistep: boolean;
};

export const SLASH_COMANDS: SlashCommand[] = [
{
label: "$(feedback) explain",
intent: "/explain-code",
description: "Explain the selected code",
scope: ["selection", "block"],
multistep: false,
},
{
label: "$(beaker) test",
intent: "/generate-test-for-code",
description: "Write tests for the selected code",
scope: ["block"],
multistep: false,
},
{
label: "$(checklist) document",
intent: "/document-code",
description: "Add documentation for the selected code",
scope: ["block"],
multistep: false,
},
{
label: "$(symbol-property) fix",
intent: "/fix-code",
description: "Find errors in the selected code and fix them",
scope: ["block"],
multistep: false,
},
{
label: "$(search) workspace",
intent: "/workspace",
description:
"Ask a question related to any code within your current workspace",
scope: ["none"],
multistep: true,
},
];

0 comments on commit a6a4c62

Please sign in to comment.