Merge pull request #2892 from continuedev/nate/edit-improvements
fix cmd+L bug
This commit is contained in:
commit
a58e7e9fc8
20 changed files with 432 additions and 202 deletions
12
core/index.d.ts
vendored
12
core/index.d.ts
vendored
|
|
@ -45,12 +45,12 @@ export interface IndexingProgressUpdate {
|
|||
debugInfo?: string;
|
||||
}
|
||||
|
||||
export type PromptTemplate =
|
||||
| string
|
||||
| ((
|
||||
history: ChatMessage[],
|
||||
otherData: Record<string, string>,
|
||||
) => string | ChatMessage[]);
|
||||
export type PromptTemplateFunction = (
|
||||
history: ChatMessage[],
|
||||
otherData: Record<string, string>,
|
||||
) => string | ChatMessage[];
|
||||
|
||||
export type PromptTemplate = string | PromptTemplateFunction;
|
||||
|
||||
export interface ILLM extends LLMOptions {
|
||||
get providerName(): ModelProvider;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const DEFAULT_MAX_TOKENS = 2048;
|
||||
const DEFAULT_MAX_TOKENS = 4096;
|
||||
const DEFAULT_CONTEXT_LENGTH = 8096;
|
||||
const DEFAULT_TEMPERATURE = 0.5;
|
||||
|
||||
|
|
@ -7,7 +7,7 @@ const DEFAULT_ARGS = {
|
|||
temperature: DEFAULT_TEMPERATURE,
|
||||
};
|
||||
|
||||
const GPT_4_CTX_LEN = 4096;
|
||||
const GPT_4_CTX_LEN = 128_000;
|
||||
|
||||
const CONTEXT_LENGTH_FOR_MODEL: { [name: string]: number } = {
|
||||
"gpt-3.5-turbo": 4096,
|
||||
|
|
@ -16,9 +16,9 @@ const CONTEXT_LENGTH_FOR_MODEL: { [name: string]: number } = {
|
|||
"gpt-35-turbo-16k": 16_384,
|
||||
"gpt-35-turbo-0613": 4096,
|
||||
"gpt-35-turbo": 4096,
|
||||
"gpt-4": GPT_4_CTX_LEN,
|
||||
"gpt-4-32k": GPT_4_CTX_LEN,
|
||||
"gpt-4-turbo-preview": GPT_4_CTX_LEN,
|
||||
"gpt-4": 4096,
|
||||
"gpt-4-32k": 32_000,
|
||||
"gpt-4-turbo-preview": 32_000,
|
||||
"gpt-4o": GPT_4_CTX_LEN,
|
||||
"gpt-4o-mini": GPT_4_CTX_LEN,
|
||||
"gpt-4-vision": GPT_4_CTX_LEN,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { ChatMessage, PromptTemplate } from "../../index.js";
|
||||
import { gptEditPrompt } from "./edit/gpt.js";
|
||||
|
||||
const simplifiedEditPrompt = `Consider the following code:
|
||||
\`\`\`{{{language}}}
|
||||
|
|
@ -18,49 +19,6 @@ Here is the edit requested:
|
|||
|
||||
Here is the code after editing:`;
|
||||
|
||||
const gptEditPrompt: PromptTemplate = (_, otherData) => {
|
||||
if (otherData?.codeToEdit?.trim().length === 0) {
|
||||
return `\
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.prefix}[BLANK]${otherData.codeToEdit}${otherData.suffix}
|
||||
\`\`\`
|
||||
|
||||
Above is the file of code that the user is currently editing in. Their cursor is located at the "[BLANK]". They have requested that you fill in the "[BLANK]" with code that satisfies the following request:
|
||||
|
||||
"${otherData.userInput}"
|
||||
|
||||
Please generate this code. Your output will be only the code that should replace the "[BLANK]", without repeating any of the prefix or suffix, without any natural language explanation, and without messing up indentation. Here is the code that will replace the "[BLANK]":`;
|
||||
}
|
||||
|
||||
const paragraphs = [
|
||||
"The user has requested a section of code in a file to be rewritten.",
|
||||
];
|
||||
if (otherData.prefix?.trim().length > 0) {
|
||||
paragraphs.push(`This is the prefix of the file:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.prefix}
|
||||
\`\`\``);
|
||||
}
|
||||
|
||||
if (otherData.suffix?.trim().length > 0) {
|
||||
paragraphs.push(`This is the suffix of the file:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.suffix}
|
||||
\`\`\``);
|
||||
}
|
||||
|
||||
paragraphs.push(`This is the code to rewrite:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.codeToEdit}
|
||||
\`\`\`
|
||||
|
||||
The user's request is: "${otherData.userInput}"
|
||||
|
||||
Here is the rewritten code:`);
|
||||
|
||||
return paragraphs.join("\n\n");
|
||||
};
|
||||
|
||||
const codellamaInfillEditPrompt = "{{filePrefix}}<FILL>{{fileSuffix}}";
|
||||
|
||||
const START_TAG = "<START EDITING HERE>";
|
||||
|
|
@ -76,7 +34,7 @@ const osModelsEditPrompt: PromptTemplate = (history, otherData) => {
|
|||
!firstCharOfFirstLine;
|
||||
const suffixTag = isSuffix ? "<STOP EDITING HERE>" : "";
|
||||
const suffixExplanation = isSuffix
|
||||
? " When you get to \"<STOP EDITING HERE>\", end your response."
|
||||
? ' When you get to "<STOP EDITING HERE>", end your response.'
|
||||
: "";
|
||||
|
||||
// If neither prefilling nor /v1/completions are supported, we have to use a chat prompt without putting words in the model's mouth
|
||||
|
|
|
|||
44
core/llm/templates/edit/claude.ts
Normal file
44
core/llm/templates/edit/claude.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { PromptTemplateFunction } from "../../..";
|
||||
|
||||
export const claudeEditPrompt: PromptTemplateFunction = (_, otherData) => {
|
||||
if (otherData?.codeToEdit?.trim().length === 0) {
|
||||
return `\
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.prefix}[BLANK]${otherData.codeToEdit}${otherData.suffix}
|
||||
\`\`\`
|
||||
|
||||
Above is the file of code that the user is currently editing in. Their cursor is located at the "[BLANK]". They have requested that you fill in the "[BLANK]" with code that satisfies the following request:
|
||||
|
||||
"${otherData.userInput}"
|
||||
|
||||
Please generate this code. Your output will be only the code that should replace the "[BLANK]", without repeating any of the prefix or suffix, without any natural language explanation, and without messing up indentation. Here is the code that will replace the "[BLANK]":`;
|
||||
}
|
||||
|
||||
const paragraphs = [
|
||||
"The user has requested a section of code in a file to be rewritten.",
|
||||
];
|
||||
if (otherData.prefix?.trim().length > 0) {
|
||||
paragraphs.push(`This is the prefix of the file:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.prefix}
|
||||
\`\`\``);
|
||||
}
|
||||
|
||||
if (otherData.suffix?.trim().length > 0) {
|
||||
paragraphs.push(`This is the suffix of the file:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.suffix}
|
||||
\`\`\``);
|
||||
}
|
||||
|
||||
paragraphs.push(`This is the code to rewrite:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.codeToEdit}
|
||||
\`\`\`
|
||||
|
||||
The user's request is: "${otherData.userInput}"
|
||||
|
||||
Here is the rewritten code:`);
|
||||
|
||||
return paragraphs.join("\n\n");
|
||||
};
|
||||
71
core/llm/templates/edit/gpt.ts
Normal file
71
core/llm/templates/edit/gpt.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { PromptTemplateFunction } from "../../..";
|
||||
import { dedent } from "../../../util";
|
||||
|
||||
const gptInsertionEditPrompt: PromptTemplateFunction = (_, otherData) => {
|
||||
return dedent`
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.prefix}[BLANK]${otherData.codeToEdit}${otherData.suffix}
|
||||
\`\`\`
|
||||
|
||||
Above is the file of code that the user is currently editing in. Their cursor is located at the "[BLANK]". They have requested that you fill in the "[BLANK]" with code that satisfies the following request:
|
||||
|
||||
"${otherData.userInput}"
|
||||
|
||||
Please generate this code. Your output will be only the code that should replace the "[BLANK]", without repeating any of the prefix or suffix, without any natural language explanation, and without messing up indentation. Here is the code that will replace the "[BLANK]":`;
|
||||
};
|
||||
|
||||
const gptFullFileEditPrompt: PromptTemplateFunction = (_, otherData) => {
|
||||
return dedent`
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.codeToEdit}
|
||||
\`\`\`
|
||||
|
||||
Please rewrite the above file to address the following request:
|
||||
|
||||
${otherData.userInput}
|
||||
|
||||
You should rewrite the entire file without any natural language explanation. DO NOT surround the code in a code block and DO NOT explain yourself.`;
|
||||
};
|
||||
|
||||
export const gptEditPrompt: PromptTemplateFunction = (history, otherData) => {
|
||||
if (otherData?.codeToEdit?.trim().length === 0) {
|
||||
return gptInsertionEditPrompt(history, otherData);
|
||||
} else if (
|
||||
otherData?.prefix?.trim().length === 0 &&
|
||||
otherData?.suffix?.trim().length === 0
|
||||
) {
|
||||
return gptFullFileEditPrompt(history, otherData);
|
||||
}
|
||||
|
||||
const paragraphs = [
|
||||
"The user has requested a section of code in a file to be rewritten.",
|
||||
];
|
||||
|
||||
if (otherData.prefix?.trim().length > 0) {
|
||||
paragraphs.push(dedent`
|
||||
This is the prefix of the file:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.prefix}
|
||||
\`\`\``);
|
||||
}
|
||||
|
||||
if (otherData.suffix?.trim().length > 0) {
|
||||
paragraphs.push(dedent`
|
||||
This is the suffix of the file:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.suffix}
|
||||
\`\`\``);
|
||||
}
|
||||
|
||||
paragraphs.push(dedent`
|
||||
This is the code to rewrite:
|
||||
\`\`\`${otherData.language}
|
||||
${otherData.codeToEdit}
|
||||
\`\`\`
|
||||
|
||||
The user's request is: "${otherData.userInput}"
|
||||
|
||||
Here is the rewritten code:`);
|
||||
|
||||
return paragraphs.join("\n\n");
|
||||
};
|
||||
|
|
@ -56,7 +56,12 @@ export interface EditModeArgs {
|
|||
highlightedCode: RangeInFileWithContents;
|
||||
}
|
||||
|
||||
export type EditStatus = "not-started" | "streaming" | "accepting" | "done";
|
||||
export type EditStatus =
|
||||
| "not-started"
|
||||
| "streaming"
|
||||
| "accepting"
|
||||
| "accepting:full-diff"
|
||||
| "done";
|
||||
|
||||
export interface ApplyState {
|
||||
streamId: string;
|
||||
|
|
@ -105,6 +110,6 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
applyCodeFromChat: [undefined, void];
|
||||
updateApplyState: [ApplyState, void];
|
||||
startEditMode: [EditModeArgs, void];
|
||||
setEditStatus: [{ status: EditStatus }, void];
|
||||
setEditStatus: [{ status: EditStatus; fileAfterEdit?: string }, void];
|
||||
exitEditMode: [undefined, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -135,4 +135,21 @@ World
|
|||
|
||||
expect(result).toBe("Hello\n\nWorld");
|
||||
});
|
||||
|
||||
it("should work with templated strings", () => {
|
||||
const language = "typescript";
|
||||
const code = "console.log('hello');\nconsole.log('world');";
|
||||
|
||||
const result = dedent`
|
||||
This is the prefix of the file:
|
||||
\`\`\`${language}
|
||||
${code}
|
||||
\`\`\``;
|
||||
|
||||
expect(result).toBe(`\
|
||||
This is the prefix of the file:
|
||||
\`\`\`${language}
|
||||
${code}
|
||||
\`\`\``);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@ export function removeQuotesAndEscapes(output: string): string {
|
|||
output = output.trim();
|
||||
|
||||
// Replace smart quotes
|
||||
output = output.replace("“", "\"");
|
||||
output = output.replace("”", "\"");
|
||||
output = output.replace("“", '"');
|
||||
output = output.replace("”", '"');
|
||||
output = output.replace("‘", "'");
|
||||
output = output.replace("’", "'");
|
||||
|
||||
// Remove escapes
|
||||
output = output.replace("\\\"", "\"");
|
||||
output = output.replace('\\"', '"');
|
||||
output = output.replace("\\'", "'");
|
||||
output = output.replace("\\n", "\n");
|
||||
output = output.replace("\\t", "\t");
|
||||
output = output.replace("\\\\", "\\");
|
||||
while (
|
||||
(output.startsWith("\"") && output.endsWith("\"")) ||
|
||||
(output.startsWith('"') && output.endsWith('"')) ||
|
||||
(output.startsWith("'") && output.endsWith("'"))
|
||||
) {
|
||||
output = output.slice(1, -1);
|
||||
|
|
@ -276,31 +276,55 @@ export function deduplicateArray<T>(
|
|||
export type TODO = any;
|
||||
|
||||
export function dedent(strings: TemplateStringsArray, ...values: any[]) {
|
||||
let result = strings.reduce(
|
||||
(acc, str, i) => acc + str + (values[i] || ""),
|
||||
"",
|
||||
);
|
||||
result = result.replace(/^\n/, "").replace(/\n\s*$/, "");
|
||||
let raw = "";
|
||||
for (let i = 0; i < strings.length; i++) {
|
||||
raw += strings[i];
|
||||
|
||||
// Handle the value if it exists
|
||||
if (i < values.length) {
|
||||
let value = String(values[i]);
|
||||
// If the value contains newlines, we need to adjust the indentation
|
||||
if (value.includes("\n")) {
|
||||
// Find the indentation level of the last line in strings[i]
|
||||
let lines = strings[i].split("\n");
|
||||
let lastLine = lines[lines.length - 1];
|
||||
let match = lastLine.match(/(^|\n)([^\S\n]*)$/);
|
||||
let indent = match ? match[2] : "";
|
||||
// Add indentation to all lines except the first line of value
|
||||
let valueLines = value.split("\n");
|
||||
valueLines = valueLines.map((line, index) =>
|
||||
index === 0 ? line : indent + line,
|
||||
);
|
||||
value = valueLines.join("\n");
|
||||
}
|
||||
raw += value;
|
||||
}
|
||||
}
|
||||
|
||||
// Now dedent the full string
|
||||
let result = raw.replace(/^\n/, "").replace(/\n\s*$/, "");
|
||||
let lines = result.split("\n");
|
||||
|
||||
// Remove leading white-space-only lines
|
||||
// Remove leading/trailing blank lines
|
||||
while (lines.length > 0 && lines[0].trim() === "") {
|
||||
lines.shift();
|
||||
}
|
||||
|
||||
// Remove trailing white-space-only lines
|
||||
while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
|
||||
lines.pop();
|
||||
}
|
||||
|
||||
const minIndent = lines.reduce((min, line) => {
|
||||
if (line.trim() === "") {
|
||||
// Don't consider empty lines when calculating indentation
|
||||
return min;
|
||||
}
|
||||
const match = line.match(/^\s*/);
|
||||
return Math.min(min, match ? match[0].length : Infinity);
|
||||
}, Infinity);
|
||||
// Calculate minimum indentation (excluding empty lines)
|
||||
let minIndent = lines.reduce((min: any, line: any) => {
|
||||
if (line.trim() === "") return min;
|
||||
let match = line.match(/^(\s*)/);
|
||||
let indent = match ? match[1].length : 0;
|
||||
return min === null ? indent : Math.min(min, indent);
|
||||
}, null);
|
||||
|
||||
return lines.map((line) => line.slice(minIndent)).join("\n");
|
||||
if (minIndent !== null && minIndent > 0) {
|
||||
// Remove the minimum indentation from each line
|
||||
lines = lines.map((line) => line.slice(minIndent));
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ export class ContinueGUIWebviewViewProvider
|
|||
public static readonly viewType = "continue.continueGUIView";
|
||||
public webviewProtocol: VsCodeWebviewProtocol;
|
||||
|
||||
public get isReady(): boolean {
|
||||
return !!this.webview;
|
||||
}
|
||||
|
||||
private updateDebugLogsStatus() {
|
||||
const settings = vscode.workspace.getConfiguration(EXTENSION_NAME);
|
||||
this.enableDebugLogs = settings.get<boolean>("enableDebugLogs", false);
|
||||
|
|
|
|||
|
|
@ -489,11 +489,13 @@ class VsCodeIde implements IDE {
|
|||
}
|
||||
|
||||
async getCurrentFile() {
|
||||
if (!vscode.window.activeTextEditor) {return undefined;}
|
||||
if (!vscode.window.activeTextEditor) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
isUntitled: vscode.window.activeTextEditor.document.isUntitled,
|
||||
path: vscode.window.activeTextEditor.document.uri.fsPath,
|
||||
contents: vscode.window.activeTextEditor.document.getText()
|
||||
contents: vscode.window.activeTextEditor.document.getText(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -629,4 +631,3 @@ class VsCodeIde implements IDE {
|
|||
}
|
||||
|
||||
export { VsCodeIde };
|
||||
|
||||
|
|
|
|||
|
|
@ -366,6 +366,14 @@ const commandsMap: (
|
|||
core.invoke("context/indexDocs", { reIndex: true });
|
||||
},
|
||||
"continue.focusContinueInput": async () => {
|
||||
// This is a temporary fix—sidebar.webviewProtocol.request is blocking
|
||||
// when the GUI hasn't yet been setup and we should instead be
|
||||
// immediately throwing an error, or returning a Result object
|
||||
if (!sidebar.isReady) {
|
||||
focusGUI();
|
||||
return;
|
||||
}
|
||||
|
||||
const historyLength = await sidebar.webviewProtocol.request(
|
||||
"getWebviewHistoryLength",
|
||||
undefined,
|
||||
|
|
@ -388,6 +396,14 @@ const commandsMap: (
|
|||
}
|
||||
},
|
||||
"continue.focusContinueInputWithoutClear": async () => {
|
||||
// This is a temporary fix—sidebar.webviewProtocol.request is blocking
|
||||
// when the GUI hasn't yet been setup and we should instead be
|
||||
// immediately throwing an error, or returning a Result object
|
||||
if (!sidebar.isReady) {
|
||||
focusGUI();
|
||||
return;
|
||||
}
|
||||
|
||||
const isContinueInputFocused = await sidebar.webviewProtocol.request(
|
||||
"isContinueInputFocused",
|
||||
undefined,
|
||||
|
|
|
|||
|
|
@ -180,6 +180,8 @@ export class VerticalDiffManager {
|
|||
// Re-enable listener for user changes to file
|
||||
this.enableDocumentChangeListener();
|
||||
}
|
||||
|
||||
this.refreshCodeLens();
|
||||
}
|
||||
|
||||
async streamDiffLines(
|
||||
|
|
@ -267,13 +269,13 @@ export class VerticalDiffManager {
|
|||
onlyOneInsertion?: boolean,
|
||||
quickEdit?: string,
|
||||
range?: vscode.Range,
|
||||
) {
|
||||
): Promise<string | undefined> {
|
||||
vscode.commands.executeCommand("setContext", "continue.diffVisible", true);
|
||||
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (!editor) {
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const filepath = editor.document.uri.fsPath;
|
||||
|
|
@ -346,7 +348,7 @@ export class VerticalDiffManager {
|
|||
|
||||
if (!diffHandler) {
|
||||
console.warn("Issue occured while creating new vertical diff handler");
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let selectedRange = diffHandler.range;
|
||||
|
|
@ -396,8 +398,10 @@ export class VerticalDiffManager {
|
|||
this.editDecorationManager.clear();
|
||||
|
||||
try {
|
||||
this.logDiffs = await diffHandler.run(
|
||||
streamDiffLines(
|
||||
const streamedLines: string[] = [];
|
||||
|
||||
async function* recordedStream() {
|
||||
const stream = streamDiffLines(
|
||||
prefix,
|
||||
rangeContent,
|
||||
suffix,
|
||||
|
|
@ -405,14 +409,26 @@ export class VerticalDiffManager {
|
|||
input,
|
||||
getMarkdownLanguageTagForFile(filepath),
|
||||
onlyOneInsertion,
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
for await (const line of stream) {
|
||||
if (line.type === "new" || line.type === "same") {
|
||||
streamedLines.push(line.line);
|
||||
}
|
||||
yield line;
|
||||
}
|
||||
}
|
||||
|
||||
this.logDiffs = await diffHandler.run(recordedStream());
|
||||
|
||||
// enable a listener for user edits to file while diff is open
|
||||
this.enableDocumentChangeListener();
|
||||
|
||||
return `${prefix}${streamedLines.join("\n")}${suffix}`;
|
||||
} catch (e) {
|
||||
this.disableDocumentChangeListener();
|
||||
vscode.window.showErrorMessage(`Error streaming diff: ${e}`);
|
||||
return undefined;
|
||||
} finally {
|
||||
vscode.commands.executeCommand(
|
||||
"setContext",
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ export class VsCodeMessenger {
|
|||
"getDefaultModelTitle",
|
||||
undefined,
|
||||
);
|
||||
await verticalDiffManager.streamEdit(
|
||||
const fileAfterEdit = await verticalDiffManager.streamEdit(
|
||||
stripImages(prompt),
|
||||
modelTitle,
|
||||
"edit",
|
||||
|
|
@ -330,6 +330,7 @@ export class VsCodeMessenger {
|
|||
|
||||
this.webviewProtocol.request("setEditStatus", {
|
||||
status: "accepting",
|
||||
fileAfterEdit,
|
||||
});
|
||||
});
|
||||
this.onWebview("edit/acceptReject", async (msg) => {
|
||||
|
|
|
|||
|
|
@ -188,8 +188,8 @@ const Layout = () => {
|
|||
[navigate],
|
||||
);
|
||||
|
||||
useWebviewListener("setEditStatus", async ({ status }) => {
|
||||
dispatch(setEditStatus(status));
|
||||
useWebviewListener("setEditStatus", async ({ status, fileAfterEdit }) => {
|
||||
dispatch(setEditStatus({ status, fileAfterEdit }));
|
||||
});
|
||||
|
||||
useWebviewListener("exitEditMode", async () => {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
import {
|
||||
useRef,
|
||||
useEffect,
|
||||
useState,
|
||||
RefObject,
|
||||
useCallback,
|
||||
useMemo,
|
||||
} from "react";
|
||||
import { RootState } from "../../redux/store";
|
||||
import { useSelector } from "react-redux";
|
||||
import { HeaderButton, Input } from "..";
|
||||
import {
|
||||
ArrowDownIcon,
|
||||
ArrowUpIcon,
|
||||
XMarkIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import {
|
||||
RefObject,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { HeaderButton, Input } from "..";
|
||||
import { RootState } from "../../redux/store";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
|
||||
interface SearchMatch {
|
||||
|
|
@ -119,7 +119,7 @@ export const useFindWidget = (searchRef: RefObject<HTMLDivElement>) => {
|
|||
// Handle keyboard shortcuts for navigation
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.metaKey && event.key.toLowerCase() === "f") {
|
||||
if (event.metaKey && event.key.toLowerCase() === "f" && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
openWidget();
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@ export function parseColorForHex(colorVar: string): string {
|
|||
colorVar,
|
||||
);
|
||||
if (value.startsWith("#")) {
|
||||
console.log("OAIJFIOJOOJOIO", colorVar, value, value.slice(0, 7));
|
||||
return value.slice(0, 7);
|
||||
}
|
||||
|
||||
|
|
|
|||
114
gui/src/pages/edit/EditInputHeader.tsx
Normal file
114
gui/src/pages/edit/EditInputHeader.tsx
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
||||
import { getBasename } from "core/util";
|
||||
import { useContext, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import FileIcon from "../../components/FileIcon";
|
||||
import HeaderButtonWithToolTip from "../../components/gui/HeaderButtonWithToolTip";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { setEditDone, setEditStatus } from "../../redux/slices/editModeState";
|
||||
import { RootState } from "../../redux/store";
|
||||
|
||||
interface EditInputHeaderParams {}
|
||||
|
||||
/**
|
||||
* @description This is a class that represents an edit input header.
|
||||
*/
|
||||
export function EditInputHeader(editInputHeaderParams: EditInputHeaderParams) {
|
||||
const dispatch = useDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const editModeState = useSelector((state: RootState) => state.editModeState);
|
||||
|
||||
const [showCode, setShowCode] = useState(false);
|
||||
|
||||
function onClick() {
|
||||
ideMessenger.ide.showLines(
|
||||
editModeState.highlightedCode.filepath,
|
||||
editModeState.highlightedCode.range.start.line,
|
||||
editModeState.highlightedCode.range.end.line,
|
||||
);
|
||||
setShowCode(!showCode);
|
||||
}
|
||||
|
||||
async function showFullDiff() {
|
||||
await ideMessenger.ide.showDiff(
|
||||
editModeState.highlightedCode.filepath,
|
||||
editModeState.fileAfterEdit,
|
||||
0,
|
||||
);
|
||||
dispatch(setEditStatus({ status: "accepting:full-diff" }));
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="select-none p-1"
|
||||
style={{
|
||||
backgroundColor: "#fff2",
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex cursor-pointer" onClick={onClick}>
|
||||
<FileIcon
|
||||
filename={editModeState.highlightedCode.filepath}
|
||||
height={"18px"}
|
||||
width={"18px"}
|
||||
></FileIcon>
|
||||
{getBasename(editModeState.highlightedCode.filepath)} (
|
||||
{editModeState.highlightedCode.range.start.line}-
|
||||
{editModeState.highlightedCode.range.end.line})
|
||||
</div>
|
||||
{editModeState.editStatus === "accepting" ||
|
||||
editModeState.editStatus === "accepting:full-diff" ? (
|
||||
<div className="float-right flex items-center gap-2">
|
||||
{/* {editModeState.editStatus === "accepting" ? (
|
||||
<>
|
||||
<HeaderButtonWithToolTip text="View full diff">
|
||||
<DocumentPlusIcon
|
||||
className="h-4 w-4 cursor-pointer"
|
||||
onClick={showFullDiff}
|
||||
></DocumentPlusIcon>
|
||||
</HeaderButtonWithToolTip>
|
||||
<span className="text-xs text-gray-400">
|
||||
N diffs remaining
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<div>hi</div>
|
||||
)} */}
|
||||
|
||||
<div className="flex">
|
||||
<HeaderButtonWithToolTip text="Accept">
|
||||
<XMarkIcon
|
||||
className="h-4 w-4 cursor-pointer px-2"
|
||||
color="red"
|
||||
onClick={() => {
|
||||
ideMessenger.request("edit/acceptReject", {
|
||||
accept: false,
|
||||
onlyFirst: false,
|
||||
filepath: editModeState.highlightedCode.filepath,
|
||||
});
|
||||
dispatch(setEditDone());
|
||||
}}
|
||||
></XMarkIcon>
|
||||
</HeaderButtonWithToolTip>
|
||||
<HeaderButtonWithToolTip text="Reject">
|
||||
<CheckIcon
|
||||
className="h-4 w-4 cursor-pointer px-2 text-green-500"
|
||||
onClick={() => {
|
||||
ideMessenger.request("edit/acceptReject", {
|
||||
accept: true,
|
||||
onlyFirst: false,
|
||||
filepath: editModeState.highlightedCode.filepath,
|
||||
});
|
||||
dispatch(setEditDone());
|
||||
}}
|
||||
></CheckIcon>
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -2,28 +2,22 @@ import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
|||
import { Editor, JSONContent } from "@tiptap/core";
|
||||
import { InputModifiers } from "core";
|
||||
import { stripImages } from "core/llm/images";
|
||||
import { getBasename } from "core/util";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { useContext, useEffect } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
parseColorForHex,
|
||||
VSC_DIFF_INSERTED_LINE_BACKGROUND_VAR,
|
||||
VSC_DIFF_REMOVED_LINE_BACKGROUND_VAR,
|
||||
vscForeground,
|
||||
} from "../components";
|
||||
import FileIcon from "../components/FileIcon";
|
||||
import { NewSessionButton } from "../components/mainInput/NewSessionButton";
|
||||
import resolveEditorContent from "../components/mainInput/resolveInput";
|
||||
import TipTapEditor from "../components/mainInput/TipTapEditor";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { setEditDone, submitEdit } from "../redux/slices/editModeState";
|
||||
import { RootState } from "../redux/store";
|
||||
import { getMetaKeyLabel } from "../util";
|
||||
} from "../../components";
|
||||
import { NewSessionButton } from "../../components/mainInput/NewSessionButton";
|
||||
import resolveEditorContent from "../../components/mainInput/resolveInput";
|
||||
import TipTapEditor from "../../components/mainInput/TipTapEditor";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { setEditDone, submitEdit } from "../../redux/slices/editModeState";
|
||||
import { RootState } from "../../redux/store";
|
||||
import { EditInputHeader } from "./EditInputHeader";
|
||||
|
||||
const TopDiv = styled.div`
|
||||
overflow-y: auto;
|
||||
|
|
@ -34,6 +28,13 @@ const TopDiv = styled.div`
|
|||
}
|
||||
`;
|
||||
|
||||
const ToolbarDiv = styled.div`
|
||||
padding: 8px;
|
||||
border-bottom: 1px solid ${lightGray};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
display: flex;
|
||||
`;
|
||||
|
||||
const AcceptRejectButton = styled.div<{
|
||||
backgroundColor: string;
|
||||
disabled: boolean;
|
||||
|
|
@ -85,7 +86,6 @@ const EDIT_DISALLOWED_CONTEXT_PROVIDERS = [
|
|||
];
|
||||
|
||||
function Edit() {
|
||||
const posthog = usePostHog();
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
|
@ -95,8 +95,6 @@ function Edit() {
|
|||
);
|
||||
useEffect(() => {}, []);
|
||||
|
||||
const [showCode, setShowCode] = useState(false);
|
||||
|
||||
// Reusing the applyState logic which was just the fastest way to get this working
|
||||
useEffect(() => {
|
||||
if (editModeState.editStatus === "done") {
|
||||
|
|
@ -137,35 +135,7 @@ function Edit() {
|
|||
|
||||
<div className="relative mb-1 mt-3 flex px-2">
|
||||
<TipTapEditor
|
||||
header={
|
||||
<div
|
||||
className="select-none p-1"
|
||||
style={{
|
||||
backgroundColor: "#fff2",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="flex cursor-pointer"
|
||||
onClick={() => {
|
||||
ideMessenger.ide.showLines(
|
||||
editModeState.highlightedCode.filepath,
|
||||
editModeState.highlightedCode.range.start.line,
|
||||
editModeState.highlightedCode.range.end.line,
|
||||
);
|
||||
setShowCode(!showCode);
|
||||
}}
|
||||
>
|
||||
<FileIcon
|
||||
filename={editModeState.highlightedCode.filepath}
|
||||
height={"18px"}
|
||||
width={"18px"}
|
||||
></FileIcon>
|
||||
{getBasename(editModeState.highlightedCode.filepath)} (
|
||||
{editModeState.highlightedCode.range.start.line}-
|
||||
{editModeState.highlightedCode.range.end.line})
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
header={<EditInputHeader />}
|
||||
toolbarOptions={{
|
||||
hideAddContext: true,
|
||||
hideImageUpload: true,
|
||||
|
|
@ -179,8 +149,8 @@ function Edit() {
|
|||
}}
|
||||
placeholder={
|
||||
["streaming", "accepting"].includes(editModeState.editStatus)
|
||||
? "Enter instructions for edit"
|
||||
: "Enter instructions for edit"
|
||||
? "Describe how to modify code"
|
||||
: "Describe how to modify code"
|
||||
}
|
||||
border={`1px solid #aa0`}
|
||||
availableContextProviders={availableContextProviders.filter(
|
||||
|
|
@ -223,43 +193,6 @@ function Edit() {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{["accepting", "streaming"].includes(editModeState.editStatus) && (
|
||||
<div className="my-2 flex w-full cursor-pointer">
|
||||
<AcceptRejectButton
|
||||
disabled={editModeState.editStatus !== "accepting"}
|
||||
backgroundColor={parseColorForHex(
|
||||
VSC_DIFF_REMOVED_LINE_BACKGROUND_VAR,
|
||||
)}
|
||||
onClick={() => {
|
||||
ideMessenger.request("edit/acceptReject", {
|
||||
accept: false,
|
||||
onlyFirst: false,
|
||||
filepath: editModeState.highlightedCode.filepath,
|
||||
});
|
||||
dispatch(setEditDone());
|
||||
}}
|
||||
>
|
||||
<code>{getMetaKeyLabel()}⇧⌫</code> Reject all
|
||||
</AcceptRejectButton>
|
||||
<AcceptRejectButton
|
||||
disabled={editModeState.editStatus !== "accepting"}
|
||||
backgroundColor={parseColorForHex(
|
||||
VSC_DIFF_INSERTED_LINE_BACKGROUND_VAR,
|
||||
)}
|
||||
onClick={() => {
|
||||
ideMessenger.request("edit/acceptReject", {
|
||||
accept: true,
|
||||
onlyFirst: false,
|
||||
filepath: editModeState.highlightedCode.filepath,
|
||||
});
|
||||
dispatch(setEditDone());
|
||||
}}
|
||||
>
|
||||
<code>{getMetaKeyLabel()}⇧⏎</code> Accept all
|
||||
</AcceptRejectButton>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-2">
|
||||
<NewSessionButton
|
||||
onClick={async () => {
|
||||
|
|
@ -311,7 +311,8 @@ export function Chat() {
|
|||
[state.history],
|
||||
);
|
||||
|
||||
const showScrollbar = state.config.ui?.showChatScrollbar || false;
|
||||
const showScrollbar =
|
||||
state.config.ui?.showChatScrollbar || window.innerHeight > 5000;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { MessageContent } from "core";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
import { EditModeArgs } from "core/protocol/ideWebview";
|
||||
type EditStatus = "not-started" | "streaming" | "accepting" | "done";
|
||||
import { EditModeArgs, EditStatus } from "core/protocol/ideWebview";
|
||||
|
||||
interface EditModeState {
|
||||
highlightedCode?: RangeInFileWithContents;
|
||||
editStatus: EditStatus;
|
||||
previousInputs: MessageContent[];
|
||||
fileAfterEdit?: string;
|
||||
}
|
||||
|
||||
const initialState: EditModeState = {
|
||||
|
|
@ -22,22 +23,47 @@ export const editModeStateSlice = createSlice({
|
|||
state.highlightedCode = payload.highlightedCode;
|
||||
state.editStatus = "not-started";
|
||||
state.previousInputs = [];
|
||||
state.fileAfterEdit = undefined;
|
||||
},
|
||||
submitEdit: (state, { payload }: PayloadAction<MessageContent>) => {
|
||||
state.previousInputs.push(payload);
|
||||
state.editStatus = "streaming";
|
||||
},
|
||||
setEditStatus: (state, { payload }: PayloadAction<EditStatus>) => {
|
||||
setEditStatus: (
|
||||
state,
|
||||
{
|
||||
payload,
|
||||
}: PayloadAction<{ status: EditStatus; fileAfterEdit?: string }>,
|
||||
) => {
|
||||
// Only allow valid transitions
|
||||
const currentStatus = state.editStatus;
|
||||
if (currentStatus === "not-started" && payload === "streaming") {
|
||||
state.editStatus = payload;
|
||||
} else if (currentStatus === "streaming" && payload === "accepting") {
|
||||
state.editStatus = payload;
|
||||
} else if (currentStatus === "accepting" && payload === "done") {
|
||||
state.editStatus = payload;
|
||||
} else if (currentStatus === "done" && payload === "not-started") {
|
||||
state.editStatus = payload;
|
||||
if (currentStatus === "not-started" && payload.status === "streaming") {
|
||||
state.editStatus = payload.status;
|
||||
} else if (
|
||||
currentStatus === "streaming" &&
|
||||
payload.status === "accepting"
|
||||
) {
|
||||
state.editStatus = payload.status;
|
||||
state.fileAfterEdit = payload.fileAfterEdit;
|
||||
} else if (currentStatus === "accepting" && payload.status === "done") {
|
||||
state.editStatus = payload.status;
|
||||
} else if (
|
||||
currentStatus === "accepting:full-diff" &&
|
||||
payload.status === "done"
|
||||
) {
|
||||
state.editStatus = payload.status;
|
||||
} else if (
|
||||
currentStatus === "accepting" &&
|
||||
payload.status === "accepting:full-diff"
|
||||
) {
|
||||
state.editStatus = payload.status;
|
||||
} else if (
|
||||
currentStatus === "accepting:full-diff" &&
|
||||
payload.status === "accepting"
|
||||
) {
|
||||
state.editStatus = payload.status;
|
||||
} else if (currentStatus === "done" && payload.status === "not-started") {
|
||||
state.editStatus = payload.status;
|
||||
}
|
||||
},
|
||||
addPreviousInput: (state, { payload }: PayloadAction<MessageContent>) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue