diff --git a/core/commands/slash/index.ts b/core/commands/slash/index.ts index 544673901..18008e251 100644 --- a/core/commands/slash/index.ts +++ b/core/commands/slash/index.ts @@ -2,7 +2,6 @@ import GenerateTerminalCommand from "./cmd"; import CommitMessageCommand from "./commit"; import DraftIssueCommand from "./draftIssue"; import HttpSlashCommand from "./http"; -import MultiFileEditSlashCommand from "./multifileEdit"; import OnboardSlashCommand from "./onboard"; import ReviewMessageCommand from "./review"; import ShareSlashCommand from "./share"; @@ -15,5 +14,4 @@ export default [ CommitMessageCommand, ReviewMessageCommand, OnboardSlashCommand, - MultiFileEditSlashCommand, ]; diff --git a/core/commands/slash/multifileEdit.ts b/core/commands/slash/multifileEdit.ts deleted file mode 100644 index c8cf64679..000000000 --- a/core/commands/slash/multifileEdit.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { SlashCommand } from "../.."; -import { stripImages } from "../../llm/images"; - -const MultiFileEditSlashCommand: SlashCommand = { - name: "multifile-edit", - description: "Edit multiple files in the codebase at once", - run: async function* ({ llm, contextItems, selectedCode, input, ide }) { - // TODO: This is causing GUI builds to fail, so we're disabling it for now - // const selectedCodeStr = ( - // await Promise.all( - // selectedCode.map(async (item) => { - // // Split the range string from the filename, e.g. `filename.ts (1-2) -> [filename.ts, (1-2)]` - // const [filepath, rangeStr] = item.filepath.split(" "); - // const { getFullyQualifiedPath } = await import( - // "../../../extensions/vscode/src/util/util" - // ); - // const fullPath = getFullyQualifiedPath(ide as any, filepath); // any = VsCodeIde here, but importing it breaks tests - // if (!fullPath) { - // return ""; - // } - // const codeStr = await ide.readRangeInFile(fullPath, item.range); - // // Include the filepath so the model can map it correctly with codeblock outputs - // return `\`\`\`${fullPath} ${rangeStr}\n${codeStr}\`\`\``; - // }), - // ) - // ).join("\n"); - - const fileContextItemsStr = contextItems - .filter((item) => item.uri?.type === "file") - .map((item) => item.content) - .join("\n"); - - const filesToEditStr = fileContextItemsStr + "\n"; // + selectedCodeStr; - - const additionalContextStr = contextItems - .filter((item) => item.uri?.type !== "file") - .map((item) => `${item.description}: ${item.content}`) - .join("\n"); - - const content = createPrompt(filesToEditStr, additionalContextStr, input); - - for await (const chunk of llm.streamChat([{ role: "user", content }], new AbortController().signal)) { - yield stripImages(chunk.content); - } - }, -}; - -function createPrompt( - filesToEditStr: string, - additionalContextStr: string, - input: string, -): string { - return ` -You are an AI assistant designed to help software engineers make multi-file edits in their codebase. Your task is to generate the necessary code changes for multiple files based on the engineer's request. Follow these guidelines: - -1. Start with a brief introduction of the task you're about to perform. Do not start with any other preamble, such as "Certainly!" -2. When providing instructions, if a user needs to interact with a CLI, walk them through each step -2. Perform file edits in a logical, sequential ordering -3. For each file edit, provide a brief explanation of the changes -4. If the user submits a code block that contains a filename in the language specifier, always include the filename in any code block you generate based on that file. The filename should be on the same line as the language specifier in your code block. - a. When creating new files, also inlcude the filname in the language specifier of the code block. -6. After providing all file changes, include a brief, sequential overview of the most important 3-5 edits - -Remember to be concise and focus on the code changes and their impact. - -Here's an example of how your response should be structured: - - -I'll make the following changes to implement feature X: - -1. First, I'll modify file1.js to add a new function: -\`\`\`javascript /path/to/file1.js -// Entire content of file1.js or changes to be made -\`\`\` - -2. Next, let's create a new test file: -\`\`\`javascript /path/to/file1.test.js -# Entire content of file2.py or changes to be made -\`\`\` - -Summary: -- [Sequential overview of the most important 3-5 edits] - - -Now, let's make the changes based on the engineer's request: - - -${input} - - -Here are the files to base your edits on: - - -${filesToEditStr} - - -And here is any additional context the engineer has provided: - - -${additionalContextStr} - - -Please provide the multi-file edit details based on the engineer's request. - `; -} - -export default MultiFileEditSlashCommand; diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 3dc6757e7..940503505 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.231", + "version": "0.9.232", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.231", + "version": "0.9.232", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 14cd63249..00be6a870 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -15,7 +15,7 @@ import { } from "../redux/slices/editModeState"; import { setShowDialog } from "../redux/slices/uiStateSlice"; import { - setIsInMultifileEdit, + setIsInEditMode, updateApplyState, updateCurCheckpoint, } from "../redux/slices/stateSlice"; @@ -195,7 +195,7 @@ const Layout = () => { "focusEdit", async (payload) => { // TODO: Move into edit state - dispatch(setIsInMultifileEdit(true)); + dispatch(setIsInEditMode(true)); dispatch(focusEdit(payload)); navigate("/edit"); diff --git a/gui/src/components/StepContainer/MultifileEditActions.tsx b/gui/src/components/StepContainer/EditActions.tsx similarity index 97% rename from gui/src/components/StepContainer/MultifileEditActions.tsx rename to gui/src/components/StepContainer/EditActions.tsx index 603d6e15a..c5bf7699f 100644 --- a/gui/src/components/StepContainer/MultifileEditActions.tsx +++ b/gui/src/components/StepContainer/EditActions.tsx @@ -12,7 +12,7 @@ export interface MultifileEditActionsProps { item: ChatHistoryItem; } -export default function MultifileEditActions({ +export default function EditActions({ index, item, }: MultifileEditActionsProps) { diff --git a/gui/src/components/StepContainer/ResponseActions.tsx b/gui/src/components/StepContainer/ResponseActions.tsx index 66d62575c..0aa08ccd6 100644 --- a/gui/src/components/StepContainer/ResponseActions.tsx +++ b/gui/src/components/StepContainer/ResponseActions.tsx @@ -6,7 +6,7 @@ import { useSelector } from "react-redux"; import { RootState } from "../../redux/store"; import { ChatHistoryItem } from "core"; import FeedbackButtons from "./FeedbackButtons"; -import MultifileEditActions from "./MultifileEditActions"; +import EditActions from "./EditActions"; export interface ResponseActionsProps { isTruncated: boolean; @@ -23,15 +23,15 @@ export default function ResponseActions({ isTruncated, onDelete, }: ResponseActionsProps) { - const isInMultifileEdit = useSelector( - (store: RootState) => store.state.isMultifileEdit, + const isInEditMode = useSelector( + (store: RootState) => store.editModeState.isInEditMode, ); // Only render delete button if there is more than one message const shouldRenderDelete = index !== 1; - if (isInMultifileEdit) { - return ; + if (isInEditMode) { + return ; } return ( diff --git a/gui/src/components/StepContainer/StepContainer.tsx b/gui/src/components/StepContainer/StepContainer.tsx index 4fdd6eda2..0c56cf40a 100644 --- a/gui/src/components/StepContainer/StepContainer.tsx +++ b/gui/src/components/StepContainer/StepContainer.tsx @@ -31,13 +31,13 @@ export default function StepContainer(props: StepContainerProps) { const curCheckpointIndex = useSelector( (store: RootState) => store.state.curCheckpointIndex, ); - const isMultifileEdit = useSelector( - (store: RootState) => store.state.isMultifileEdit, + const isInEditMode = useSelector( + (store: RootState) => store.editModeState.isInEditMode, ); const uiConfig = useUIConfig(); const shouldHideActions = active && props.isLast; const isStepAheadOfCurCheckpoint = - isMultifileEdit && Math.floor(props.index / 2) > curCheckpointIndex; + isInEditMode && Math.floor(props.index / 2) > curCheckpointIndex; useEffect(() => { if (!active) { diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 65c148f57..960f27e75 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -65,6 +65,7 @@ import { } from "./handleMetaKeyIssues"; import { ComboBoxItem } from "./types"; import useIsOSREnabled from "../../hooks/useIsOSREnabled"; +import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice"; const InputBoxDiv = styled.div<{ border?: string }>` resize: none; @@ -170,6 +171,7 @@ function TipTapEditor(props: TipTapEditorProps) { const historyLength = useSelector( (store: RootState) => store.state.history.length, ); + const useActiveFile = useSelector(selectUseActiveFile); const { saveSession, loadSession } = useHistory(dispatch); @@ -183,11 +185,13 @@ function TipTapEditor(props: TipTapEditorProps) { const isOSREnabled = useIsOSREnabled(); - const isMultifileEdit = useSelector( - (state: RootState) => state.state.isMultifileEdit, + const isInEditMode = useSelector( + (state: RootState) => state.editModeState.isInEditMode, ); - console.log("isMultifileEdit", isMultifileEdit); + const shouldAddFileForEditing = useSelector( + (state: RootState) => state.uiState.shouldAddFileForEditing, + ); const enterSubmenu = async (editor: Editor, providerId: string) => { const contents = editor.getText(); @@ -473,7 +477,7 @@ function TipTapEditor(props: TipTapEditorProps) { }, }) : undefined, - isMultifileEdit + isInEditMode ? Mention.configure({ HTMLAttributes: { class: "mention", @@ -808,6 +812,13 @@ function TipTapEditor(props: TipTapEditorProps) { const [activeKey, setActiveKey] = useState(null); + useEffect(() => { + if (shouldAddFileForEditing && props.isMainInput) { + insertCharacterWithWhitespace("#"); + dispatch(setShouldAddFileForEditing(false)); + } + }, [shouldAddFileForEditing]); + const insertCharacterWithWhitespace = useCallback( (char: string) => { const text = editor.getText(); diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 5bed71147..4692e1bb1 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -68,11 +68,11 @@ export default function StepContainerPreToolbar( const ideMessenger = useContext(IdeMessengerContext); const streamIdRef = useRef(uuidv4()); const wasGeneratingRef = useRef(props.isGeneratingCodeBlock); - const isMultifileEdit = useSelector( - (state: RootState) => state.state.isMultifileEdit, + const isInEditMode = useSelector( + (state: RootState) => state.editModeState.isInEditMode, ); const active = useSelector((state: RootState) => state.state.active); - const [isExpanded, setIsExpanded] = useState(isMultifileEdit ? false : true); + const [isExpanded, setIsExpanded] = useState(isInEditMode ? false : true); const [codeBlockContent, setCodeBlockContent] = useState(""); const isChatActive = useSelector((state: RootState) => state.state.active); @@ -135,7 +135,7 @@ export default function StepContainerPreToolbar( useEffect(() => { const hasCompletedGenerating = wasGeneratingRef.current && !isGeneratingCodeBlock; - const shouldAutoApply = hasCompletedGenerating && isMultifileEdit; + const shouldAutoApply = hasCompletedGenerating && isInEditMode; if (shouldAutoApply) { onClickApply(); diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index ca1ea2afd..ff8cbfbfb 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -166,7 +166,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( // So in this case we just put them in refs const symbolsRef = useRef([]); const contextItemsRef = useRef([]); - + useEffect(() => { contextItemsRef.current = contextItems || []; }, [contextItems]); diff --git a/gui/src/pages/Edit/CodeToEdit.tsx b/gui/src/pages/Edit/CodeToEdit.tsx index 1bfac2d0d..81b2dc609 100644 --- a/gui/src/pages/Edit/CodeToEdit.tsx +++ b/gui/src/pages/Edit/CodeToEdit.tsx @@ -8,6 +8,7 @@ import CodeToEditListItem from "./CodeToEditListItem"; import { RangeInFileWithContents } from "core/commands/util"; import { vscEditorBackground } from "../../components"; import { ToolTip } from "../../components/gui/Tooltip"; +import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice"; export default function WorkingSet() { const dispatch = useDispatch(); @@ -20,7 +21,9 @@ export default function WorkingSet() { dispatch(removeEntryFromCodeToEdit(rif)); } - function onClickAddFileToCodeToEdit() {} + function onClickAddFileToCodeToEdit() { + dispatch(setShouldAddFileForEditing(true)); + } function onClickFilename(rif: RangeInFileWithContents) { const { filepath, range } = editModeState.codeToEdit.find( @@ -44,7 +47,7 @@ export default function WorkingSet() { className="mx-1 flex flex-col rounded-t-lg px-1 pb-1" style={{ backgroundColor: vscEditorBackground }} > -
+
Code to edit {hasCodeToEdit ? ( -
    +
      {codeToEditItems}
    ) : ( diff --git a/gui/src/pages/Edit/CodeToEditListItem.tsx b/gui/src/pages/Edit/CodeToEditListItem.tsx index 7668f702f..a39d40ed4 100644 --- a/gui/src/pages/Edit/CodeToEditListItem.tsx +++ b/gui/src/pages/Edit/CodeToEditListItem.tsx @@ -3,12 +3,12 @@ import FileIcon from "../../components/FileIcon"; import { ChevronDownIcon, ChevronRightIcon, - ChevronUpIcon, XMarkIcon, } from "@heroicons/react/24/outline"; import { useState } from "react"; import StyledMarkdownPreview from "../../components/markdown/StyledMarkdownPreview"; import { getMarkdownLanguageTagForFile } from "core/util"; +import styled from "styled-components"; export interface CodeToEditListItemProps { rif: RangeInFileWithContents; @@ -16,6 +16,19 @@ export interface CodeToEditListItemProps { onClickFilename: (rif: RangeInFileWithContents) => void; } +// Easiest method to overwrite the top level styling of the markdown preview +const NoPaddingWrapper = styled.div` + > * { + margin: 0 !important; + padding: 0 !important; + } + + pre { + margin: 0 !important; + padding: 0 !important; + } +`; + export default function CodeToEditListItem({ rif, onDelete, @@ -36,12 +49,13 @@ export default function CodeToEditListItem({ return (
  • setShowCodeSnippet((showCodeSnippet) => !showCodeSnippet)} > - {" "} -
    -
    +
    +
    {showCodeSnippet ? ( { @@ -61,7 +75,7 @@ export default function CodeToEditListItem({ )} { e.stopPropagation(); onClickFilename(rif); @@ -81,8 +95,10 @@ export default function CodeToEditListItem({
    {showCodeSnippet && ( -
    - +
    + + +
    )}
  • diff --git a/gui/src/pages/Edit/Edit.tsx b/gui/src/pages/Edit/Edit.tsx index 93aae4c3b..8a1280a6b 100644 --- a/gui/src/pages/Edit/Edit.tsx +++ b/gui/src/pages/Edit/Edit.tsx @@ -58,7 +58,11 @@ export default function Edit() { (store: RootState) => store.state.config.contextProviders, ); - const state = useSelector((state: RootState) => state.state); + const history = useSelector((state: RootState) => state.state.history); + + const applyStates = useSelector( + (state: RootState) => state.state.applyStates, + ); const applyState = useSelector( (store: RootState) => @@ -83,11 +87,7 @@ export default function Edit() { } }, [applyState, editModeState.editStatus]); - const applyStates = useSelector( - (state: RootState) => state.state.applyStates, - ); - - const active = useSelector((state: RootState) => state.state.active); + // const active = useSelector((state: RootState) => state.state.active); const pendingApplyStates = applyStates.filter( (state) => state.status === "done", @@ -98,8 +98,8 @@ export default function Edit() { editModeState.editStatus === "accepting"; const toolbarOptions = { - hideAddContext: true, - hideImageUpload: true, + hideAddContext: false, + hideImageUpload: false, hideUseCodebase: true, hideSelectModel: false, enterText: isStreaming ? "Retry" : "Edit", @@ -124,6 +124,7 @@ export default function Edit() { }, ideMessenger, [], + dispatch, ); const prompt = [ @@ -166,11 +167,11 @@ export default function Edit() { const isLastUserInput = useCallback( (index: number): boolean => { - return !state.history + return !history .slice(index + 1) .some((entry) => entry.message.role === "user"); }, - [state.history], + [history], ); return ( @@ -181,7 +182,7 @@ export default function Edit() {
- {!isSingleFileEdit && state.history.length > 1 && ( + {!isSingleFileEdit && history.length > 1 && (
- {state.history.slice(1).map((item, index: number) => ( + {history.slice(1).map((item, index: number) => (
{item.message.role === "user" ? ( )} diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index dc872f5c3..a4c5ac1fa 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -8,12 +8,14 @@ interface EditModeState { previousInputs: MessageContent[]; fileAfterEdit?: string; codeToEdit: RangeInFileWithContents[]; + isInEditMode: boolean; } const initialState: EditModeState = { editStatus: "not-started", previousInputs: [], codeToEdit: [], + isInEditMode: false, }; export const editModeStateSlice = createSlice({ @@ -98,6 +100,9 @@ export const editModeStateSlice = createSlice({ state.editStatus = "done"; state.previousInputs = []; }, + setIsInEditMode: (state, { payload }: PayloadAction) => { + state.isInEditMode = payload; + }, }, }); @@ -110,5 +115,6 @@ export const { removeEntryFromCodeToEdit, focusEdit, clearCodeToEdit, + setIsInEditMode, } = editModeStateSlice.actions; export default editModeStateSlice.reducer; diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 770e9ce69..bc4f6ce63 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -46,7 +46,6 @@ type State = { statuses: Record; }; streamAborter: AbortController; - isMultifileEdit: boolean; }; const initialState: State = { @@ -78,7 +77,6 @@ const initialState: State = { defaultModelTitle: "GPT-4", selectedProfileId: "local", checkpoints: [], - isMultifileEdit: false, curCheckpointIndex: 0, nextCodeBlockToApplyIndex: 0, applyStates: [], @@ -308,7 +306,6 @@ export const stateSlice = createSlice({ state.active = false; state.context.isGathering = false; - state.isMultifileEdit = false; state.symbols = {}; if (payload) { state.history = payload.history as any; @@ -374,10 +371,6 @@ export const stateSlice = createSlice({ selectedProfileId: payload, }; }, - - setIsInMultifileEdit: (state, { payload }: PayloadAction) => { - state.isMultifileEdit = payload; - }, setCurCheckpointIndex: (state, { payload }: PayloadAction) => { state.curCheckpointIndex = payload; }, @@ -472,7 +465,6 @@ export const { setSelectedProfileId, deleteMessage, setIsGatheringContext, - setIsInMultifileEdit, updateCurCheckpoint, setCurCheckpointIndex, resetNextCodeBlockToApplyIndex, diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts index f4b531c39..9a13415d3 100644 --- a/gui/src/redux/slices/uiStateSlice.ts +++ b/gui/src/redux/slices/uiStateSlice.ts @@ -9,6 +9,7 @@ type UiState = { dialogMessage: string | JSX.Element | undefined; dialogEntryOn: boolean; onboardingCard: OnboardingCardState; + shouldAddFileForEditing: boolean; }; export const uiStateSlice = createSlice({ @@ -18,6 +19,7 @@ export const uiStateSlice = createSlice({ dialogMessage: "", dialogEntryOn: false, onboardingCard: defaultOnboardingCardState, + shouldAddFileForEditing: false, } as UiState, reducers: { setOnboardingCard: ( @@ -41,6 +43,12 @@ export const uiStateSlice = createSlice({ setShowDialog: (state, action: PayloadAction) => { state.showDialog = action.payload; }, + setShouldAddFileForEditing: ( + state, + action: PayloadAction, + ) => { + state.shouldAddFileForEditing = action.payload; + }, }, }); @@ -49,6 +57,7 @@ export const { setDialogMessage, setDialogEntryOn, setShowDialog, + setShouldAddFileForEditing, } = uiStateSlice.actions; export default uiStateSlice.reducer;