diff --git a/core/index.d.ts b/core/index.d.ts index b8e941f28..1bad9fd74 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -45,12 +45,12 @@ export interface IndexingProgressUpdate { debugInfo?: string; } -export type PromptTemplate = - | string - | (( - history: ChatMessage[], - otherData: Record, - ) => string | ChatMessage[]); +export type PromptTemplateFunction = ( + history: ChatMessage[], + otherData: Record, +) => string | ChatMessage[]; + +export type PromptTemplate = string | PromptTemplateFunction; export interface ILLM extends LLMOptions { get providerName(): ModelProvider; diff --git a/core/llm/constants.ts b/core/llm/constants.ts index 52265d509..59a9c301a 100644 --- a/core/llm/constants.ts +++ b/core/llm/constants.ts @@ -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, diff --git a/core/llm/templates/edit.ts b/core/llm/templates/edit.ts index ce0c0dc75..e6ad4d6b6 100644 --- a/core/llm/templates/edit.ts +++ b/core/llm/templates/edit.ts @@ -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}}{{fileSuffix}}"; const START_TAG = ""; @@ -76,7 +34,7 @@ const osModelsEditPrompt: PromptTemplate = (history, otherData) => { !firstCharOfFirstLine; const suffixTag = isSuffix ? "" : ""; const suffixExplanation = isSuffix - ? " When you get to \"\", end your response." + ? ' When you get to "", 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 diff --git a/core/llm/templates/edit/claude.ts b/core/llm/templates/edit/claude.ts new file mode 100644 index 000000000..5ec103fa9 --- /dev/null +++ b/core/llm/templates/edit/claude.ts @@ -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"); +}; diff --git a/core/llm/templates/edit/gpt.ts b/core/llm/templates/edit/gpt.ts new file mode 100644 index 000000000..4dcc39523 --- /dev/null +++ b/core/llm/templates/edit/gpt.ts @@ -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"); +}; diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 55cb3a9b9..040f4445d 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -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]; }; diff --git a/core/util/dedent.test.ts b/core/util/dedent.test.ts index 3b0d526e1..95908ab4a 100644 --- a/core/util/dedent.test.ts +++ b/core/util/dedent.test.ts @@ -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} +\`\`\``); + }); }); diff --git a/core/util/index.ts b/core/util/index.ts index 531ff1959..7f46278f9 100644 --- a/core/util/index.ts +++ b/core/util/index.ts @@ -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( 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"); } diff --git a/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts b/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts index a7018196c..8c8c399a7 100644 --- a/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts +++ b/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts @@ -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("enableDebugLogs", false); diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 980eb7ab4..217f33e6d 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -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 }; - diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 197a2c111..4733dee6f 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -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, diff --git a/extensions/vscode/src/diff/vertical/manager.ts b/extensions/vscode/src/diff/vertical/manager.ts index 56be062ae..5c6ca0884 100644 --- a/extensions/vscode/src/diff/vertical/manager.ts +++ b/extensions/vscode/src/diff/vertical/manager.ts @@ -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 { 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", diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 96ab1fa1a..b4e9749da 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -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) => { diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 0ab40cb03..42a1182e6 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -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 () => { diff --git a/gui/src/components/find/FindWidget.tsx b/gui/src/components/find/FindWidget.tsx index 3089803da..266a09cd8 100644 --- a/gui/src/components/find/FindWidget.tsx +++ b/gui/src/components/find/FindWidget.tsx @@ -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) => { // 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(); diff --git a/gui/src/components/index.ts b/gui/src/components/index.ts index 7a04bf43a..3a384c995 100644 --- a/gui/src/components/index.ts +++ b/gui/src/components/index.ts @@ -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); } diff --git a/gui/src/pages/edit/EditInputHeader.tsx b/gui/src/pages/edit/EditInputHeader.tsx new file mode 100644 index 000000000..b7b66de8c --- /dev/null +++ b/gui/src/pages/edit/EditInputHeader.tsx @@ -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 ( + <> +
+
+
+ + {getBasename(editModeState.highlightedCode.filepath)} ( + {editModeState.highlightedCode.range.start.line}- + {editModeState.highlightedCode.range.end.line}) +
+ {editModeState.editStatus === "accepting" || + editModeState.editStatus === "accepting:full-diff" ? ( +
+ {/* {editModeState.editStatus === "accepting" ? ( + <> + + + + + N diffs remaining + + + ) : ( +
hi
+ )} */} + +
+ + { + ideMessenger.request("edit/acceptReject", { + accept: false, + onlyFirst: false, + filepath: editModeState.highlightedCode.filepath, + }); + dispatch(setEditDone()); + }} + > + + + { + ideMessenger.request("edit/acceptReject", { + accept: true, + onlyFirst: false, + filepath: editModeState.highlightedCode.filepath, + }); + dispatch(setEditDone()); + }} + > + +
+
+ ) : null} +
+
+ + ); +} diff --git a/gui/src/pages/edit.tsx b/gui/src/pages/edit/index.tsx similarity index 61% rename from gui/src/pages/edit.tsx rename to gui/src/pages/edit/index.tsx index 9faf01578..5b1b71e66 100644 --- a/gui/src/pages/edit.tsx +++ b/gui/src/pages/edit/index.tsx @@ -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() {
-
{ - ideMessenger.ide.showLines( - editModeState.highlightedCode.filepath, - editModeState.highlightedCode.range.start.line, - editModeState.highlightedCode.range.end.line, - ); - setShowCode(!showCode); - }} - > - - {getBasename(editModeState.highlightedCode.filepath)} ( - {editModeState.highlightedCode.range.start.line}- - {editModeState.highlightedCode.range.end.line}) -
-
- } + header={} 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() { - {["accepting", "streaming"].includes(editModeState.editStatus) && ( -
- { - ideMessenger.request("edit/acceptReject", { - accept: false, - onlyFirst: false, - filepath: editModeState.highlightedCode.filepath, - }); - dispatch(setEditDone()); - }} - > - {getMetaKeyLabel()}⇧⌫ Reject all - - { - ideMessenger.request("edit/acceptReject", { - accept: true, - onlyFirst: false, - filepath: editModeState.highlightedCode.filepath, - }); - dispatch(setEditDone()); - }} - > - {getMetaKeyLabel()}⇧⏎ Accept all - -
- )} -
{ diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 4e3e82fc2..78bbcd262 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -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 ( <> diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index 4c5defeef..38091ccbf 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -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) => { state.previousInputs.push(payload); state.editStatus = "streaming"; }, - setEditStatus: (state, { payload }: PayloadAction) => { + 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) => {