diff --git a/core/autocomplete/context/ImportDefinitionsService.ts b/core/autocomplete/context/ImportDefinitionsService.ts index 525834a95..128dbf78e 100644 --- a/core/autocomplete/context/ImportDefinitionsService.ts +++ b/core/autocomplete/context/ImportDefinitionsService.ts @@ -1,5 +1,4 @@ -import { IDE } from "../.."; -import { RangeInFileWithContents } from "../../commands/util"; +import { IDE, RangeInFileWithContents } from "../.."; import { PrecalculatedLruCache } from "../../util/LruCache"; import { getFullLanguageName, diff --git a/core/autocomplete/context/ranking/index.ts b/core/autocomplete/context/ranking/index.ts index 3e83afca5..e68763746 100644 --- a/core/autocomplete/context/ranking/index.ts +++ b/core/autocomplete/context/ranking/index.ts @@ -1,7 +1,6 @@ -import { RangeInFileWithContents } from "../../../commands/util.js"; -import { Range } from "../../../index.js"; -import { countTokens } from "../../../llm/countTokens.js"; -import { HelperVars } from "../../util/HelperVars.js"; +import { Range, RangeInFileWithContents } from "../../../"; +import { countTokens } from "../../../llm/countTokens"; +import { HelperVars } from "../../util/HelperVars"; export type AutocompleteSnippet = RangeInFileWithContents & { score?: number; diff --git a/core/autocomplete/context/ranking/slidingWindow.ts b/core/autocomplete/context/ranking/slidingWindow.ts index 7b650eb44..61c505c13 100644 --- a/core/autocomplete/context/ranking/slidingWindow.ts +++ b/core/autocomplete/context/ranking/slidingWindow.ts @@ -1,6 +1,6 @@ -import { RangeInFileWithContents } from "../../../commands/util.js"; +import { RangeInFileWithContents } from "../../../"; -import { AutocompleteSnippet, jaccardSimilarity } from "./index.js"; +import { AutocompleteSnippet, jaccardSimilarity } from "./"; function* slidingWindow( content: string, diff --git a/core/autocomplete/util/ast.ts b/core/autocomplete/util/ast.ts index 6bd6e1f88..241c42fb9 100644 --- a/core/autocomplete/util/ast.ts +++ b/core/autocomplete/util/ast.ts @@ -1,7 +1,7 @@ import Parser from "web-tree-sitter"; -import { RangeInFileWithContents } from "../../commands/util.js"; -import { getParserForFile } from "../../util/treeSitter.js"; +import { RangeInFileWithContents } from "../../"; +import { getParserForFile } from "../../util/treeSitter"; export type AstPath = Parser.SyntaxNode[]; diff --git a/core/autocomplete/util/types.ts b/core/autocomplete/util/types.ts index cb9064b62..8d531d026 100644 --- a/core/autocomplete/util/types.ts +++ b/core/autocomplete/util/types.ts @@ -1,5 +1,10 @@ -import { Position, Range, RangeInFile, TabAutocompleteOptions } from "../.."; -import { RangeInFileWithContents } from "../../commands/util"; +import { + Position, + Range, + RangeInFile, + RangeInFileWithContents, + TabAutocompleteOptions, +} from "../.."; export type RecentlyEditedRange = RangeInFile & { timestamp: number; diff --git a/core/commands/slash/edit.ts b/core/commands/slash/edit.ts index 78d86beee..a8f8db944 100644 --- a/core/commands/slash/edit.ts +++ b/core/commands/slash/edit.ts @@ -1,4 +1,9 @@ -import { ContextItemWithId, ILLM, SlashCommand } from "../../"; +import { + ContextItemWithId, + ILLM, + RangeInFileWithContents, + SlashCommand, +} from "../../"; import { filterCodeBlockLines, filterEnglishLinesAtEnd, @@ -13,10 +18,7 @@ import { dedentAndGetCommonWhitespace, getMarkdownLanguageTagForFile, } from "../../util/"; -import { - ctxItemToRifWithContents, - type RangeInFileWithContents, -} from "../util"; +import { ctxItemToRifWithContents } from "../util"; const PROMPT = `Take the file prefix and suffix into account, but only rewrite the code_to_edit as specified in the user_request. The code you write in modified_code_to_edit will replace the code between the code_to_edit tags. Do NOT preface your answer or write anything other than code. The tag should be written to indicate the end of the modified code section. Do not ever use nested tags. @@ -478,10 +480,18 @@ const EditSlashCommand: SlashCommand = { messages = rendered; } - const completion = llm.streamComplete(rendered as string, new AbortController().signal, { - maxTokens: Math.min(maxTokens, Math.floor(llm.contextLength / 2), 4096), - raw: true, - }); + const completion = llm.streamComplete( + rendered as string, + new AbortController().signal, + { + maxTokens: Math.min( + maxTokens, + Math.floor(llm.contextLength / 2), + 4096, + ), + raw: true, + }, + ); let lineStream = streamLines(completion); lineStream = filterEnglishLinesAtStart(lineStream); @@ -494,14 +504,18 @@ const EditSlashCommand: SlashCommand = { ); } else { async function* gen() { - for await (const chunk of llm.streamChat(messages, new AbortController().signal,{ - temperature: 0.5, // TODO - maxTokens: Math.min( - maxTokens, - Math.floor(llm.contextLength / 2), - 4096, - ), - })) { + for await (const chunk of llm.streamChat( + messages, + new AbortController().signal, + { + temperature: 0.5, // TODO + maxTokens: Math.min( + maxTokens, + Math.floor(llm.contextLength / 2), + 4096, + ), + }, + )) { yield stripImages(chunk.content); } } @@ -609,7 +623,10 @@ ${lines.join("\n")} Please briefly explain the changes made to the code above. Give no more than 2-3 sentences, and use markdown bullet points:`; - for await (const update of llm.streamComplete(prompt, new AbortController().signal)) { + for await (const update of llm.streamComplete( + prompt, + new AbortController().signal, + )) { yield update; } } diff --git a/core/commands/util.ts b/core/commands/util.ts index a6be440e9..74266e70f 100644 --- a/core/commands/util.ts +++ b/core/commands/util.ts @@ -1,13 +1,4 @@ -import { ContextItemWithId } from "../"; - -export interface RangeInFileWithContents { - filepath: string; - range: { - start: { line: number; character: number }; - end: { line: number; character: number }; - }; - contents: string; -} +import { ContextItemWithId, RangeInFileWithContents } from "../"; export function ctxItemToRifWithContents( item: ContextItemWithId, diff --git a/core/index.d.ts b/core/index.d.ts index ce2e59449..d08b00b11 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -106,7 +106,7 @@ export interface ILLM extends LLMOptions { complete( prompt: string, signal: AbortSignal, - options?: LLMFullCompletionOptions + options?: LLMFullCompletionOptions, ): Promise; streamComplete( @@ -1012,6 +1012,37 @@ interface ModelRoles { repoMapFileSelection?: string; } +export type EditStatus = + | "not-started" + | "streaming" + | "accepting" + | "accepting:full-diff" + | "done"; + +export type ApplyStateStatus = + | "streaming" // Changes are being applied to the file + | "done" // All changes have been applied, awaiting user to accept/reject + | "closed"; // All changes have been applied. Note that for new files, we immediately set the status to "closed" + +export interface ApplyState { + streamId: string; + status?: ApplyStateStatus; + numDiffs?: number; + filepath?: string; + fileContent?: string; +} + +export interface RangeInFileWithContents { + filepath: string; + range: { + start: { line: number; character: number }; + end: { line: number; character: number }; + }; + contents: string; +} + +export type CodeToEdit = RangeInFileWithContents | FileWithContents; + /** * Represents the configuration for a quick action in the Code Lens. * Quick actions are custom commands that can be added to function and class declarations. diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 4dd0aa2d8..a4d9f923a 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -1,8 +1,14 @@ -import { ToIdeFromWebviewOrCoreProtocol } from "./ide.js"; -import { ToWebviewFromIdeOrCoreProtocol } from "./webview.js"; +import { ToIdeFromWebviewOrCoreProtocol } from "./ide"; +import { ToWebviewFromIdeOrCoreProtocol } from "./webview"; -import type { RangeInFileWithContents } from "../commands/util.js"; -import type { ContextSubmenuItem, MessageContent } from "../index.js"; +import type { + ApplyState, + CodeToEdit, + ContextSubmenuItem, + EditStatus, + MessageContent, + RangeInFileWithContents, +} from "../"; export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { onLoad: [ @@ -54,26 +60,6 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { "edit/escape": [undefined, void]; }; -export type EditStatus = - | "not-started" - | "streaming" - | "accepting" - | "accepting:full-diff" - | "done"; - -export type ApplyStateStatus = - | "streaming" // Changes are being applied to the file - | "done" // All changes have been applied, awaiting user to accept/reject - | "closed"; // All changes have been applied. Note that for new files, we immediately set the status to "closed" - -export interface ApplyState { - streamId: string; - status?: ApplyStateStatus; - numDiffs?: number; - filepath?: string; - fileContent?: string; -} - export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { setInactive: [undefined, void]; submitMessage: [{ message: any }, void]; // any -> JSONContent from TipTap @@ -94,7 +80,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { }, void, ]; - addCodeToEdit: [RangeInFileWithContents, void]; + addCodeToEdit: [CodeToEdit, void]; navigateTo: [{ path: string; toggle?: boolean }, void]; addModel: [undefined, void]; @@ -118,4 +104,5 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { setEditStatus: [{ status: EditStatus; fileAfterEdit?: string }, void]; exitEditMode: [undefined, void]; focusEdit: [undefined, void]; + focusEditWithoutClear: [undefined, void]; }; diff --git a/extensions/vscode/src/autocomplete/lsp.ts b/extensions/vscode/src/autocomplete/lsp.ts index f900058ab..90b034a2e 100644 --- a/extensions/vscode/src/autocomplete/lsp.ts +++ b/extensions/vscode/src/autocomplete/lsp.ts @@ -2,7 +2,6 @@ import { GetLspDefinitionsFunction } from "core/autocomplete/CompletionProvider" import { AutocompleteLanguageInfo } from "core/autocomplete/constants/AutocompleteLanguageInfo"; import { AutocompleteSnippet } from "core/autocomplete/context/ranking"; import { getAst, getTreePathAtCursor } from "core/autocomplete/util/ast"; -import { RangeInFileWithContents } from "core/commands/util"; import { FUNCTION_BLOCK_NODE_TYPES, FUNCTION_DECLARATION_NODE_TYPEs, @@ -10,7 +9,7 @@ import { import { intersection } from "core/util/ranges"; import * as vscode from "vscode"; -import type { IDE, Range, RangeInFile } from "core"; +import type { IDE, Range, RangeInFile, RangeInFileWithContents } from "core"; import type Parser from "web-tree-sitter"; type GotoProviderName = @@ -134,7 +133,9 @@ async function crawlTypes( // Parse AST const ast = await getAst(rif.filepath, contents); - if (!ast) {return results;} + if (!ast) { + return results; + } const astLineCount = ast.rootNode.text.split("\n").length; // Find type identifiers @@ -343,10 +344,14 @@ export const getDefinitionsFromLsp: GetLspDefinitionsFunction = async ( ): Promise => { try { const ast = await getAst(filepath, contents); - if (!ast) {return [];} + if (!ast) { + return []; + } const treePath = await getTreePathAtCursor(ast, cursorIndex); - if (!treePath) {return [];} + if (!treePath) { + return []; + } const results: RangeInFileWithContents[] = []; for (const node of treePath.reverse()) { diff --git a/extensions/vscode/src/autocomplete/recentlyEdited.ts b/extensions/vscode/src/autocomplete/recentlyEdited.ts index 0b206eab2..221d7df66 100644 --- a/extensions/vscode/src/autocomplete/recentlyEdited.ts +++ b/extensions/vscode/src/autocomplete/recentlyEdited.ts @@ -1,6 +1,6 @@ +import { RangeInFileWithContents } from "core"; import { getSymbolsForSnippet } from "core/autocomplete/context/ranking"; import { RecentlyEditedRange } from "core/autocomplete/util/types"; -import { RangeInFileWithContents } from "core/commands/util"; import * as vscode from "vscode"; type VsCodeRecentlyEditedRange = { diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index b4252f8dd..22e9fe10b 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -3,9 +3,8 @@ import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; -import { ContextMenuConfig } from "core"; +import { ContextMenuConfig, RangeInFileWithContents } from "core"; import { CompletionProvider } from "core/autocomplete/CompletionProvider"; -import { RangeInFileWithContents } from "core/commands/util"; import { ConfigHandler } from "core/config/ConfigHandler"; import { getModelByRole } from "core/config/util"; import { ContinueServerClient } from "core/continueServer/stubs/client"; @@ -201,6 +200,58 @@ function hideGUI() { } } +async function processDiff( + action: "accept" | "reject", + sidebar: ContinueGUIWebviewViewProvider, + diffManager: DiffManager, + ide: VsCodeIde, + verticalDiffManager: VerticalDiffManager, + newFilepath?: string | vscode.Uri, + streamId?: string, +) { + captureCommandTelemetry(`${action}Diff`); + + let fullPath = newFilepath; + + if (fullPath instanceof vscode.Uri) { + fullPath = fullPath.fsPath; + } else if (fullPath) { + fullPath = getFullyQualifiedPath(ide, fullPath); + } else { + console.warn(`Unable to resolve filepath: ${newFilepath}`); + } + + if (!fullPath) return; + + await ide.openFile(fullPath); + + // Clear vertical diffs depending on action + verticalDiffManager.clearForFilepath(fullPath, action === "accept"); + + // Accept or reject the diff + if (action === "accept") { + await diffManager.acceptDiff(fullPath); + } else { + await diffManager.rejectDiff(fullPath); + } + + void sidebar.webviewProtocol.request("setEditStatus", { + status: "done", + }); + + if (streamId) { + const fileContent = await ide.readFile(fullPath); + + await sidebar.webviewProtocol.request("updateApplyState", { + fileContent, + filepath: fullPath, + streamId, + status: "closed", + numDiffs: 0, + }); + } +} + // Copy everything over from extension.ts const commandsMap: ( ide: VsCodeIde, @@ -267,77 +318,34 @@ const commandsMap: ( range, ); } - return { "continue.acceptDiff": async ( newFilepath?: string | vscode.Uri, streamId?: string, - ) => { - captureCommandTelemetry("acceptDiff"); + ) => + processDiff( + "accept", + sidebar, + diffManager, + ide, + verticalDiffManager, + newFilepath, + streamId, + ), - let fullPath = newFilepath; - - if (fullPath instanceof vscode.Uri) { - fullPath = fullPath.fsPath; - } else if (fullPath) { - fullPath = getFullyQualifiedPath(ide, fullPath); - } else { - console.warn(`Unable to resolve filepath: ${newFilepath}`); - } - - verticalDiffManager.clearForFilepath(fullPath, true); - await diffManager.acceptDiff(fullPath); - - void sidebar.webviewProtocol.request("setEditStatus", { - status: "done", - }); - - if (streamId && fullPath) { - const fileContent = await ide.readFile(fullPath); - - await sidebar.webviewProtocol.request("updateApplyState", { - fileContent, - filepath: fullPath, - streamId: streamId, - status: "closed", - numDiffs: 0, - }); - } - }, "continue.rejectDiff": async ( newFilepath?: string | vscode.Uri, streamId?: string, - ) => { - captureCommandTelemetry("rejectDiff"); - - let fullPath = newFilepath; - - if (fullPath instanceof vscode.Uri) { - fullPath = fullPath.fsPath; - } else if (fullPath) { - fullPath = getFullyQualifiedPath(ide, fullPath); - } else { - console.warn(`Unable to resolve filepath: ${newFilepath}`); - } - - verticalDiffManager.clearForFilepath(fullPath, false); - await diffManager.rejectDiff(fullPath); - void sidebar.webviewProtocol.request("setEditStatus", { - status: "done", - }); - - if (streamId && fullPath) { - const fileContent = await ide.readFile(fullPath); - - await sidebar.webviewProtocol.request("updateApplyState", { - fileContent, - filepath: fullPath, - streamId: streamId, - status: "closed", - numDiffs: 0, - }); - } - }, + ) => + processDiff( + "reject", + sidebar, + diffManager, + ide, + verticalDiffManager, + newFilepath, + streamId, + ), "continue.acceptVerticalDiffBlock": (filepath?: string, index?: number) => { captureCommandTelemetry("acceptVerticalDiffBlock"); verticalDiffManager.acceptRejectVerticalDiffBlock(true, filepath, index); @@ -453,8 +461,6 @@ const commandsMap: ( void addHighlightedCodeToContext(sidebar.webviewProtocol); } }, - // TODO - "continue.focusEditWithoutClear": async () => {}, "continue.focusEdit": async () => { captureCommandTelemetry("focusEdit"); focusGUI(); @@ -501,6 +507,51 @@ const commandsMap: ( sidebar.webviewProtocol?.request("focusContinueInput", undefined); }, 30); }, + "continue.focusEditWithoutClear": async () => { + captureCommandTelemetry("focusEditWithoutClear"); + focusGUI(); + + sidebar.webviewProtocol?.request("focusEditWithoutClear", undefined); + + const editor = vscode.window.activeTextEditor; + + if (!editor) { + return; + } + + const document = editor.document; + + const existingDiff = verticalDiffManager.getHandlerForFile( + document.fileName, + ); + + // If there's a diff currently being applied, then we just toggle focus back to the input + if (existingDiff) { + sidebar.webviewProtocol?.request("focusContinueInput", undefined); + return; + } + + const rangeInFileWithContents = getCurrentlyHighlightedCode(false); + + if (rangeInFileWithContents) { + sidebar.webviewProtocol?.request( + "addCodeToEdit", + rangeInFileWithContents, + ); + } else { + const filepath = document.uri.fsPath; + const contents = document.getText(); + + sidebar.webviewProtocol?.request("addCodeToEdit", { + filepath, + contents, + }); + } + + setTimeout(() => { + sidebar.webviewProtocol?.request("focusContinueInput", undefined); + }, 30); + }, "continue.exitEditMode": async () => { captureCommandTelemetry("exitEditMode"); await sidebar.webviewProtocol?.request("exitEditMode", undefined); diff --git a/extensions/vscode/src/diff/vertical/handler.ts b/extensions/vscode/src/diff/vertical/handler.ts index 3286749a6..c68619277 100644 --- a/extensions/vscode/src/diff/vertical/handler.ts +++ b/extensions/vscode/src/diff/vertical/handler.ts @@ -1,4 +1,3 @@ -import { ApplyState } from "core/protocol/ideWebview"; import * as vscode from "vscode"; import { @@ -10,7 +9,7 @@ import { } from "./decorations"; import type { VerticalDiffCodeLens } from "./manager"; -import type { DiffLine } from "core"; +import type { ApplyState, DiffLine } from "core"; export interface VerticalDiffHandlerOptions { input?: string; diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 3b5baad5f..b031241c6 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -255,7 +255,9 @@ export class VsCodeMessenger { llm, fastLlm, ); + const verticalDiffManager = await this.verticalDiffManagerPromise; + if (instant) { await verticalDiffManager.streamDiffLines( diffLines, diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index f4598ec8f..b7006a9a8 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -12,6 +12,7 @@ import { setEditStatus, addCodeToEdit, focusEdit, + clearCodeToEdit, } from "../redux/slices/editModeState"; import { setShowDialog } from "../redux/slices/uiStateSlice"; import { @@ -192,6 +193,16 @@ const Layout = () => { useWebviewListener( "focusEdit", + async () => { + dispatch(focusEdit()); + dispatch(clearCodeToEdit()); + navigate("/edit"); + }, + [navigate], + ); + + useWebviewListener( + "focusEditWithoutClear", async () => { dispatch(focusEdit()); navigate("/edit"); diff --git a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx b/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx index 6a2574bc0..c6f06979d 100644 --- a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx +++ b/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx @@ -13,6 +13,8 @@ export default function AcceptRejectAllButtons({ onAcceptOrReject, }: AcceptRejectAllButtonsProps) { const ideMessenger = useContext(IdeMessengerContext); + + // To handle the case of a single-range edit const hasSinglePendingApplyStates = pendingApplyStates.length === 1; async function handleAcceptOrReject(status: "acceptDiff" | "rejectDiff") { diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 67d71eee8..bde052274 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -4,7 +4,7 @@ import Image from "@tiptap/extension-image"; import Paragraph from "@tiptap/extension-paragraph"; import Placeholder from "@tiptap/extension-placeholder"; import Text from "@tiptap/extension-text"; -import { Plugin, PluginKey } from "@tiptap/pm/state"; +import { Plugin } from "@tiptap/pm/state"; import { Editor, EditorContent, JSONContent, useEditor } from "@tiptap/react"; import { ContextItemWithId, diff --git a/gui/src/hooks/useNavigationListener.tsx b/gui/src/hooks/useNavigationListener.tsx index cadc40330..503b4a997 100644 --- a/gui/src/hooks/useNavigationListener.tsx +++ b/gui/src/hooks/useNavigationListener.tsx @@ -1,5 +1,5 @@ import type { ToWebviewProtocol } from "core/protocol"; -import { useLocation, useNavigate } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import { v4 as uuidv4 } from "uuid"; import { useWebviewListener } from "./useWebviewListener"; diff --git a/gui/src/pages/Edit/CodeToEdit.tsx b/gui/src/pages/Edit/CodeToEdit.tsx index a97bdc5e3..7f990415b 100644 --- a/gui/src/pages/Edit/CodeToEdit.tsx +++ b/gui/src/pages/Edit/CodeToEdit.tsx @@ -1,13 +1,13 @@ -import { InformationCircleIcon, PlusIcon } from "@heroicons/react/24/outline"; +import { PlusIcon } from "@heroicons/react/24/outline"; import { useContext } from "react"; import { useDispatch, useSelector } from "react-redux"; import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { CodeToEdit, removeCodeToEdit } from "../../redux/slices/editModeState"; +import { removeCodeToEdit } from "../../redux/slices/editModeState"; import { RootState } from "../../redux/store"; import CodeToEditListItem from "./CodeToEditListItem"; -import { RangeInFileWithContents } from "core/commands/util"; import { vscEditorBackground } from "../../components"; import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice"; +import { CodeToEdit, RangeInFileWithContents } from "core"; export default function WorkingSet() { const dispatch = useDispatch(); @@ -16,6 +16,15 @@ export default function WorkingSet() { const hasCodeToEdit = editModeState.codeToEdit.length > 0; + const addFileText = hasCodeToEdit ? "Add file" : "Add a file to get started"; + + const title = + editModeState.codeToEdit.length === 0 + ? "Code to edit" + : editModeState.codeToEdit.length === 1 + ? "Code to edit (1 item)" + : `Code to edit (${editModeState.codeToEdit.length} items)`; + function onDelete(rif: RangeInFileWithContents) { dispatch(removeCodeToEdit(rif)); } @@ -48,37 +57,24 @@ export default function WorkingSet() { )); return ( -
-
- Code to edit +
+
+ {title} - Add file + {addFileText}
-
- {hasCodeToEdit ? ( -
    - {codeToEditItems} -
- ) : ( - - - Add a file to get started - - )} -
+ {hasCodeToEdit && ( +
    + {codeToEditItems} +
+ )}
); } diff --git a/gui/src/pages/Edit/CodeToEditListItem.tsx b/gui/src/pages/Edit/CodeToEditListItem.tsx index 7f872a4ae..f6ddca996 100644 --- a/gui/src/pages/Edit/CodeToEditListItem.tsx +++ b/gui/src/pages/Edit/CodeToEditListItem.tsx @@ -9,12 +9,12 @@ import { useState } from "react"; import StyledMarkdownPreview from "../../components/markdown/StyledMarkdownPreview"; import { getMarkdownLanguageTagForFile } from "core/util"; import styled from "styled-components"; -import { CodeToEdit } from "../../redux/slices/editModeState"; +import { CodeToEdit } from "core"; export interface CodeToEditListItemProps { code: CodeToEdit; - onDelete: (code: CodeToEdit) => void; - onClickFilename: (code: CodeToEdit) => void; + onDelete: (codeToEdit: CodeToEdit) => void; + onClickFilename: (codeToEdit: CodeToEdit) => void; } // Easiest method to overwrite the top level styling of the markdown preview @@ -26,7 +26,7 @@ const NoPaddingWrapper = styled.div` pre { margin: 0 !important; - padding: 0 !important; + padding: 0px 0px 0px 10px !important; } `; @@ -35,13 +35,13 @@ export default function CodeToEditListItem({ onDelete, onClickFilename, }: CodeToEditListItemProps) { - const [showCodeSnippet, setShowCodeSnippet] = useState(true); + const [showCodeSnippet, setShowCodeSnippet] = useState(false); const filepath = code.filepath.split("/").pop() || code.filepath; let title = filepath; if ("range" in code) { - title += `(${code.range.start.line + 1} - ${code.range.end.line + 1})`; + title += ` (${code.range.start.line + 1} - ${code.range.end.line + 1})`; } const source = @@ -54,11 +54,11 @@ export default function CodeToEditListItem({ return (
  • setShowCodeSnippet((showCodeSnippet) => !showCodeSnippet)} >
    {showCodeSnippet ? ( @@ -67,7 +67,7 @@ export default function CodeToEditListItem({ e.stopPropagation(); setShowCodeSnippet(false); }} - className="h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 text-gray-400 transition-colors hover:bg-white/10" + className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 hover:bg-opacity-20" /> ) : ( )} @@ -95,7 +95,7 @@ export default function CodeToEditListItem({ e.stopPropagation(); onDelete(code); }} - className="h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 text-gray-400 transition-colors hover:bg-white/10" + className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 hover:bg-opacity-20" />
    diff --git a/gui/src/pages/Edit/Edit.tsx b/gui/src/pages/Edit/Edit.tsx index 4c201bf29..522f99fda 100644 --- a/gui/src/pages/Edit/Edit.tsx +++ b/gui/src/pages/Edit/Edit.tsx @@ -20,7 +20,6 @@ import useChatHandler from "../../hooks/useChatHandler"; import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectAllButtons"; import ContinueInputBox from "../../components/mainInput/ContinueInputBox"; import StepContainer from "../../components/StepContainer"; -import styled from "styled-components"; import getMultifileEditPrompt from "./getMultifileEditPrompt"; import { RangeInFileWithContents } from "core/commands/util"; @@ -121,14 +120,6 @@ export default function Edit() { stripImages(userInstructions), ].join("\n\n"); - const codeToEdit = editModeState.codeToEdit[0]; - - let rif: RangeInFileWithContents = { - filepath: codeToEdit.filepath, - contents: codeToEdit.contents, - range: "range" in codeToEdit ? codeToEdit.range : undefined, - }; - ideMessenger.post("edit/sendPrompt", { prompt, range: editModeState.codeToEdit[0] as RangeInFileWithContents, diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index 9f370c95a..489bc7b41 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -1,9 +1,5 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { FileWithContents, MessageContent } from "core"; -import { RangeInFileWithContents } from "core/commands/util"; -import { EditStatus } from "core/protocol/ideWebview"; - -export type CodeToEdit = RangeInFileWithContents | FileWithContents; +import { CodeToEdit, EditStatus, MessageContent } from "core"; interface EditModeState { editStatus: EditStatus; @@ -20,15 +16,22 @@ const initialState: EditModeState = { isInEditMode: false, }; +function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) { + return a.filepath === b.filepath && a.contents === b.contents; +} + export const editModeStateSlice = createSlice({ name: "editModeState", initialState, reducers: { addCodeToEdit: (state, { payload }: PayloadAction) => { - state.codeToEdit.push(payload); - state.editStatus = "not-started"; - state.previousInputs = []; - state.fileAfterEdit = undefined; + const entryExists = state.codeToEdit.some((entry) => + isCodeToEditEqual(entry, payload), + ); + + if (!entryExists) { + state.codeToEdit.push(payload); + } }, focusEdit: (state) => { state.isInEditMode = true; @@ -42,11 +45,7 @@ export const editModeStateSlice = createSlice({ }, removeCodeToEdit: (state, { payload }: PayloadAction) => { state.codeToEdit = state.codeToEdit.filter( - (entry) => - !( - entry.filepath === payload.filepath && - entry.contents === payload.contents - ), + (entry) => !isCodeToEditEqual(entry, payload), ); }, clearCodeToEdit: (state) => { diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 17c317ee5..71e26711d 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -1,6 +1,7 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit"; import { JSONContent } from "@tiptap/react"; import { + ApplyState, ChatHistoryItem, ChatMessage, Checkpoint, @@ -13,7 +14,6 @@ import { import { BrowserSerializedContinueConfig } from "core/config/load"; import { ConfigValidationError } from "core/config/validation"; import { stripImages } from "core/llm/images"; -import { ApplyState } from "core/protocol/ideWebview"; import { v4 as uuidv4, v4 } from "uuid"; // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array. diff --git a/gui/tailwind.config.cjs b/gui/tailwind.config.cjs index 5758b18db..bc8b5273e 100644 --- a/gui/tailwind.config.cjs +++ b/gui/tailwind.config.cjs @@ -25,6 +25,7 @@ module.exports = { "spin-slow": "spin 6s linear infinite", }, colors: { + lightgray: "#999998", "vsc-background": "rgb(var(--vsc-background) / )", "secondary-dark": "rgb(var(--secondary-dark) / )", "vsc-input-background": "var(--vscode-input-background, rgb(45 45 45))",