diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 38cb8852a..a8484c105 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -11,7 +11,9 @@ import { streamEdit, verticalPerLineDiffManager, } from "./diff/verticalPerLine/manager"; +import { VsCodeIde } from "./ideProtocol"; import { AutocompleteOutcome } from "./lang-server/completionProvider"; +import { configHandler, llmFromTitle } from "./loadConfig"; function addHighlightedCodeToContext(edit: boolean) { const editor = vscode.window.activeTextEditor; @@ -152,14 +154,84 @@ const commandsMap: { [command: string]: (...args: any) => any } = { }, "continue.quickEdit": async () => { const selectionEmpty = vscode.window.activeTextEditor?.selection.isEmpty; - const text = await vscode.window.showInputBox({ + + let text = await vscode.window.showInputBox({ placeHolder: selectionEmpty - ? "Describe the code you want to generate" - : "Describe how to edit the highlighted code", + ? "Describe the code you want to generate (or press enter to add context first)" + : "Describe how to edit the highlighted code (or press enter to add context first)", title: "Continue Quick Edit", }); - if (text) { + + if (text === undefined) { + return; + } + + if (text.length > 0) { await streamEdit(text); + } else { + // Pick context first + const quickPickItems: Promise = configHandler + .loadConfig() + .then((config) => { + return ( + config.contextProviders + ?.filter((provider) => provider.description.type === "normal") + .map((provider) => { + return { + label: provider.description.displayTitle, + description: provider.description.title, + detail: provider.description.description, + }; + }) || [] + ); + }); + + const selectedProviders = await vscode.window.showQuickPick( + quickPickItems, + { + title: "Add Context", + canPickMany: true, + } + ); + + let text = await vscode.window.showInputBox({ + placeHolder: selectionEmpty + ? "Describe the code you want to generate (or press enter to add context first)" + : "Describe how to edit the highlighted code (or press enter to add context first)", + title: "Continue Quick Edit", + }); + if (text) { + const llm = await llmFromTitle(); + const config = await configHandler.loadConfig(); + const context = ( + await Promise.all( + selectedProviders?.map((providerTitle) => { + const provider = config.contextProviders?.find( + (provider) => + provider.description.title === providerTitle.description + ); + if (!provider) { + return []; + } + + return provider.getContextItems("", { + embeddingsProvider: config.embeddingsProvider, + ide: new VsCodeIde(), + llm, + fullInput: text || "", + selectedCode: [], + }); + }) || [] + ) + ).flat(); + + text = + context.map((item) => item.content).join("\n\n") + + "\n\n---\n\n" + + text; + + await streamEdit(text); + } } }, "continue.writeCommentsForCode": async () => {