feat: impl /multifile-edit
This commit is contained in:
parent
f1c561fc28
commit
f88f28b855
12 changed files with 146 additions and 61 deletions
|
|
@ -4,9 +4,10 @@ import CommitMessageCommand from "./commit";
|
|||
import DraftIssueCommand from "./draftIssue";
|
||||
import EditSlashCommand from "./edit";
|
||||
import HttpSlashCommand from "./http";
|
||||
import MultiFileEditSlashCommand from "./multifileEdit";
|
||||
import OnboardSlashCommand from "./onboard";
|
||||
import ReviewMessageCommand from "./review";
|
||||
import ShareSlashCommand from "./share";
|
||||
import OnboardSlashCommand from "./onboard";
|
||||
|
||||
export default [
|
||||
DraftIssueCommand,
|
||||
|
|
@ -18,4 +19,5 @@ export default [
|
|||
CommitMessageCommand,
|
||||
ReviewMessageCommand,
|
||||
OnboardSlashCommand,
|
||||
MultiFileEditSlashCommand,
|
||||
];
|
||||
|
|
|
|||
67
core/commands/slash/multifileEdit.ts
Normal file
67
core/commands/slash/multifileEdit.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import { SlashCommand } from "../..";
|
||||
import { stripImages } from "../../llm/images";
|
||||
|
||||
const MultiFileEditSlashCommand: SlashCommand = {
|
||||
name: "multifile-edit",
|
||||
description: "Edit multiple files in the codebase at once",
|
||||
run: async function* ({ llm, contextItems, input }) {
|
||||
const filesToEditStr = contextItems.map((item) => item.content).join("\n");
|
||||
|
||||
const content = createPrompt(filesToEditStr, input);
|
||||
|
||||
for await (const chunk of llm.streamChat([{ role: "user", content }])) {
|
||||
yield stripImages(chunk.content);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function createPrompt(filesToEditStr: string, input: string): string {
|
||||
return `
|
||||
You are an AI assistant designed to help software engineers make multi-file edits in their codebase. Your task is to generate the necessary code changes for multiple files based on the engineer's request. Follow these guidelines:
|
||||
|
||||
1. Start with a brief introduction of the task you're about to perform. Do not start with any other preamble, such as "Certainly!"
|
||||
2. When providing instructions, if a user needs to interact with a CLI, walk them through each step
|
||||
2. Perform file edits in a logical, sequential ordering
|
||||
3. For each file edit, provide a brief explanation of the changes
|
||||
4. If the user submits a code block that contains a filename in the language specifier, always include the filename in any code block you generate based on that file. The filename should be on the same line as the language specifier in your code block.
|
||||
a. When creating new files, also inlcude the filname in the language specifier of the code block.
|
||||
6. After providing all file changes, include a brief, sequential overview of the most important 3-5 edits
|
||||
|
||||
Remember to be concise and focus on the code changes and their impact.
|
||||
|
||||
Here's an example of how your response should be structured:
|
||||
|
||||
<example>
|
||||
I'll make the following changes to implement feature X:
|
||||
|
||||
1. First, I'll modify file1.js to add a new function:
|
||||
\`\`\`javascript /path/to/file1.js
|
||||
// Entire content of file1.js or changes to be made
|
||||
\`\`\`
|
||||
|
||||
2. Next, let's create a new test file:
|
||||
\`\`\`javascript /path/to/file1.test.js
|
||||
# Entire content of file2.py or changes to be made
|
||||
\`\`\`
|
||||
|
||||
Summary:
|
||||
- [Sequential overview of the most important 3-5 edits]
|
||||
</example>
|
||||
|
||||
Now, let's make the changes based on the engineer's request:
|
||||
|
||||
<input>
|
||||
${input}
|
||||
</input>
|
||||
|
||||
Here are the files to edit:
|
||||
|
||||
<files>
|
||||
${filesToEditStr}
|
||||
</files>
|
||||
|
||||
Please provide the multi-file edit details based on the engineer's request.
|
||||
`;
|
||||
}
|
||||
|
||||
export default MultiFileEditSlashCommand;
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
import type { RangeInFileWithContents } from "../commands/util.js";
|
||||
import type { ContextSubmenuItem, MessageContent } from "../index.js";
|
||||
import { ToIdeFromWebviewOrCoreProtocol } from "./ide.js";
|
||||
import { ToWebviewFromIdeOrCoreProtocol } from "./webview.js";
|
||||
|
||||
import type { RangeInFileWithContents } from "../commands/util.js";
|
||||
import type { ContextSubmenuItem, MessageContent } from "../index.js";
|
||||
|
||||
export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
||||
onLoad: [
|
||||
undefined,
|
||||
|
|
@ -17,8 +18,13 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
openUrl: [string, void];
|
||||
// We pass the `curSelectedModel` because we currently cannot access the
|
||||
// default model title in the GUI from JB
|
||||
applyToCurrentFile: [
|
||||
{ text: string; streamId: string; curSelectedModelTitle: string },
|
||||
applyToFile: [
|
||||
{
|
||||
text: string;
|
||||
streamId: string;
|
||||
curSelectedModelTitle: string;
|
||||
filepath: string;
|
||||
},
|
||||
void,
|
||||
];
|
||||
showTutorial: [undefined, void];
|
||||
|
|
|
|||
|
|
@ -632,7 +632,7 @@ class IdeProtocolClient(
|
|||
}
|
||||
}
|
||||
|
||||
"applyToCurrentFile" -> {
|
||||
"applyToFile" -> {
|
||||
val msg = data as Map<String, String>;
|
||||
val text = msg["text"] as String
|
||||
val curSelectedModelTitle = msg["curSelectedModelTitle"] as String
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "0.9.225",
|
||||
"version": "0.9.227",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "0.9.225",
|
||||
"version": "0.9.227",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "continue",
|
||||
"icon": "media/icon.png",
|
||||
"author": "Continue Dev, Inc",
|
||||
"version": "0.9.225",
|
||||
"version": "0.9.227",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/continuedev/continue"
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ class VsCodeIde implements IDE {
|
|||
}
|
||||
|
||||
async openFile(path: string): Promise<void> {
|
||||
this.ideUtils.openFile(path);
|
||||
await this.ideUtils.openFile(path);
|
||||
}
|
||||
|
||||
async showLines(
|
||||
|
|
|
|||
|
|
@ -257,30 +257,6 @@ export class VerticalDiffManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams an edit to the current document based on user input and model output.
|
||||
*
|
||||
* @param input - The user's input or instruction for the edit.
|
||||
* @param modelTitle - The title of the language model to be used.
|
||||
* @param [onlyOneInsertion] - Optional flag to limit the edit to a single insertion.
|
||||
* @param [quickEdit] - Optional string indicating if this is a quick edit.
|
||||
* @param [range] - Optional range to use instead of the highlighted text. Note that the `quickEdit`
|
||||
* property currently can't be passed with `range` since it assumes there is an
|
||||
* active selection.
|
||||
*
|
||||
* This method performs the following steps:
|
||||
* 1. Sets up the editor context for the diff.
|
||||
* 2. Determines the range of text to be edited.
|
||||
* 3. Clears any existing diff handlers for the file.
|
||||
* 4. Creates a new vertical diff handler.
|
||||
* 5. Prepares the context (prefix and suffix) for the language model.
|
||||
* 6. Streams the diff lines from the language model.
|
||||
* 7. Applies the changes to the document.
|
||||
* 8. Sets up a listener for subsequent user edits.
|
||||
*
|
||||
* The method handles various edge cases, such as quick edits and existing diffs,
|
||||
* and manages the lifecycle of diff handlers and document change listeners.
|
||||
*/
|
||||
async streamEdit(
|
||||
input: string,
|
||||
modelTitle: string | undefined,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import {
|
|||
import { getExtensionUri } from "../util/vscode";
|
||||
import { VsCodeIde } from "../VsCodeIde";
|
||||
import { VsCodeWebviewProtocol } from "../webviewProtocol";
|
||||
import { getFullyQualifiedPath } from "../util/util";
|
||||
|
||||
/**
|
||||
* A shared messenger class between Core and Webview
|
||||
|
|
@ -85,7 +86,11 @@ export class VsCodeMessenger {
|
|||
) {
|
||||
/** WEBVIEW ONLY LISTENERS **/
|
||||
this.onWebview("showFile", (msg) => {
|
||||
this.ide.openFile(msg.data.filepath);
|
||||
const fullPath = getFullyQualifiedPath(msg.data.filepath);
|
||||
|
||||
if (fullPath) {
|
||||
this.ide.openFile(fullPath);
|
||||
}
|
||||
});
|
||||
|
||||
this.onWebview("vscode/openMoveRightMarkdown", (msg) => {
|
||||
|
|
@ -153,9 +158,33 @@ export class VsCodeMessenger {
|
|||
await vscode.commands.executeCommand("continue.rejectDiff", filepath);
|
||||
});
|
||||
|
||||
this.onWebview("applyToCurrentFile", async ({ data }) => {
|
||||
this.onWebview("applyToFile", async ({ data }) => {
|
||||
const fullPath = getFullyQualifiedPath(data.filepath);
|
||||
|
||||
if (!fullPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fileExists = await this.ide.fileExists(fullPath);
|
||||
|
||||
// If it's a new file, no need to apply, just write directly
|
||||
if (!fileExists) {
|
||||
await this.ide.writeFile(fullPath, data.text);
|
||||
await this.ide.openFile(fullPath);
|
||||
|
||||
await webviewProtocol.request("updateApplyState", {
|
||||
streamId: data.streamId,
|
||||
status: "done",
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await this.ide.openFile(fullPath);
|
||||
|
||||
// Get active text editor
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (!editor) {
|
||||
vscode.window.showErrorMessage("No active editor to apply edits to");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -136,9 +136,7 @@ export class VsCodeIdeUtils {
|
|||
);
|
||||
}
|
||||
|
||||
private async resolveAbsFilepathInWorkspace(
|
||||
filepath: string,
|
||||
): Promise<string> {
|
||||
async resolveAbsFilepathInWorkspace(filepath: string): Promise<string> {
|
||||
// If the filepath is already absolute, return it as is
|
||||
if (this.path.isAbsolute(filepath)) {
|
||||
return filepath;
|
||||
|
|
@ -158,7 +156,7 @@ export class VsCodeIdeUtils {
|
|||
|
||||
async openFile(filepath: string, range?: vscode.Range) {
|
||||
// vscode has a builtin open/get open files
|
||||
return openEditorAndRevealRange(
|
||||
return await openEditorAndRevealRange(
|
||||
await this.resolveAbsFilepathInWorkspace(filepath),
|
||||
range,
|
||||
vscode.ViewColumn.One,
|
||||
|
|
|
|||
|
|
@ -124,14 +124,16 @@ export function getExtensionVersion(): string {
|
|||
}
|
||||
|
||||
export function getFullyQualifiedPath(filepath?: string) {
|
||||
if (filepath && !path.isAbsolute(filepath)) {
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
if (workspaceFolders && workspaceFolders.length > 0) {
|
||||
return path.join(workspaceFolders[0].uri.fsPath, filepath);
|
||||
} else {
|
||||
vscode.window.showErrorMessage(
|
||||
"Unable to resolve filepath: no workspace folder found",
|
||||
);
|
||||
}
|
||||
if (!filepath) return;
|
||||
if (path.isAbsolute(filepath)) return filepath;
|
||||
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
|
||||
if (workspaceFolders && workspaceFolders.length > 0) {
|
||||
return path.join(workspaceFolders[0].uri.fsPath, filepath);
|
||||
} else {
|
||||
vscode.window.showErrorMessage(
|
||||
"Unable to resolve filepath: no workspace folder found",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,19 +176,24 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
|
||||
if (isTerminal) {
|
||||
await ideMessenger.ide.runCommand(getTerminalCommand(props.text));
|
||||
} else {
|
||||
ideMessenger.post("applyToCurrentFile", {
|
||||
curSelectedModelTitle: defaultModel.title,
|
||||
text: props.text,
|
||||
streamId: streamIdRef.current,
|
||||
});
|
||||
dispatch(
|
||||
updateApplyState({
|
||||
streamId: streamIdRef.current,
|
||||
status: "streaming",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!props.filepath) return;
|
||||
|
||||
dispatch(
|
||||
updateApplyState({
|
||||
streamId: streamIdRef.current,
|
||||
status: "streaming",
|
||||
}),
|
||||
);
|
||||
|
||||
ideMessenger.post("applyToFile", {
|
||||
curSelectedModelTitle: defaultModel.title,
|
||||
text: props.text,
|
||||
streamId: streamIdRef.current,
|
||||
filepath: props.filepath,
|
||||
});
|
||||
}
|
||||
|
||||
function onClickHeader() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue