From e36bef8a16de0cb6ec5edbf42ab2ef69b3104007 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 15:24:49 -0700 Subject: [PATCH 01/25] edit mode state updates --- gui/src/components/AcceptRejectAllButtons.tsx | 23 +----- gui/src/components/Layout.tsx | 17 ++-- .../OnboardingLocalTab.tsx | 4 +- .../platform/PlatformOnboardingCard.tsx | 2 +- .../components/OnboardingCard/tabs/index.ts | 2 +- .../StepContainer/ResponseActions.tsx | 5 +- .../StepContainerPreToolbar/index.tsx | 10 +-- .../dialogs/FreeTrialOverDialog.tsx | 9 +-- .../components/mainInput/ContinueInputBox.tsx | 52 +++++++------ gui/src/components/mainInput/InputToolbar.tsx | 15 ++-- .../mainInput/TipTapEditor/TipTapEditor.tsx | 11 ++- .../useMainEditorWebviewListeners.ts | 6 +- .../TipTapEditor/utils/editorConfig.ts | 21 ++--- .../components/modelSelection/ModeSelect.tsx | 8 +- .../components/modelSelection/ModelSelect.tsx | 23 +++--- gui/src/pages/gui/Chat.tsx | 67 ++++++---------- gui/src/pages/gui/EmptyChatBody.tsx | 9 +-- gui/src/pages/gui/StreamError.tsx | 21 ++--- gui/src/redux/selectors/index.ts | 3 - gui/src/redux/slices/editModeState.ts | 72 ++++++++++++++++- gui/src/redux/slices/sessionSlice.ts | 77 +------------------ gui/src/redux/store.ts | 3 +- gui/src/redux/thunks/exitEditMode.ts | 21 ++--- gui/src/util/getMultifileEditPrompt.ts | 62 --------------- 24 files changed, 194 insertions(+), 349 deletions(-) rename gui/src/components/OnboardingCard/{tabs => components}/OnboardingLocalTab.tsx (97%) delete mode 100644 gui/src/util/getMultifileEditPrompt.ts diff --git a/gui/src/components/AcceptRejectAllButtons.tsx b/gui/src/components/AcceptRejectAllButtons.tsx index 7a9c28062..5ffbabbf1 100644 --- a/gui/src/components/AcceptRejectAllButtons.tsx +++ b/gui/src/components/AcceptRejectAllButtons.tsx @@ -2,8 +2,6 @@ import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { ApplyState } from "core"; import { useContext } from "react"; import { IdeMessengerContext } from "../context/IdeMessenger"; -import { useAppSelector } from "../redux/hooks"; -import { selectIsSingleRangeEditOrInsertion } from "../redux/slices/sessionSlice"; import { getMetaKeyLabel } from "../util"; export interface AcceptRejectAllButtonsProps { @@ -18,7 +16,6 @@ export default function AcceptRejectAllButtons({ onAcceptOrReject, }: AcceptRejectAllButtonsProps) { const ideMessenger = useContext(IdeMessengerContext); - const isSingleRangeEdit = useAppSelector(selectIsSingleRangeEditOrInsertion); async function handleAcceptOrReject(status: AcceptOrRejectOutcome) { for (const { filepath = "", streamId } of pendingApplyStates) { @@ -41,15 +38,7 @@ export default function AcceptRejectAllButtons({ data-testid="edit-reject-button" > - {isSingleRangeEdit ? ( - Reject ({getMetaKeyLabel()}⇧⌫) - ) : ( - <> - Reject - Reject all - Reject all changes - - )} + Reject ({getMetaKeyLabel()}⇧⌫) ); diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 0c5acda83..7844a3e04 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -6,13 +6,12 @@ import { AuthProvider } from "../context/Auth"; import { LocalStorageProvider } from "../context/LocalStorage"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; -import { focusEdit, setEditStatus } from "../redux/slices/editModeState"; import { addCodeToEdit, - newSession, - selectIsInEditMode, - setMode, -} from "../redux/slices/sessionSlice"; + focusEdit, + setEditStatus, +} from "../redux/slices/editModeState"; +import { newSession, setMode } from "../redux/slices/sessionSlice"; import { setShowDialog } from "../redux/slices/uiSlice"; import { exitEditMode } from "../redux/thunks"; import { loadLastSession, saveCurrentSession } from "../redux/thunks/session"; @@ -172,7 +171,7 @@ const Layout = () => { async (payload) => { dispatch(addCodeToEdit(payload)); }, - [navigate], + [], ); useWebviewListener( @@ -183,11 +182,11 @@ const Layout = () => { [], ); - const isInEditMode = useAppSelector(selectIsInEditMode); + const mode = useAppSelector((store) => store.session.mode); useWebviewListener( "exitEditMode", async () => { - if (!isInEditMode) { + if (mode !== "edit") { return; } dispatch( @@ -197,7 +196,7 @@ const Layout = () => { ); dispatch(exitEditMode()); }, - [isInEditMode], + [mode], ); useEffect(() => { diff --git a/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx b/gui/src/components/OnboardingCard/components/OnboardingLocalTab.tsx similarity index 97% rename from gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx rename to gui/src/components/OnboardingCard/components/OnboardingLocalTab.tsx index 7e99f430d..b0cc6f179 100644 --- a/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx +++ b/gui/src/components/OnboardingCard/components/OnboardingLocalTab.tsx @@ -12,9 +12,9 @@ import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useAppDispatch } from "../../../redux/hooks"; import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; import { updateSelectedModelByRole } from "../../../redux/thunks"; -import OllamaModelDownload from "../components/OllamaModelDownload"; -import { OllamaStatus } from "../components/OllamaStatus"; import { useSubmitOnboarding } from "../hooks"; +import OllamaModelDownload from "./OllamaModelDownload"; +import { OllamaStatus } from "./OllamaStatus"; const OLLAMA_CHECK_INTERVAL_MS = 3000; diff --git a/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx b/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx index 69eed3ffb..883ea66d1 100644 --- a/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx +++ b/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx @@ -5,8 +5,8 @@ import { getLocalStorage, setLocalStorage } from "../../../util/localStorage"; import Alert from "../../gui/Alert"; import { ReusableCard } from "../../ReusableCard"; import { TabTitle } from "../components/OnboardingCardTabs"; +import OnboardingLocalTab from "../components/OnboardingLocalTab"; import { useOnboardingCard } from "../hooks"; -import OnboardingLocalTab from "../tabs/OnboardingLocalTab"; import MainTab from "./tabs/main"; export interface OnboardingCardState { diff --git a/gui/src/components/OnboardingCard/tabs/index.ts b/gui/src/components/OnboardingCard/tabs/index.ts index 7e975a8ec..1e6aae37d 100644 --- a/gui/src/components/OnboardingCard/tabs/index.ts +++ b/gui/src/components/OnboardingCard/tabs/index.ts @@ -1,3 +1,3 @@ +export { default as Local } from "../components/OnboardingLocalTab"; export { default as Best } from "./OnboardingBestTab"; -export { default as Local } from "./OnboardingLocalTab"; export { default as Quickstart } from "./OnboardingQuickstartTab"; diff --git a/gui/src/components/StepContainer/ResponseActions.tsx b/gui/src/components/StepContainer/ResponseActions.tsx index dce39ea6f..c49daccda 100644 --- a/gui/src/components/StepContainer/ResponseActions.tsx +++ b/gui/src/components/StepContainer/ResponseActions.tsx @@ -2,7 +2,6 @@ import { BarsArrowDownIcon, TrashIcon } from "@heroicons/react/24/outline"; import { ChatHistoryItem } from "core"; import { renderChatMessage } from "core/util/messageContent"; import { useAppSelector } from "../../redux/hooks"; -import { selectIsInEditMode } from "../../redux/slices/sessionSlice"; import FeedbackButtons from "../FeedbackButtons"; import { CopyIconButton } from "../gui/CopyIconButton"; import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; @@ -23,9 +22,9 @@ export default function ResponseActions({ isTruncated, onDelete, }: ResponseActionsProps) { - const isInEditMode = useAppSelector(selectIsInEditMode); + const mode = useAppSelector((store) => store.session.mode); - if (isInEditMode) { + if (mode === "edit") { return ; } diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index 6b299db18..44977514f 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -11,10 +11,7 @@ import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useIdeMessengerRequest } from "../../../hooks"; import { useWebviewListener } from "../../../hooks/useWebviewListener"; import { useAppSelector } from "../../../redux/hooks"; -import { - selectApplyStateByStreamId, - selectIsInEditMode, -} from "../../../redux/slices/sessionSlice"; +import { selectApplyStateByStreamId } from "../../../redux/slices/sessionSlice"; import { getFontSize } from "../../../util"; import { isTerminalCodeBlock } from "../utils"; import { ApplyActions } from "./ApplyActions"; @@ -74,10 +71,7 @@ export function StepContainerPreToolbar({ disableManualApply, }: StepContainerPreToolbarProps) { const ideMessenger = useContext(IdeMessengerContext); - const isInEditMode = useAppSelector(selectIsInEditMode); - const [isExpanded, setIsExpanded] = useState( - expanded ?? (isInEditMode ? false : true), - ); + const [isExpanded, setIsExpanded] = useState(expanded ?? true); const [relativeFilepathUri, setRelativeFilepathUri] = useState( null, diff --git a/gui/src/components/dialogs/FreeTrialOverDialog.tsx b/gui/src/components/dialogs/FreeTrialOverDialog.tsx index 107e351ce..a200b2f15 100644 --- a/gui/src/components/dialogs/FreeTrialOverDialog.tsx +++ b/gui/src/components/dialogs/FreeTrialOverDialog.tsx @@ -1,15 +1,12 @@ import { useEffect } from "react"; import { useDispatch } from "react-redux"; import { useAppSelector } from "../../redux/hooks"; -import { selectUseHub } from "../../redux/selectors"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; -import { OnboardingCard } from "../OnboardingCard"; import { PlatformOnboardingCard } from "../OnboardingCard/platform/PlatformOnboardingCard"; function FreeTrialOverDialog() { const dispatch = useDispatch(); const history = useAppSelector((store) => store.session.history); - const usePlatform = useAppSelector(selectUseHub); useEffect(() => { if (history.length === 0) { @@ -20,11 +17,7 @@ function FreeTrialOverDialog() { return (
- {usePlatform ? ( - - ) : ( - - )} +
); } diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index 14d4816f4..7540dae8d 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -11,7 +11,6 @@ import { Lump } from "./Lump"; import { TipTapEditor } from "./TipTapEditor"; interface ContinueInputBoxProps { - isEditMode?: boolean; isLastUserInput: boolean; isMainInput?: boolean; onEnter: ( @@ -82,36 +81,41 @@ function ContinueInputBox(props: ContinueInputBoxProps) { const availableContextProviders = useAppSelector( (state) => state.config.config.contextProviders, ); + const mode = useAppSelector((store) => store.session.mode); const editModeState = useAppSelector((state) => state.editModeState); - const filteredSlashCommands = props.isEditMode ? [] : availableSlashCommands; + const filteredSlashCommands = useMemo(() => { + return mode === "edit" ? [] : availableSlashCommands; + }, [mode, availableSlashCommands]); + const filteredContextProviders = useMemo(() => { - if (!props.isEditMode) { - return availableContextProviders ?? []; + if (mode === "edit") { + return ( + availableContextProviders?.filter( + (provider) => + !EDIT_DISALLOWED_CONTEXT_PROVIDERS.includes(provider.title), + ) ?? [] + ); } - return ( - availableContextProviders?.filter( - (provider) => - !EDIT_DISALLOWED_CONTEXT_PROVIDERS.includes(provider.title), - ) ?? [] - ); - }, [availableContextProviders]); + return availableContextProviders ?? []; + }, [availableContextProviders, mode]); - const historyKey = props.isEditMode ? "edit" : "chat"; - const placeholder = props.isEditMode - ? "Describe changes, '#' to add files" - : undefined; + const historyKey = mode === "edit" ? "edit" : "chat"; + const placeholder = + mode === "edit" ? "Describe changes, '#' to add files" : undefined; - const toolbarOptions: ToolbarOptions = props.isEditMode - ? { - hideAddContext: false, - hideImageUpload: false, - hideUseCodebase: true, - hideSelectModel: false, - enterText: editModeState.editStatus === "accepting" ? "Retry" : "Edit", - } - : {}; + const toolbarOptions: ToolbarOptions = + mode === "edit" + ? { + hideAddContext: false, + hideImageUpload: false, + hideUseCodebase: true, + hideSelectModel: false, + enterText: + editModeState.editStatus === "accepting" ? "Retry" : "Edit", + } + : {}; return (
(null); const defaultModel = useAppSelector(selectSelectedChatModel); const useActiveFile = useAppSelector(selectUseActiveFile); - const isInEditMode = useAppSelector(selectIsInEditMode); - const hasCodeToEdit = useAppSelector(selectHasCodeToEdit); + const mode = useAppSelector((store) => store.session.mode); + const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit); const toolCallState = useAppSelector(selectCurrentToolCall); - const isEditModeAndNoCodeToEdit = isInEditMode && !hasCodeToEdit; const currentToolCallApplyState = useAppSelector( selectCurrentToolCallApplyState, ); const isEnterDisabled = props.disabled || - isEditModeAndNoCodeToEdit || + (mode === "edit" && codeToEdit.length === 0) || toolCallState?.status === "generated" || (currentToolCallApplyState && currentToolCallApplyState.status !== "closed"); @@ -158,7 +153,7 @@ function InputToolbar(props: InputToolbarProps) { fontSize: tinyFont, }} > - {!props.toolbarOptions?.hideUseCodebase && !isInEditMode && ( + {!props.toolbarOptions?.hideUseCodebase && mode !== "edit" && ( )} - {isInEditMode && ( + {mode === "edit" && ( { diff --git a/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx index f5d172dc2..b9f341032 100644 --- a/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx @@ -7,7 +7,6 @@ import useIsOSREnabled from "../../../hooks/useIsOSREnabled"; import useUpdatingRef from "../../../hooks/useUpdatingRef"; import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; import { selectSelectedChatModel } from "../../../redux/slices/configSlice"; -import { selectIsInEditMode } from "../../../redux/slices/sessionSlice"; import InputToolbar, { ToolbarOptions } from "../InputToolbar"; import { ComboBoxItem } from "../types"; import { DragOverlay, InputBoxDiv } from "./components"; @@ -48,9 +47,9 @@ export function TipTapEditor(props: TipTapEditorProps) { const defaultModel = useAppSelector(selectSelectedChatModel); const isStreaming = useAppSelector((state) => state.session.isStreaming); - const isInEditMode = useAppSelector(selectIsInEditMode); const historyLength = useAppSelector((store) => store.session.history.length); + const mode = useAppSelector((store) => store.session.mode); const { editor, onEnterRef } = createEditorConfig({ props, ideMessenger, @@ -82,13 +81,13 @@ export function TipTapEditor(props: TipTapEditorProps) { }, [editor, props.placeholder, historyLength]); useEffect(() => { - if (isInEditMode) { + if (mode === "edit") { setShouldHideToolbar(false); } if (props.isMainInput) { editor?.commands.clearContent(true); } - }, [editor, isInEditMode, props.isMainInput]); + }, [editor, mode, props.isMainInput]); const editorFocusedRef = useUpdatingRef(editor?.isFocused, [editor]); @@ -148,7 +147,7 @@ export function TipTapEditor(props: TipTapEditorProps) { const handleBlur = useCallback( (e: React.FocusEvent) => { - if (isInEditMode) { + if (mode === "edit") { return; } // Check if the new focus target is within our InputBoxDiv @@ -163,7 +162,7 @@ export function TipTapEditor(props: TipTapEditorProps) { setShouldHideToolbar(true); }, 100); }, - [isInEditMode, blurTimeout], + [mode, blurTimeout], ); const handleFocus = useCallback(() => { diff --git a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts index 400f08019..15fd50a18 100644 --- a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts +++ b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts @@ -3,10 +3,8 @@ import { InputModifiers } from "core"; import { rifWithContentsToContextItem } from "core/commands/util"; import { MutableRefObject } from "react"; import { useWebviewListener } from "../../../hooks/useWebviewListener"; -import { - clearCodeToEdit, - setNewestToolbarPreviewForInput, -} from "../../../redux/slices/sessionSlice"; +import { clearCodeToEdit } from "../../../redux/slices/editModeState"; +import { setNewestToolbarPreviewForInput } from "../../../redux/slices/sessionSlice"; import { AppDispatch } from "../../../redux/store"; import { loadSession, saveCurrentSession } from "../../../redux/thunks/session"; import { CodeBlock, PromptBlock } from "./extensions"; diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index c4a70bb51..340190683 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -22,11 +22,7 @@ import useUpdatingRef from "../../../../hooks/useUpdatingRef"; import { useAppSelector } from "../../../../redux/hooks"; import { selectUseActiveFile } from "../../../../redux/selectors"; import { selectSelectedChatModel } from "../../../../redux/slices/configSlice"; -import { - addCodeToEdit, - selectHasCodeToEdit, - selectIsInEditMode, -} from "../../../../redux/slices/sessionSlice"; +import { addCodeToEdit } from "../../../../redux/slices/editModeState"; import { AppDispatch } from "../../../../redux/store"; import { exitEditMode } from "../../../../redux/thunks"; import { loadLastSession } from "../../../../redux/thunks/session"; @@ -87,15 +83,14 @@ export function createEditorConfig(options: { const isStreaming = useAppSelector((state) => state.session.isStreaming); const useActiveFile = useAppSelector(selectUseActiveFile); const historyLength = useAppSelector((store) => store.session.history.length); - const isInEditMode = useAppSelector(selectIsInEditMode); - const hasCodeToEdit = useAppSelector(selectHasCodeToEdit); - const isEditModeAndNoCodeToEdit = isInEditMode && !hasCodeToEdit; + const mode = useAppSelector((store) => store.session.mode); + const modeRef = useUpdatingRef(mode); + const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit); const inSubmenuRef = useRef(undefined); const inDropdownRef = useRef(false); const defaultModelRef = useUpdatingRef(defaultModel); const isStreamingRef = useUpdatingRef(isStreaming); - const isInEditModeRef = useUpdatingRef(isInEditMode); const getSubmenuContextItemsRef = useUpdatingRef(getSubmenuContextItems); const availableContextProvidersRef = useUpdatingRef( props.availableContextProviders, @@ -273,7 +268,7 @@ export function createEditorConfig(options: { return true; } - if (inDropdownRef.current || !isInEditModeRef.current) { + if (inDropdownRef.current || modeRef.current !== "edit") { ideMessenger.post("focusEditor", undefined); return true; } @@ -336,7 +331,7 @@ export function createEditorConfig(options: { inSubmenuRef, ideMessenger, ), - allow: () => isInEditModeRef.current, + allow: () => modeRef.current !== "edit", command: async ({ editor, range, props }) => { editor.chain().focus().insertContentAt(range, "").run(); const filepath = props.id; @@ -389,7 +384,7 @@ export function createEditorConfig(options: { if (!editor) { return; } - if (isStreaming || isEditModeAndNoCodeToEdit) { + if (isStreaming || (codeToEdit.length === 0 && mode === "edit")) { return; } @@ -406,7 +401,7 @@ export function createEditorConfig(options: { props.onEnter(json, modifiers, editor); }, - [props.onEnter, editor, props.isMainInput], + [props.onEnter, editor, props.isMainInput, codeToEdit, mode], ); return { editor, onEnterRef }; diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index b4cb94545..0ab3225f9 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -14,11 +14,7 @@ import { lightGray } from ".."; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { - cycleMode, - selectCurrentMode, - setMode, -} from "../../redux/slices/sessionSlice"; +import { cycleMode, setMode } from "../../redux/slices/sessionSlice"; import { exitEditMode } from "../../redux/thunks"; import { loadLastSession, @@ -40,7 +36,7 @@ const ShortcutText = styled.span` function ModeSelect() { const dispatch = useAppDispatch(); - const mode = useAppSelector(selectCurrentMode); + const mode = useAppSelector((store) => store.session.mode); const selectedModel = useAppSelector(selectSelectedChatModel); const currentSession = useAppSelector((state) => state.session); const [newSessionInitialized, setNewSessionInitialized] = useState(false); diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 88e1e6829..3523a7d9f 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -12,9 +12,6 @@ import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import AddModelForm from "../../forms/AddModelForm"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { - selectIsInEditMode, -} from "../../redux/slices/sessionSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import { updateSelectedModelByRole } from "../../redux/thunks"; import { getMetaKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; @@ -123,12 +120,12 @@ function ModelOption({ function ModelSelect() { const dispatch = useAppDispatch(); - const isInEditMode = useAppSelector(selectIsInEditMode); + const mode = useAppSelector((store) => store.session.mode); const config = useAppSelector((state) => state.config.config); let selectedModel = null; let allModels = null; - if (isInEditMode) { + if (mode === "edit") { allModels = config.modelsByRole.edit; selectedModel = config.selectedModelByRole.edit; } @@ -158,14 +155,14 @@ function ModelSelect() { useEffect(() => { setOptions( allModels.map((model) => { - return { - value: model.title, - title: modelSelectTitle(model), - apiKey: model.apiKey, - }; - }), + return { + value: model.title, + title: modelSelectTitle(model), + apiKey: model.apiKey, + }; + }), ); - }, [isInEditMode, config]); + }, [config]); useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { @@ -225,7 +222,7 @@ function ModelSelect() { dispatch( updateSelectedModelByRole({ selectedProfile, - role: isInEditMode ? "edit" : "chat", + role: mode === "edit" ? "edit" : "chat", modelTitle: val, }), ); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 4350ff56d..268e22e7a 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -29,7 +29,6 @@ import { TabBar } from "../../components/TabBar/TabBar"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { selectUseHub } from "../../redux/selectors"; import { selectCurrentToolCall, selectCurrentToolCallApplyState, @@ -38,8 +37,6 @@ import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { submitEdit } from "../../redux/slices/editModeState"; import { newSession, - selectIsInEditMode, - selectIsSingleRangeEditOrInsertion, updateToolCallOutput, } from "../../redux/slices/sessionSlice"; import { @@ -56,7 +53,7 @@ import { FREE_TRIAL_LIMIT_REQUESTS, incrementFreeTrialCount, } from "../../util/freeTrial"; -import getMultifileEditPrompt from "../../util/getMultifileEditPrompt"; + import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; @@ -115,7 +112,7 @@ export function Chat() { const showChatScrollbar = useAppSelector( (state) => state.config.config.ui?.showChatScrollbar, ); - const codeToEdit = useAppSelector((state) => state.session.codeToEdit); + const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); const toolCallState = useAppSelector(selectCurrentToolCall); const applyStates = useAppSelector( (state) => state.session.codeBlockApplyStates.states, @@ -124,12 +121,8 @@ export function Chat() { (state) => state.status === "done", ); const hasPendingApplies = pendingApplyStates.length > 0; - const isInEditMode = useAppSelector(selectIsInEditMode); - const isSingleRangeEditOrInsertion = useAppSelector( - selectIsSingleRangeEditOrInsertion, - ); + const mode = useAppSelector((store) => store.session.mode); const lastSessionId = useAppSelector((state) => state.session.lastSessionId); - const useHub = useAppSelector(selectUseHub); const hasDismissedExploreDialog = useAppSelector( (state) => state.ui.hasDismissedExploreDialog, ); @@ -206,18 +199,12 @@ export function Chat() { } } - if (isSingleRangeEditOrInsertion) { + if (mode === "edit") { handleSingleRangeEditOrInsertion(editorState); return; } - const promptPreamble = isInEditMode - ? getMultifileEditPrompt(codeToEdit) - : undefined; - - dispatch( - streamResponseThunk({ editorState, modifiers, promptPreamble, index }), - ); + dispatch(streamResponseThunk({ editorState, modifiers, index })); if (editorToClearOnSend) { editorToClearOnSend.commands.clearContent(); @@ -240,7 +227,7 @@ export function Chat() { history, selectedChatModel, streamResponse, - isSingleRangeEditOrInsertion, + mode, codeToEdit, toolCallState, ], @@ -314,8 +301,6 @@ export function Chat() { useAutoScroll(stepsDivRef, history); - const showPageHeader = isInEditMode || useHub; - return ( <> {widget} @@ -324,7 +309,7 @@ export function Chat() { 0 ? "flex-1" : ""}`} + className={`mt-3 overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${history.length > 0 ? "flex-1" : ""}`} > {highlights} {history.map((item, index: number) => ( @@ -342,14 +327,13 @@ export function Chat() { > {item.message.role === "user" ? ( <> - {isInEditMode && index === 0 && } + {mode === "edit" && } sendInput(editorState, modifiers, index) } isLastUserInput={isLastUserInput(index)} - isMainInput={false} + isMainInput={mode === "edit"} editorState={item.editorState} contextItems={item.contextItems} inputId={item.message.id} @@ -421,18 +405,18 @@ export function Chat() { ))}
- {isInEditMode && history.length === 0 && } - - {isInEditMode && history.length > 0 ? null : ( - - sendInput(editorState, modifiers, undefined, editor) - } - inputId={MAIN_EDITOR_INPUT_ID} - /> + {mode === "edit" && history.length > 0 ? null : ( + <> + {mode === "edit" && } + + sendInput(editorState, modifiers, undefined, editor) + } + inputId={MAIN_EDITOR_INPUT_ID} + /> + )}
- {history.length === 0 && lastSessionId && !isInEditMode && ( + {history.length === 0 && lastSessionId && mode !== "edit" && (
{ @@ -462,7 +446,7 @@ export function Chat() {
- {hasPendingApplies && isSingleRangeEditOrInsertion && ( + {hasPendingApplies && ( { @@ -481,10 +465,7 @@ export function Chat() { {!hasDismissedExploreDialog && } {history.length === 0 && ( - + )}
diff --git a/gui/src/pages/gui/EmptyChatBody.tsx b/gui/src/pages/gui/EmptyChatBody.tsx index dce70cdd5..ac8ba7631 100644 --- a/gui/src/pages/gui/EmptyChatBody.tsx +++ b/gui/src/pages/gui/EmptyChatBody.tsx @@ -4,18 +4,15 @@ import { OnboardingCard } from "../../components/OnboardingCard"; import { PlatformOnboardingCard } from "../../components/OnboardingCard/platform/PlatformOnboardingCard"; export interface EmptyChatBodyProps { - useHub: boolean; showOnboardingCard?: boolean; } -export function EmptyChatBody({ - useHub, - showOnboardingCard, -}: EmptyChatBodyProps) { +export function EmptyChatBody({ showOnboardingCard }: EmptyChatBodyProps) { if (showOnboardingCard) { return (
- {useHub ? ( + {true ? ( + // For now we are excluding local onboarding options other than ollama ) : ( diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index d098d2bc4..3d89a6245 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -11,7 +11,6 @@ import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { selectSelectedProfile } from "../../redux/"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { selectUseHub } from "../../redux/selectors"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import { isLocalProfile } from "../../util"; @@ -36,7 +35,6 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const selectedModel = useAppSelector(selectSelectedChatModel); - const hubEnabled = useAppSelector(selectUseHub); const selectedProfile = useAppSelector(selectSelectedProfile); const { session, refreshProfiles } = useAuth(); @@ -180,17 +178,14 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { if (statusCode === 401) { errorContent = (
- {hubEnabled && - session && - selectedProfile && - !isLocalProfile(selectedProfile) && ( -
- {`If your hub secret values may have changed, refresh your assistants`} - - Refresh assistant secrets - -
- )} + {session && selectedProfile && !isLocalProfile(selectedProfile) && ( +
+ {`If your hub secret values may have changed, refresh your assistants`} + + Refresh assistant secrets + +
+ )} {`It's possible that your API key is invalid.`}
{checkKeysButton} diff --git a/gui/src/redux/selectors/index.ts b/gui/src/redux/selectors/index.ts index bbfea5364..aa24f87b3 100644 --- a/gui/src/redux/selectors/index.ts +++ b/gui/src/redux/selectors/index.ts @@ -46,6 +46,3 @@ export const selectUseActiveFile = createSelector( [(state: RootState) => state.config.config.experimental?.defaultContext], (defaultContext) => defaultContext?.includes("activeFile" as any), ); - -export const selectUseHub = (state: RootState) => - state.config.config.usePlatform; diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index b0283a0ab..391da9200 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -1,15 +1,19 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { EditStatus, MessageContent } from "core"; +import { CodeToEdit, EditStatus, MessageContent } from "core"; export interface EditModeState { + codeToEdit: CodeToEdit[]; editStatus: EditStatus; previousInputs: MessageContent[]; fileAfterEdit?: string; + enteredEditModeFromEditor: boolean; } const initialState: EditModeState = { editStatus: "not-started", previousInputs: [], + codeToEdit: [], + enteredEditModeFromEditor: false, }; export const editModeStateSlice = createSlice({ @@ -69,6 +73,36 @@ export const editModeStateSlice = createSlice({ state.editStatus = "done"; state.previousInputs = []; }, + addCodeToEdit: ( + state, + { payload }: PayloadAction, + ) => { + const entries = Array.isArray(payload) ? payload : [payload]; + + const newEntries = entries.filter( + (entry) => + !state.codeToEdit.some((existingEntry) => + isCodeToEditEqual(existingEntry, entry), + ), + ); + + if (newEntries.length > 0) { + state.codeToEdit.push(...newEntries); + } + }, + removeCodeToEdit: (state, { payload }: PayloadAction) => { + state.codeToEdit = state.codeToEdit.filter( + (entry) => !isCodeToEditEqual(entry, payload), + ); + }, + clearCodeToEdit: (state) => { + state.codeToEdit = []; + }, + }, + selectors: { + selectHasCodeToEdit: (state) => { + return state.codeToEdit.length > 0; + }, }, }); @@ -78,5 +112,41 @@ export const { setEditDone, submitEdit, focusEdit, + clearCodeToEdit, + addCodeToEdit, + removeCodeToEdit, } = editModeStateSlice.actions; export default editModeStateSlice.reducer; + +function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) { + if (a.filepath !== b.filepath || a.contents !== b.contents) { + return false; + } + + if ("range" in a && "range" in b) { + const rangeA = a.range; + const rangeB = b.range; + + return ( + rangeA.start.line === rangeB.start.line && + rangeA.end.line === rangeB.end.line + ); + } + + // If neither has a range, they are considered equal in this context + return !("range" in a) && !("range" in b); +} + +export const { selectHasCodeToEdit } = editModeStateSlice.selectors; + +// selectIsSingleRangeEditOrInsertion: (state) => { +// if (state.mode !== "edit") { +// return false; +// } + +// const isInsertion = state.codeToEdit.length === 0; +// const selectIsSingleRangeEdit = +// state.codeToEdit.length === 1 && "range" in state.codeToEdit[0]; + +// return selectIsSingleRangeEdit || isInsertion; +// }, diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 5f74e0c50..5ef58dfff 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -10,7 +10,6 @@ import { ApplyState, ChatHistoryItem, ChatMessage, - CodeToEdit, ContextItem, ContextItemWithId, FileSymbolMap, @@ -44,7 +43,6 @@ type SessionState = { title: string; id: string; streamAborter: AbortController; - codeToEdit: CodeToEdit[]; curCheckpointIndex: number; mainEditorContentTrigger?: JSONContent | undefined; symbols: FileSymbolMap; @@ -56,25 +54,6 @@ type SessionState = { newestToolbarPreviewForInput: Record; }; -function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) { - if (a.filepath !== b.filepath || a.contents !== b.contents) { - return false; - } - - if ("range" in a && "range" in b) { - const rangeA = a.range; - const rangeB = b.range; - - return ( - rangeA.start.line === rangeB.start.line && - rangeA.end.line === rangeB.end.line - ); - } - - // If neither has a range, they are considered equal in this context - return !("range" in a) && !("range" in b); -} - const initialState: SessionState = { allSessionMetadata: [], history: [], @@ -83,7 +62,6 @@ const initialState: SessionState = { id: uuidv4(), curCheckpointIndex: 0, streamAborter: new AbortController(), - codeToEdit: [], symbols: {}, mode: "chat", codeBlockApplyStates: { @@ -584,31 +562,7 @@ export const sessionSlice = createSlice({ resetNextCodeBlockToApplyIndex: (state) => { state.codeBlockApplyStates.curIndex = 0; }, - addCodeToEdit: ( - state, - { payload }: PayloadAction, - ) => { - const entries = Array.isArray(payload) ? payload : [payload]; - const newEntries = entries.filter( - (entry) => - !state.codeToEdit.some((existingEntry) => - isCodeToEditEqual(existingEntry, entry), - ), - ); - - if (newEntries.length > 0) { - state.codeToEdit.push(...newEntries); - } - }, - removeCodeToEdit: (state, { payload }: PayloadAction) => { - state.codeToEdit = state.codeToEdit.filter( - (entry) => !isCodeToEditEqual(entry, payload), - ); - }, - clearCodeToEdit: (state) => { - state.codeToEdit = []; - }, // TOOL CALL STATE setToolGenerated: ( state, @@ -724,26 +678,6 @@ export const sessionSlice = createSlice({ const curHistoryItem = state.history.at(-1); return curHistoryItem?.isGatheringContext || false; }, - selectIsInEditMode: (state) => { - return state.mode === "edit"; - }, - selectCurrentMode: (state) => { - return state.mode; - }, - selectIsSingleRangeEditOrInsertion: (state) => { - if (state.mode !== "edit") { - return false; - } - - const isInsertion = state.codeToEdit.length === 0; - const selectIsSingleRangeEdit = - state.codeToEdit.length === 1 && "range" in state.codeToEdit[0]; - - return selectIsSingleRangeEdit || isInsertion; - }, - selectHasCodeToEdit: (state) => { - return state.codeToEdit.length > 0; - }, }, extraReducers: (builder) => { addPassthroughCases(builder, [streamResponseThunk]); @@ -811,9 +745,6 @@ export const { resetNextCodeBlockToApplyIndex, updateApplyState, abortStream, - clearCodeToEdit, - addCodeToEdit, - removeCodeToEdit, setToolCallCalling, cancelToolCall, errorToolCall, @@ -829,12 +760,6 @@ export const { cycleMode, } = sessionSlice.actions; -export const { - selectIsGatheringContext, - selectIsInEditMode, - selectCurrentMode, - selectIsSingleRangeEditOrInsertion, - selectHasCodeToEdit, -} = sessionSlice.selectors; +export const { selectIsGatheringContext } = sessionSlice.selectors; export default sessionSlice.reducer; diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index aa7c2bb5c..6a15431e0 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -47,7 +47,6 @@ const saveSubsetFilters = [ // Persist edit mode in case closes in middle "mode", - "codeToEdit", // higher risk to persist // codeBlockApplyStates @@ -55,7 +54,7 @@ const saveSubsetFilters = [ // curCheckpointIndex ]), // Don't persist any of the edit state for now - createFilter("editModeState", []), + createFilter("editModeState", ["codeToEdit"]), createFilter("config", ["defaultModelTitle"]), createFilter("ui", ["toolSettings", "toolGroupSettings"]), createFilter("indexing", []), diff --git a/gui/src/redux/thunks/exitEditMode.ts b/gui/src/redux/thunks/exitEditMode.ts index 438783499..9e5452e68 100644 --- a/gui/src/redux/thunks/exitEditMode.ts +++ b/gui/src/redux/thunks/exitEditMode.ts @@ -1,24 +1,17 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; -import { - clearCodeToEdit, - selectIsInEditMode, - selectIsSingleRangeEditOrInsertion, - setMainEditorContentTrigger, - setMode, -} from "../slices/sessionSlice"; +import { clearCodeToEdit, setEditDone } from "../slices/editModeState"; +import { setMainEditorContentTrigger, setMode } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; -import { setEditDone } from "../slices/editModeState"; export const exitEditMode = createAsyncThunk( "edit/complete", async (_, { dispatch, extra, getState }) => { const state = getState(); - const isInEditMode = selectIsInEditMode(state); - const codeToEdit = state.session.codeToEdit; - const isSingleRangeEditOrInsertion = - selectIsSingleRangeEditOrInsertion(state); + const codeToEdit = state.editModeState.codeToEdit; + const enteredEditModeFromEditor = + state.editModeState.enteredEditModeFromEditor; - if (!isInEditMode) { + if (state.session.mode !== "edit") { return; } @@ -35,7 +28,7 @@ export const exitEditMode = createAsyncThunk( dispatch(setMainEditorContentTrigger(undefined)); extra.ideMessenger.post("edit/exit", { - shouldFocusEditor: isSingleRangeEditOrInsertion, + shouldFocusEditor: enteredEditModeFromEditor, }); }, ); diff --git a/gui/src/util/getMultifileEditPrompt.ts b/gui/src/util/getMultifileEditPrompt.ts deleted file mode 100644 index 13ee8ac78..000000000 --- a/gui/src/util/getMultifileEditPrompt.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { CodeToEdit, IDE } from "core"; -import { findUriInDirs } from "core/util/uri"; - -export default function getMultifileEditPrompt( - codeToEdit: CodeToEdit[], - dirs?: string[], -): string { - const codeToEditStr = codeToEdit - .map((code) => { - const { relativePathOrBasename } = findUriInDirs( - code.filepath, - dirs ?? window.workspacePaths ?? [], - ); - return ` -\`\`\` ${relativePathOrBasename} -${code.contents} -\`\`\` - `; - }) - .join("\n"); - - 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] - - -Here are the files to base your edits on: - - -${codeToEditStr} - - -Please provide the multi-file edit details based on the engineer's request below: - `; -} From 2b46bca508dd39e90fcd93dcc530456899148f69 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 15:31:47 -0700 Subject: [PATCH 02/25] type fixes --- gui/src/components/CodeToEditCard/AddFileButton.tsx | 2 +- .../components/CodeToEditCard/AddFileCombobox.tsx | 13 ++++++------- .../components/CodeToEditCard/CodeToEditCard.tsx | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/gui/src/components/CodeToEditCard/AddFileButton.tsx b/gui/src/components/CodeToEditCard/AddFileButton.tsx index d051f847f..412e6cb8f 100644 --- a/gui/src/components/CodeToEditCard/AddFileButton.tsx +++ b/gui/src/components/CodeToEditCard/AddFileButton.tsx @@ -2,7 +2,7 @@ import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; import { useContext, useRef } from "react"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppDispatch } from "../../redux/hooks"; -import { addCodeToEdit } from "../../redux/slices/sessionSlice"; +import { addCodeToEdit } from "../../redux/slices/editModeState"; import { Listbox, ListboxButton, diff --git a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx index 1d2e62942..6fea05292 100644 --- a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx +++ b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx @@ -28,7 +28,7 @@ export default function AddFileCombobox({ const buttonRef = useRef(null); const { getSubmenuContextItems } = useSubmenuContextProviders(); const allFiles = getSubmenuContextItems("file", ""); - const codeToEdit = useAppSelector((state) => state.session.codeToEdit); + const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); const remainingFiles = allFiles.filter( (file) => !codeToEdit.find((code) => code.filepath === file.id), ); @@ -41,12 +41,11 @@ export default function AddFileCombobox({ useEffect(() => { // update selectedFiles showing only the files that are in codeToEdit - setSelectedFiles( - (prevSelectedFiles) => - prevSelectedFiles.filter( - (file) => - codeToEdit.findIndex((code) => code.filepath === file.id) !== -1, - ), + setSelectedFiles((prevSelectedFiles) => + prevSelectedFiles.filter( + (file) => + codeToEdit.findIndex((code) => code.filepath === file.id) !== -1, + ), ); }, [codeToEdit]); diff --git a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx index 6e16d4d4f..629aa000b 100644 --- a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx +++ b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx @@ -7,7 +7,7 @@ import { useAppSelector } from "../../redux/hooks"; import { addCodeToEdit, removeCodeToEdit, -} from "../../redux/slices/sessionSlice"; +} from "../../redux/slices/editModeState"; import AddFileButton from "./AddFileButton"; import AddFileCombobox from "./AddFileCombobox"; import CodeToEditListItem from "./CodeToEditListItem"; @@ -16,7 +16,7 @@ export default function CodeToEditCard() { const dispatch = useDispatch(); const ideMessenger = useContext(IdeMessengerContext); const [showAddFileCombobox, setShowAddFileCombobox] = useState(false); - const codeToEdit = useAppSelector((state) => state.session.codeToEdit); + const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); const itemCount = codeToEdit.length === 0 From 961e45193f27fe236442b4d4adccc40ef67dd600 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 18:10:59 -0700 Subject: [PATCH 03/25] edit mode apply state --- core/config/types.ts | 7 -- core/edit/constants.ts | 1 + core/index.d.ts | 11 +-- core/protocol/ideWebview.ts | 2 - extensions/vscode/src/commands.ts | 6 +- .../vscode/src/extension/VsCodeMessenger.ts | 18 ++-- .../CodeToEditCard/AddFileButton.tsx | 7 +- .../CodeToEditCard/CodeToEditCard.tsx | 13 ++- gui/src/components/Layout.tsx | 21 ++--- .../components/mainInput/ContinueInputBox.tsx | 2 +- .../TipTapEditor/utils/editorConfig.ts | 7 +- gui/src/redux/slices/editModeState.ts | 86 +++++-------------- gui/src/redux/thunks/exitEditMode.ts | 5 +- 13 files changed, 62 insertions(+), 124 deletions(-) create mode 100644 core/edit/constants.ts diff --git a/core/config/types.ts b/core/config/types.ts index ee3e308f8..bd64c78fb 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -1051,13 +1051,6 @@ declare global { 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 diff --git a/core/edit/constants.ts b/core/edit/constants.ts new file mode 100644 index 000000000..ecc3340ca --- /dev/null +++ b/core/edit/constants.ts @@ -0,0 +1 @@ +export const EDIT_MODE_STREAM_ID = "edit-mode"; diff --git a/core/index.d.ts b/core/index.d.ts index 7aa8d00ec..5f2abb9b1 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -158,9 +158,7 @@ export interface ModelInstaller { progressReporter?: (task: string, increment: number, total: number) => void, ): Promise; - isInstallingModel( - modelName: string - ): Promise; + isInstallingModel(modelName: string): Promise; } export type ContextProviderType = "normal" | "query" | "submenu"; @@ -1213,13 +1211,6 @@ export interface ExperimentalMCPOptions { faviconUrl?: string; } -export type EditStatus = - | "not-started" - | "streaming" - | "accepting" - | "accepting:full-diff" - | "done"; - export type ApplyStateStatus = | "not-started" // Apply state created but not necessarily streaming | "streaming" // Changes are being applied to the file diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index cc1191d92..24c25e7fa 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -4,7 +4,6 @@ import { ToWebviewFromIdeOrCoreProtocol } from "./webview"; import type { ApplyState, CodeToEdit, - EditStatus, MessageContent, RangeInFileWithContents, } from "../"; @@ -87,7 +86,6 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { openOnboardingCard: [undefined, void]; applyCodeFromChat: [undefined, void]; updateApplyState: [ApplyState, void]; - setEditStatus: [{ status: EditStatus; fileAfterEdit?: string }, void]; exitEditMode: [undefined, void]; focusEdit: [undefined, void]; focusEditWithoutClear: [undefined, void]; diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 1e39374c1..15e3d10d3 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -269,10 +269,6 @@ async function processDiff( // Clear vertical diffs depending on action verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept"); - void sidebar.webviewProtocol.request("setEditStatus", { - status: "done", - }); - if (streamId) { const fileContent = await ide.readFile(newOrCurrentUri); @@ -951,7 +947,7 @@ const getCommandsMap: ( if (core.configHandler.currentProfile?.profileDescription.id) { core.invoke("config/updateSelectedModel", { profileId: - core.configHandler.currentProfile?.profileDescription.id, + core.configHandler.currentProfile?.profileDescription.id, role: "autocomplete", title: selectedOption, }); diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 49de7f758..7f63f4a02 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -15,6 +15,7 @@ import { import { stripImages } from "core/util/messageContent"; import * as vscode from "vscode"; +import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; import { ApplyManager } from "../apply"; import { VerticalDiffManager } from "../diff/vertical/manager"; import EditDecorationManager from "../quickEdit/EditDecorationManager"; @@ -210,18 +211,13 @@ export class VsCodeMessenger { const fileAfterEdit = await verticalDiffManager.streamEdit({ input: stripImages(prompt), llm: model, - streamId: "edit", + streamId: EDIT_MODE_STREAM_ID, range: new vscode.Range( new vscode.Position(start.line, start.character), new vscode.Position(end.line, end.character), ), rules: config.rules, }); - - void this.webviewProtocol.request("setEditStatus", { - status: "accepting", - fileAfterEdit, - }); }); this.onWebview("edit/exit", async (msg) => { if (msg.data.shouldFocusEditor) { @@ -238,11 +234,11 @@ export class VsCodeMessenger { /** PASS THROUGH FROM WEBVIEW TO CORE AND BACK **/ WEBVIEW_TO_CORE_PASS_THROUGH.forEach((messageType) => { this.onWebview(messageType, async (msg) => { - return await this.inProcessMessenger.externalRequest( - messageType, - msg.data, - msg.messageId, - ); + return await this.inProcessMessenger.externalRequest( + messageType, + msg.data, + msg.messageId, + ); }); }); diff --git a/gui/src/components/CodeToEditCard/AddFileButton.tsx b/gui/src/components/CodeToEditCard/AddFileButton.tsx index 412e6cb8f..585060b3f 100644 --- a/gui/src/components/CodeToEditCard/AddFileButton.tsx +++ b/gui/src/components/CodeToEditCard/AddFileButton.tsx @@ -28,7 +28,12 @@ export default function AddFileButton({ onClick }: AddFileButtonProps) { }), ); - dispatch(addCodeToEdit(filesData)); + dispatch( + addCodeToEdit({ + codeToEdit: filesData, + fromEditor: false, + }), + ); } return ( diff --git a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx index 629aa000b..1d50c4368 100644 --- a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx +++ b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx @@ -6,7 +6,7 @@ import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppSelector } from "../../redux/hooks"; import { addCodeToEdit, - removeCodeToEdit, + clearCodeToEdit, } from "../../redux/slices/editModeState"; import AddFileButton from "./AddFileButton"; import AddFileCombobox from "./AddFileCombobox"; @@ -25,8 +25,8 @@ export default function CodeToEditCard() { ? "(1 item)" : `(${codeToEdit.length} items)`; - function onDelete(rif: CodeToEdit) { - dispatch(removeCodeToEdit(rif)); + function onDelete() { + dispatch(clearCodeToEdit()); } async function onClickFilename(code: CodeToEdit) { @@ -50,7 +50,12 @@ export default function CodeToEditCard() { const fileResults = await Promise.all(filePromises); for (const file of fileResults) { - dispatch(addCodeToEdit(file)); + dispatch( + addCodeToEdit({ + codeToEdit: file, + fromEditor: false, + }), + ); } } diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 7844a3e04..bf1554475 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -6,11 +6,7 @@ import { AuthProvider } from "../context/Auth"; import { LocalStorageProvider } from "../context/LocalStorage"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; -import { - addCodeToEdit, - focusEdit, - setEditStatus, -} from "../redux/slices/editModeState"; +import { addCodeToEdit, focusEdit } from "../redux/slices/editModeState"; import { newSession, setMode } from "../redux/slices/sessionSlice"; import { setShowDialog } from "../redux/slices/uiSlice"; import { exitEditMode } from "../redux/thunks"; @@ -169,15 +165,12 @@ const Layout = () => { useWebviewListener( "addCodeToEdit", async (payload) => { - dispatch(addCodeToEdit(payload)); - }, - [], - ); - - useWebviewListener( - "setEditStatus", - async ({ status, fileAfterEdit }) => { - dispatch(setEditStatus({ status, fileAfterEdit })); + dispatch( + addCodeToEdit({ + codeToEdit: payload, + fromEditor: true, + }), + ); }, [], ); diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index 7540dae8d..c6ce86a3d 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -113,7 +113,7 @@ function ContinueInputBox(props: ContinueInputBoxProps) { hideUseCodebase: true, hideSelectModel: false, enterText: - editModeState.editStatus === "accepting" ? "Retry" : "Edit", + editModeState.applyState.status === "done" ? "Retry" : "Edit", } : {}; diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index 340190683..c2d19dde0 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -338,8 +338,11 @@ export function createEditorConfig(options: { const contents = await ideMessenger.ide.readFile(filepath); dispatch( addCodeToEdit({ - filepath, - contents, + codeToEdit: { + filepath, + contents, + }, + fromEditor: false, }), ); }, diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index 391da9200..7c1dfa6e4 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -1,16 +1,17 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { CodeToEdit, EditStatus, MessageContent } from "core"; - +import { ApplyState, CodeToEdit, MessageContent } from "core"; +import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; export interface EditModeState { codeToEdit: CodeToEdit[]; - editStatus: EditStatus; + applyState: ApplyState; previousInputs: MessageContent[]; - fileAfterEdit?: string; enteredEditModeFromEditor: boolean; } const initialState: EditModeState = { - editStatus: "not-started", + applyState: { + streamId: EDIT_MODE_STREAM_ID, + }, previousInputs: [], codeToEdit: [], enteredEditModeFromEditor: false, @@ -21,63 +22,30 @@ export const editModeStateSlice = createSlice({ initialState, reducers: { focusEdit: (state) => { - state.editStatus = "not-started"; + state.applyState.status = "not-started"; state.previousInputs = []; - state.fileAfterEdit = undefined; }, submitEdit: (state, { payload }: PayloadAction) => { state.previousInputs.push(payload); - state.editStatus = "streaming"; - }, - setEditStatus: ( - state, - { - payload, - }: PayloadAction<{ status: EditStatus; fileAfterEdit?: string }>, - ) => { - // Only allow valid transitions - const currentStatus = state.editStatus; - 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) => { - state.previousInputs.push(payload); + state.applyState.status = "streaming"; }, setEditDone: (state) => { - state.editStatus = "done"; + state.applyState.status = "done"; state.previousInputs = []; }, addCodeToEdit: ( state, - { payload }: PayloadAction, + { + payload, + }: PayloadAction<{ + fromEditor: boolean; + codeToEdit: CodeToEdit | CodeToEdit[]; + }>, ) => { - const entries = Array.isArray(payload) ? payload : [payload]; + state.enteredEditModeFromEditor = payload.fromEditor; + const entries = Array.isArray(payload.codeToEdit) + ? payload.codeToEdit + : [payload.codeToEdit]; const newEntries = entries.filter( (entry) => @@ -90,31 +58,19 @@ export const editModeStateSlice = createSlice({ state.codeToEdit.push(...newEntries); } }, - removeCodeToEdit: (state, { payload }: PayloadAction) => { - state.codeToEdit = state.codeToEdit.filter( - (entry) => !isCodeToEditEqual(entry, payload), - ); - }, clearCodeToEdit: (state) => { state.codeToEdit = []; }, }, - selectors: { - selectHasCodeToEdit: (state) => { - return state.codeToEdit.length > 0; - }, - }, + selectors: {}, }); export const { - setEditStatus, - addPreviousInput, setEditDone, submitEdit, focusEdit, clearCodeToEdit, addCodeToEdit, - removeCodeToEdit, } = editModeStateSlice.actions; export default editModeStateSlice.reducer; @@ -137,7 +93,7 @@ function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) { return !("range" in a) && !("range" in b); } -export const { selectHasCodeToEdit } = editModeStateSlice.selectors; +// export const { } = editModeStateSlice.selectors; // selectIsSingleRangeEditOrInsertion: (state) => { // if (state.mode !== "edit") { diff --git a/gui/src/redux/thunks/exitEditMode.ts b/gui/src/redux/thunks/exitEditMode.ts index 9e5452e68..1e00b1b79 100644 --- a/gui/src/redux/thunks/exitEditMode.ts +++ b/gui/src/redux/thunks/exitEditMode.ts @@ -10,13 +10,12 @@ export const exitEditMode = createAsyncThunk( const codeToEdit = state.editModeState.codeToEdit; const enteredEditModeFromEditor = state.editModeState.enteredEditModeFromEditor; + // const editStreamId = state.editModeState.streamId; if (state.session.mode !== "edit") { return; } - dispatch(setMode("chat")); - for (const code of codeToEdit) { extra.ideMessenger.post("rejectDiff", { filepath: code.filepath, @@ -27,6 +26,8 @@ export const exitEditMode = createAsyncThunk( dispatch(setEditDone()); dispatch(setMainEditorContentTrigger(undefined)); + dispatch(setMode("chat")); + extra.ideMessenger.post("edit/exit", { shouldFocusEditor: enteredEditModeFromEditor, }); From 25e7b951e8d0b2a4aeec2f08714a255402ae4287 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 18:18:55 -0700 Subject: [PATCH 04/25] remove focus edit mode without clear command --- extensions/vscode/package-lock.json | 6 +-- extensions/vscode/src/commands.ts | 40 ------------------- gui/package-lock.json | 2 +- .../useMainEditorWebviewListeners.ts | 10 ----- gui/src/redux/slices/editModeState.ts | 10 +++-- gui/src/redux/thunks/exitEditMode.ts | 10 ++--- 6 files changed, 15 insertions(+), 63 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 69beb8be7..48690802a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.28", + "version": "1.1.29", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.28", + "version": "1.1.29", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", @@ -107,7 +107,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.4", + "@continuedev/fetch": "^1.0.6", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.19", "@modelcontextprotocol/sdk": "^1.5.0", diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 15e3d10d3..e1ed76cf6 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -591,46 +591,6 @@ const getCommandsMap: ( ); } }, - "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 = getRangeInFileWithContents(false); - - if (rangeInFileWithContents) { - sidebar.webviewProtocol?.request( - "addCodeToEdit", - rangeInFileWithContents, - ); - } else { - const contents = document.getText(); - - sidebar.webviewProtocol?.request("addCodeToEdit", { - filepath: document.uri.toString(), - contents, - }); - } - }, "continue.exitEditMode": async () => { captureCommandTelemetry("exitEditMode"); editDecorationManager.clear(); diff --git a/gui/package-lock.json b/gui/package-lock.json index e4a7c0b67..e6e474377 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -111,7 +111,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.4", + "@continuedev/fetch": "^1.0.6", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.19", "@modelcontextprotocol/sdk": "^1.5.0", diff --git a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts index 15fd50a18..cd06d41cb 100644 --- a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts +++ b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts @@ -166,16 +166,6 @@ export function useMainEditorWebviewListeners({ [editor], ); - useWebviewListener( - "focusEditWithoutClear", - async () => { - setTimeout(() => { - editor?.commands.focus("end"); - }, 2000); - }, - [editor], - ); - useWebviewListener( "isContinueInputFocused", async () => { diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index 7c1dfa6e4..08c613739 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -1,11 +1,12 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { ApplyState, CodeToEdit, MessageContent } from "core"; +import { ApplyState, CodeToEdit, MessageContent, MessageModes } from "core"; import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; export interface EditModeState { codeToEdit: CodeToEdit[]; applyState: ApplyState; previousInputs: MessageContent[]; - enteredEditModeFromEditor: boolean; + returnCursorToEditorAfterEdit: boolean; + returnToMode: MessageModes; } const initialState: EditModeState = { @@ -14,7 +15,8 @@ const initialState: EditModeState = { }, previousInputs: [], codeToEdit: [], - enteredEditModeFromEditor: false, + returnCursorToEditorAfterEdit: false, + returnToMode: "chat", }; export const editModeStateSlice = createSlice({ @@ -42,7 +44,7 @@ export const editModeStateSlice = createSlice({ codeToEdit: CodeToEdit | CodeToEdit[]; }>, ) => { - state.enteredEditModeFromEditor = payload.fromEditor; + state.returnCursorToEditorAfterEdit = payload.fromEditor; const entries = Array.isArray(payload.codeToEdit) ? payload.codeToEdit : [payload.codeToEdit]; diff --git a/gui/src/redux/thunks/exitEditMode.ts b/gui/src/redux/thunks/exitEditMode.ts index 1e00b1b79..07ba73db9 100644 --- a/gui/src/redux/thunks/exitEditMode.ts +++ b/gui/src/redux/thunks/exitEditMode.ts @@ -1,5 +1,5 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; -import { clearCodeToEdit, setEditDone } from "../slices/editModeState"; +import { clearCodeToEdit, clearPreviousInputs } from "../slices/editModeState"; import { setMainEditorContentTrigger, setMode } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; @@ -8,8 +8,8 @@ export const exitEditMode = createAsyncThunk( async (_, { dispatch, extra, getState }) => { const state = getState(); const codeToEdit = state.editModeState.codeToEdit; - const enteredEditModeFromEditor = - state.editModeState.enteredEditModeFromEditor; + const returnCursorToEditorAfterEdit = + state.editModeState.returnCursorToEditorAfterEdit; // const editStreamId = state.editModeState.streamId; if (state.session.mode !== "edit") { @@ -23,13 +23,13 @@ export const exitEditMode = createAsyncThunk( } dispatch(clearCodeToEdit()); - dispatch(setEditDone()); + dispatch(clearPreviousInputs()); dispatch(setMainEditorContentTrigger(undefined)); dispatch(setMode("chat")); extra.ideMessenger.post("edit/exit", { - shouldFocusEditor: enteredEditModeFromEditor, + shouldFocusEditor: returnCursorToEditorAfterEdit, }); }, ); From bd57476f1a179461e94240765e3c8f0c520cf500 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 19:58:52 -0700 Subject: [PATCH 05/25] edit mode toggle fixes --- core/protocol/ideWebview.ts | 1 - extensions/vscode/package.json | 5 - gui/src/components/Layout.tsx | 94 +++++------- .../components/StepContainer/EditActions.tsx | 4 +- gui/src/components/mainInput/InputToolbar.tsx | 10 +- .../TipTapEditor/utils/editorConfig.ts | 15 +- .../components/modelSelection/ModeSelect.tsx | 141 ++++++++++-------- gui/src/hooks/useSetup.ts | 53 ++++--- gui/src/pages/gui/Chat.tsx | 8 +- gui/src/redux/slices/editModeState.ts | 52 +++---- gui/src/redux/slices/sessionSlice.ts | 9 -- gui/src/redux/thunks/editMode.ts | 82 ++++++++++ gui/src/redux/thunks/exitEditMode.ts | 35 ----- gui/src/redux/thunks/index.ts | 2 +- 14 files changed, 265 insertions(+), 246 deletions(-) create mode 100644 gui/src/redux/thunks/editMode.ts delete mode 100644 gui/src/redux/thunks/exitEditMode.ts diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 24c25e7fa..7ee2bb9c3 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -88,5 +88,4 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { updateApplyState: [ApplyState, void]; exitEditMode: [undefined, void]; focusEdit: [undefined, void]; - focusEditWithoutClear: [undefined, void]; }; diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index f2f1fb54f..4464ec7fc 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -383,11 +383,6 @@ "mac": "cmd+i", "key": "ctrl+i" }, - { - "command": "continue.focusEditWithoutClear", - "mac": "cmd+shift+i", - "key": "ctrl+shift+i" - }, { "command": "continue.exitEditMode", "mac": "escape", diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index bf1554475..a5b3ba70e 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -6,11 +6,10 @@ import { AuthProvider } from "../context/Auth"; import { LocalStorageProvider } from "../context/LocalStorage"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; -import { addCodeToEdit, focusEdit } from "../redux/slices/editModeState"; -import { newSession, setMode } from "../redux/slices/sessionSlice"; +import { addCodeToEdit } from "../redux/slices/editModeState"; import { setShowDialog } from "../redux/slices/uiSlice"; -import { exitEditMode } from "../redux/thunks"; -import { loadLastSession, saveCurrentSession } from "../redux/thunks/session"; +import { enterEditMode, exitEditMode } from "../redux/thunks/editMode"; +import { saveCurrentSession } from "../redux/thunks/session"; import { fontSize, isMetaEquivalentKeyPressed } from "../util"; import { incrementFreeTrialCount } from "../util/freeTrial"; import { ROUTES } from "../util/navigation"; @@ -46,19 +45,24 @@ const Layout = () => { const showDialog = useAppSelector((state) => state.ui.showDialog); + const mode = useAppSelector((state) => state.session.mode); + useWebviewListener( "newSession", async () => { navigate(ROUTES.HOME); - await dispatch( - saveCurrentSession({ - openNewSession: true, - generateTitle: true, - }), - ); - dispatch(exitEditMode()); + if (mode === "edit") { + await dispatch(exitEditMode({})); + } else { + await dispatch( + saveCurrentSession({ + openNewSession: true, + generateTitle: true, + }), + ); + } }, - [], + [mode], ); useWebviewListener( @@ -74,13 +78,20 @@ const Layout = () => { "focusContinueInputWithNewSession", async () => { navigate(ROUTES.HOME); - await dispatch( - saveCurrentSession({ - openNewSession: true, - generateTitle: true, - }), - ); - dispatch(exitEditMode()); + if (mode === "edit") { + await dispatch( + exitEditMode({ + openNewSession: true, + }), + ); + } else { + await dispatch( + saveCurrentSession({ + openNewSession: true, + generateTitle: true, + }), + ); + } }, [location.pathname], location.pathname === ROUTES.HOME, @@ -133,31 +144,7 @@ const Layout = () => { useWebviewListener( "focusEdit", async () => { - await dispatch( - saveCurrentSession({ - openNewSession: false, - // Because this causes a lag before Edit mode is focused. TODO just have that happen in background - generateTitle: false, - }), - ); - dispatch(newSession()); - dispatch(focusEdit()); - dispatch(setMode("edit")); - }, - [], - ); - - useWebviewListener( - "focusEditWithoutClear", - async () => { - await dispatch( - saveCurrentSession({ - openNewSession: true, - generateTitle: true, - }), - ); - dispatch(focusEdit()); - dispatch(setMode("edit")); + dispatch(enterEditMode({})); }, [], ); @@ -171,23 +158,20 @@ const Layout = () => { fromEditor: true, }), ); + dispatch( + enterEditMode({ + returnCursorToEditor: true, + returnToMode: mode, + }), + ); }, - [], + [mode], ); - const mode = useAppSelector((store) => store.session.mode); useWebviewListener( "exitEditMode", async () => { - if (mode !== "edit") { - return; - } - dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); - dispatch(exitEditMode()); + dispatch(exitEditMode({})); }, [mode], ); diff --git a/gui/src/components/StepContainer/EditActions.tsx b/gui/src/components/StepContainer/EditActions.tsx index 08a61e2e3..4dec48d27 100644 --- a/gui/src/components/StepContainer/EditActions.tsx +++ b/gui/src/components/StepContainer/EditActions.tsx @@ -2,7 +2,7 @@ import { ChatHistoryItem } from "core"; import { renderChatMessage } from "core/util/messageContent"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { exitEditMode } from "../../redux/thunks/exitEditMode"; +import { exitEditMode } from "../../redux/thunks/editMode"; import { loadLastSession } from "../../redux/thunks/session"; import AcceptRejectAllButtons from "../AcceptRejectAllButtons"; import FeedbackButtons from "../FeedbackButtons"; @@ -64,7 +64,7 @@ export default function EditActions({ index, item }: EditActionsProps) { saveCurrentSession: false, }), ); - dispatch(exitEditMode()); + dispatch(exitEditMode({})); } }} /> diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index c2b6dac7d..d6f45d864 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -10,7 +10,6 @@ import { } from "../../redux/selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { exitEditMode } from "../../redux/thunks"; -import { loadLastSession } from "../../redux/thunks/session"; import { getAltKeyLabel, getMetaKeyLabel, @@ -186,13 +185,8 @@ function InputToolbar(props: InputToolbarProps) { {mode === "edit" && ( { - await dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); - dispatch(exitEditMode()); + onClick={async () => { + dispatch(exitEditMode({})); }} > diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index c2d19dde0..2212928d4 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -24,8 +24,6 @@ import { selectUseActiveFile } from "../../../../redux/selectors"; import { selectSelectedChatModel } from "../../../../redux/slices/configSlice"; import { addCodeToEdit } from "../../../../redux/slices/editModeState"; import { AppDispatch } from "../../../../redux/store"; -import { exitEditMode } from "../../../../redux/thunks"; -import { loadLastSession } from "../../../../redux/thunks/session"; import { getFontSize, isJetBrains } from "../../../../util"; import * as ContinueExtensions from "../extensions"; import { TipTapEditorProps } from "../TipTapEditor"; @@ -272,14 +270,11 @@ export function createEditorConfig(options: { ideMessenger.post("focusEditor", undefined); return true; } - (async () => { - await dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); - dispatch(exitEditMode()); - })(); + // dispatch( + // exitEditMode({ + // openNewSession: false, + // }), + // ); return true; }, diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index 0ab3225f9..35acc2dd9 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -8,18 +8,14 @@ import { } from "@heroicons/react/24/outline"; import { MessageModes } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; -import { useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo } from "react"; import styled from "styled-components"; import { lightGray } from ".."; -import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { cycleMode, setMode } from "../../redux/slices/sessionSlice"; +import { setMode } from "../../redux/slices/sessionSlice"; import { exitEditMode } from "../../redux/thunks"; -import { - loadLastSession, - saveCurrentSession, -} from "../../redux/thunks/session"; +import { enterEditMode } from "../../redux/thunks/editMode"; import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util"; import { Listbox, @@ -38,8 +34,6 @@ function ModeSelect() { const dispatch = useAppDispatch(); const mode = useAppSelector((store) => store.session.mode); const selectedModel = useAppSelector(selectSelectedChatModel); - const currentSession = useAppSelector((state) => state.session); - const [newSessionInitialized, setNewSessionInitialized] = useState(false); const agentModeSupported = selectedModel && modelSupportsTools(selectedModel); const jetbrains = useMemo(() => { @@ -70,11 +64,66 @@ function ModeSelect() { } }, [mode, agentModeSupported, dispatch, selectedModel]); + const cycleMode = useCallback(async () => { + const modes: MessageModes[] = jetbrains + ? ["chat", "agent"] + : ["chat", "agent", "edit"]; + const currentIndex = modes.indexOf(mode); + const oneModeAhead = modes[(currentIndex + 1) % modes.length]; + // const twoModesAhead = modes[(currentIndex + 2) % modes.length]; + if (mode === "edit") { + await dispatch( + exitEditMode({ + goToMode: oneModeAhead, + }), + ); + } else { + if (oneModeAhead === "edit") { + await dispatch( + enterEditMode({ + returnToMode: mode, // twoModesAhead + returnCursorToEditor: false, + }), + ); + } else { + dispatch(setMode(oneModeAhead)); + } + } + }, [jetbrains, mode]); + + const selectMode = useCallback( + async (newMode: MessageModes) => { + if (newMode === mode) { + return; + } + + if (newMode === "edit") { + await dispatch( + enterEditMode({ + returnToMode: mode, + returnCursorToEditor: false, + }), + ); + } else { + if (mode === "edit") { + await dispatch( + exitEditMode({ + goToMode: newMode, + }), + ); + } else { + dispatch(setMode(newMode)); + } + } + }, + [mode], + ); + useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "." && (e.metaKey || e.ctrlKey)) { e.preventDefault(); - dispatch(cycleMode({ isJetBrains: jetbrains })); + cycleMode(); } }; @@ -82,43 +131,8 @@ function ModeSelect() { return () => document.removeEventListener("keydown", handleKeyDown); }, [dispatch, mode, jetbrains]); - useWebviewListener("newSession", async () => { - setNewSessionInitialized(true); - }); - - useEffect(() => { - if (currentSession.history.length > 0) { - setNewSessionInitialized(false); - } - }, [currentSession.history]); - return ( - { - if (newMode === mode) { - return; - } - dispatch(setMode(newMode)); - if (newMode === "edit" || newSessionInitialized) { - // generate a new session for edit mode and if user opened a new session explicitly - await dispatch( - saveCurrentSession({ - generateTitle: false, - openNewSession: true, - }), - ); - } else if (mode === "edit") { - // load last session if the previous mode was edit - await dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); - dispatch(exitEditMode()); - } - }} - > +
- -
- - Agent -
- {mode === "agent" && } - {!agentModeSupported && (Not supported)} -
- - -
- - Chat - {getMetaKeyLabel()}L -
- {mode === "chat" && } -
- {!jetbrains && (
@@ -166,6 +162,23 @@ function ModeSelect() { {mode === "edit" && } )} + +
+ + Chat + {getMetaKeyLabel()}L +
+ {mode === "chat" && } +
+ + +
+ + Agent +
+ {mode === "agent" && } + {!agentModeSupported && (Not supported)} +
{metaKeyLabel}. for next mode diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 98ba3c5cf..dcfab3e29 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -2,6 +2,7 @@ import { useCallback, useContext, useEffect, useRef } from "react"; import { VSC_THEME_COLOR_VARS } from "../components"; import { IdeMessengerContext } from "../context/IdeMessenger"; +import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; import { FromCoreProtocol } from "core/protocol"; import { initializeProfilePreferences, @@ -15,6 +16,7 @@ import { selectSelectedChatModel, setConfigResult, } from "../redux/slices/configSlice"; +import { setEditStateApplyState } from "../redux/slices/editModeState"; import { updateIndexingStatus } from "../redux/slices/indexingSlice"; import { acceptToolCall, @@ -259,30 +261,35 @@ function useSetup() { useWebviewListener( "updateApplyState", async (state) => { - dispatch(updateApplyState(state)); + if (state.streamId === EDIT_MODE_STREAM_ID) { + dispatch(setEditStateApplyState(state)); + } else { + // chat or agent + dispatch(updateApplyState(state)); - // Handle apply status updates that are associated with current tool call - if ( - state.status === "closed" && - currentToolCallApplyState && - currentToolCallApplyState.streamId === state.streamId - ) { - // const output: ContextItem = { - // name: "Edit tool output", - // content: "Completed edit", - // description: "", - // }; - dispatch( - acceptToolCall({ - toolCallId: currentToolCallApplyState.toolCallId!, - }), - ); - // dispatch(setToolCallOutput([])); - dispatch( - streamResponseAfterToolCall({ - toolCallId: currentToolCallApplyState.toolCallId!, - }), - ); + // Handle apply status updates that are associated with current tool call + if ( + state.status === "closed" && + currentToolCallApplyState && + currentToolCallApplyState.streamId === state.streamId + ) { + // const output: ContextItem = { + // name: "Edit tool output", + // content: "Completed edit", + // description: "", + // }; + dispatch( + acceptToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); + // dispatch(setToolCallOutput([])); + dispatch( + streamResponseAfterToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); + } } }, [currentToolCallApplyState, history], diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 268e22e7a..3a4ccf8f7 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -34,7 +34,7 @@ import { selectCurrentToolCallApplyState, } from "../../redux/selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { submitEdit } from "../../redux/slices/editModeState"; +import { setEditStateApplyStatus } from "../../redux/slices/editModeState"; import { newSession, updateToolCallOutput, @@ -45,7 +45,7 @@ import { setShowDialog, } from "../../redux/slices/uiSlice"; import { cancelStream } from "../../redux/thunks/cancelStream"; -import { exitEditMode } from "../../redux/thunks/exitEditMode"; +import { exitEditMode } from "../../redux/thunks/editMode"; import { loadLastSession } from "../../redux/thunks/session"; import { streamResponseThunk } from "../../redux/thunks/streamResponse"; import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; @@ -261,7 +261,7 @@ export function Chat() { range: codeToEdit[0] as RangeInFileWithContents, }); - dispatch(submitEdit(prompt)); + dispatch(setEditStateApplyStatus("streaming")); } useWebviewListener( @@ -456,7 +456,7 @@ export function Chat() { saveCurrentSession: false, }), ); - dispatch(exitEditMode()); + dispatch(exitEditMode({})); } }} /> diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index 08c613739..68d22fded 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -1,10 +1,9 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { ApplyState, CodeToEdit, MessageContent, MessageModes } from "core"; +import { ApplyState, ApplyStateStatus, CodeToEdit, MessageModes } from "core"; import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; export interface EditModeState { codeToEdit: CodeToEdit[]; applyState: ApplyState; - previousInputs: MessageContent[]; returnCursorToEditorAfterEdit: boolean; returnToMode: MessageModes; } @@ -13,7 +12,6 @@ const initialState: EditModeState = { applyState: { streamId: EDIT_MODE_STREAM_ID, }, - previousInputs: [], codeToEdit: [], returnCursorToEditorAfterEdit: false, returnToMode: "chat", @@ -23,17 +21,26 @@ export const editModeStateSlice = createSlice({ name: "editModeState", initialState, reducers: { - focusEdit: (state) => { - state.applyState.status = "not-started"; - state.previousInputs = []; + setReturnCursorToEditorAfterEdit: ( + state, + { payload }: PayloadAction, + ) => { + state.returnCursorToEditorAfterEdit = payload; }, - submitEdit: (state, { payload }: PayloadAction) => { - state.previousInputs.push(payload); - state.applyState.status = "streaming"; + setReturnToModeAfterEdit: ( + state, + { payload }: PayloadAction, + ) => { + state.returnToMode = payload; }, - setEditDone: (state) => { - state.applyState.status = "done"; - state.previousInputs = []; + setEditStateApplyStatus: ( + state, + { payload }: PayloadAction, + ) => { + state.applyState.status = payload; + }, + setEditStateApplyState: (state, { payload }: PayloadAction) => { + state.applyState = payload; }, addCodeToEdit: ( state, @@ -68,11 +75,12 @@ export const editModeStateSlice = createSlice({ }); export const { - setEditDone, - submitEdit, - focusEdit, + setReturnToModeAfterEdit, + setReturnCursorToEditorAfterEdit, clearCodeToEdit, addCodeToEdit, + setEditStateApplyStatus, + setEditStateApplyState, } = editModeStateSlice.actions; export default editModeStateSlice.reducer; @@ -94,17 +102,3 @@ function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) { // If neither has a range, they are considered equal in this context return !("range" in a) && !("range" in b); } - -// export const { } = editModeStateSlice.selectors; - -// selectIsSingleRangeEditOrInsertion: (state) => { -// if (state.mode !== "edit") { -// return false; -// } - -// const isInsertion = state.codeToEdit.length === 0; -// const selectIsSingleRangeEdit = -// state.codeToEdit.length === 1 && "range" in state.codeToEdit[0]; - -// return selectIsSingleRangeEdit || isInsertion; -// }, diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 5ef58dfff..b20701ba2 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -652,14 +652,6 @@ export const sessionSlice = createSlice({ setMode: (state, action: PayloadAction) => { state.mode = action.payload; }, - cycleMode: (state, action: PayloadAction<{ isJetBrains: boolean }>) => { - const modes = action.payload.isJetBrains - ? ["chat", "agent"] - : ["chat", "edit", "agent"]; - const currentIndex = modes.indexOf(state.mode); - const nextIndex = (currentIndex + 1) % modes.length; - state.mode = modes[nextIndex] as MessageModes; - }, setNewestToolbarPreviewForInput: ( state, { @@ -757,7 +749,6 @@ export const { updateSessionMetadata, deleteSessionMetadata, setNewestToolbarPreviewForInput, - cycleMode, } = sessionSlice.actions; export const { selectIsGatheringContext } = sessionSlice.selectors; diff --git a/gui/src/redux/thunks/editMode.ts b/gui/src/redux/thunks/editMode.ts new file mode 100644 index 000000000..073eb1a18 --- /dev/null +++ b/gui/src/redux/thunks/editMode.ts @@ -0,0 +1,82 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { MessageModes } from "core"; +import { + clearCodeToEdit, + setEditStateApplyStatus, + setReturnCursorToEditorAfterEdit, + setReturnToModeAfterEdit, +} from "../slices/editModeState"; +import { newSession, setMode } from "../slices/sessionSlice"; +import { ThunkApiType } from "../store"; +import { loadLastSession, saveCurrentSession } from "./session"; + +export const exitEditMode = createAsyncThunk< + void, + { goToMode?: MessageModes; openNewSession?: boolean }, + ThunkApiType +>( + "edit/exitMode", + async ({ goToMode, openNewSession }, { dispatch, extra, getState }) => { + const state = getState(); + const codeToEdit = state.editModeState.codeToEdit; + + if (state.session.mode !== "edit") { + return; + } + + for (const code of codeToEdit) { + extra.ideMessenger.post("rejectDiff", { + filepath: code.filepath, + }); + } + + dispatch(clearCodeToEdit()); + + if (openNewSession) { + dispatch(newSession()); + } else { + await dispatch( + loadLastSession({ + saveCurrentSession: false, + }), + ); + } + + dispatch(setMode(goToMode ?? state.editModeState.returnToMode)); + + extra.ideMessenger.post("edit/exit", { + shouldFocusEditor: state.editModeState.returnCursorToEditorAfterEdit, + }); + }, +); + +export const enterEditMode = createAsyncThunk< + void, + { returnToMode?: MessageModes; returnCursorToEditor?: boolean }, + ThunkApiType +>( + "edit/enterMode", + async ( + { returnCursorToEditor, returnToMode }, + { dispatch, extra, getState }, + ) => { + const state = getState(); + + dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode)); + dispatch(setReturnCursorToEditorAfterEdit(returnCursorToEditor ?? false)); + + if (state.session.mode === "edit") { + return; + } + + await dispatch( + saveCurrentSession({ + openNewSession: true, + // Because this causes a lag before Edit mode is focused. TODO just have that happen in background + generateTitle: false, + }), + ); + dispatch(setEditStateApplyStatus("not-started")); + dispatch(setMode("edit")); + }, +); diff --git a/gui/src/redux/thunks/exitEditMode.ts b/gui/src/redux/thunks/exitEditMode.ts deleted file mode 100644 index 07ba73db9..000000000 --- a/gui/src/redux/thunks/exitEditMode.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { createAsyncThunk } from "@reduxjs/toolkit"; -import { clearCodeToEdit, clearPreviousInputs } from "../slices/editModeState"; -import { setMainEditorContentTrigger, setMode } from "../slices/sessionSlice"; -import { ThunkApiType } from "../store"; - -export const exitEditMode = createAsyncThunk( - "edit/complete", - async (_, { dispatch, extra, getState }) => { - const state = getState(); - const codeToEdit = state.editModeState.codeToEdit; - const returnCursorToEditorAfterEdit = - state.editModeState.returnCursorToEditorAfterEdit; - // const editStreamId = state.editModeState.streamId; - - if (state.session.mode !== "edit") { - return; - } - - for (const code of codeToEdit) { - extra.ideMessenger.post("rejectDiff", { - filepath: code.filepath, - }); - } - - dispatch(clearCodeToEdit()); - dispatch(clearPreviousInputs()); - dispatch(setMainEditorContentTrigger(undefined)); - - dispatch(setMode("chat")); - - extra.ideMessenger.post("edit/exit", { - shouldFocusEditor: returnCursorToEditorAfterEdit, - }); - }, -); diff --git a/gui/src/redux/thunks/index.ts b/gui/src/redux/thunks/index.ts index ad987fafa..9c619d785 100644 --- a/gui/src/redux/thunks/index.ts +++ b/gui/src/redux/thunks/index.ts @@ -1,4 +1,4 @@ -export { exitEditMode } from "./exitEditMode"; +export { exitEditMode } from "./editMode"; export { gatherContext } from "./gatherContext"; export { resetStateForNewMessage } from "./resetStateForNewMessage"; export { streamNormalInput } from "./streamNormalInput"; From 654842a96e525fd14e02c15114d393c91e1fb221 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 20:30:13 -0700 Subject: [PATCH 06/25] working edit apply state --- core/protocol/ideWebview.ts | 2 +- extensions/vscode/src/commands.ts | 2 +- .../CodeToEditCard/AddFileButton.tsx | 71 ------- .../CodeToEditCard/AddFileCombobox.tsx | 142 ------------- .../CodeToEditCard/CodeToEditCard.tsx | 72 +------ gui/src/components/Layout.tsx | 6 +- .../components/StepContainer/EditActions.tsx | 48 +---- .../TipTapEditor/extensions/AddCodeToEdit.ts | 189 ------------------ .../TipTapEditor/extensions/index.ts | 1 - .../TipTapEditor/utils/editorConfig.ts | 51 +---- gui/src/redux/slices/editModeState.ts | 4 +- 11 files changed, 25 insertions(+), 563 deletions(-) delete mode 100644 gui/src/components/CodeToEditCard/AddFileButton.tsx delete mode 100644 gui/src/components/CodeToEditCard/AddFileCombobox.tsx delete mode 100644 gui/src/components/mainInput/TipTapEditor/extensions/AddCodeToEdit.ts diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 7ee2bb9c3..1549c0b26 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -70,7 +70,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { }, void, ]; - addCodeToEdit: [CodeToEdit, void]; + setCodeToEdit: [CodeToEdit, void]; navigateTo: [{ path: string; toggle?: boolean }, void]; addModel: [undefined, void]; diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index e1ed76cf6..7465eb2e2 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -580,7 +580,7 @@ const getCommandsMap: ( if (rangeInFileWithContents) { sidebar.webviewProtocol?.request( - "addCodeToEdit", + "setCodeToEdit", rangeInFileWithContents, ); diff --git a/gui/src/components/CodeToEditCard/AddFileButton.tsx b/gui/src/components/CodeToEditCard/AddFileButton.tsx deleted file mode 100644 index 585060b3f..000000000 --- a/gui/src/components/CodeToEditCard/AddFileButton.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; -import { useContext, useRef } from "react"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useAppDispatch } from "../../redux/hooks"; -import { addCodeToEdit } from "../../redux/slices/editModeState"; -import { - Listbox, - ListboxButton, - ListboxOption, - ListboxOptions, -} from "../ui/Listbox"; - -export interface AddFileButtonProps { - onClick: () => void; -} - -export default function AddFileButton({ onClick }: AddFileButtonProps) { - const buttonRef = useRef(null); - const ideMessenger = useContext(IdeMessengerContext); - const dispatch = useAppDispatch(); - - async function handleAddAllOpenFiles() { - const openFiles = await ideMessenger.ide.getOpenFiles(); - const filesData = await Promise.all( - openFiles.map(async (filepath) => { - const contents = await ideMessenger.ide.readFile(filepath); - return { filepath, contents }; - }), - ); - - dispatch( - addCodeToEdit({ - codeToEdit: filesData, - fromEditor: false, - }), - ); - } - - return ( - -
- -
{ - e.preventDefault(); - e.stopPropagation(); - onClick(); - }} - > - - - Add file - -
- -
- - - - - - Add all open files - -
- - ); -} diff --git a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx deleted file mode 100644 index 6fea05292..000000000 --- a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx +++ /dev/null @@ -1,142 +0,0 @@ -import { ContextSubmenuItemWithProvider } from "core"; -import { useEffect, useRef, useState } from "react"; -import { - Combobox, - ComboboxButton, - ComboboxInput, - ComboboxOption, - ComboboxOptions, -} from "../../components/ui/Combobox"; -import { useSubmenuContextProviders } from "../../context/SubmenuContextProviders"; -import { useAppSelector } from "../../redux/hooks"; -import FileIcon from "../FileIcon"; -export interface AddFileComboboxProps { - onSelect: (filepaths: string[]) => void | Promise; - onEscape: () => void | Promise; -} - -export default function AddFileCombobox({ - onSelect, - onEscape, -}: AddFileComboboxProps) { - const [query, setQuery] = useState(""); - const [selectedFiles, setSelectedFiles] = useState< - ContextSubmenuItemWithProvider[] - >([]); - - const inputRef = useRef(null); - const buttonRef = useRef(null); - const { getSubmenuContextItems } = useSubmenuContextProviders(); - const allFiles = getSubmenuContextItems("file", ""); - const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); - const remainingFiles = allFiles.filter( - (file) => !codeToEdit.find((code) => code.filepath === file.id), - ); - - useEffect(() => { - if (inputRef.current) { - inputRef.current.focus(); - } - }, []); - - useEffect(() => { - // update selectedFiles showing only the files that are in codeToEdit - setSelectedFiles((prevSelectedFiles) => - prevSelectedFiles.filter( - (file) => - codeToEdit.findIndex((code) => code.filepath === file.id) !== -1, - ), - ); - }, [codeToEdit]); - - const filteredFiles = - query === "" - ? remainingFiles - : remainingFiles.filter((file) => - file.title.toLowerCase().includes(query.toLowerCase()), - ); - - return ( -
- { - setSelectedFiles(files); - void onSelect(files.map((file) => file.id)); - buttonRef.current?.click(); - setQuery(""); - }} - > - {({ open }) => ( -
- - { - if (!open) { - buttonRef.current?.click(); - } - }} - onFocus={() => { - buttonRef.current?.click(); - }} - className="bg-vsc-background border-lightgray text-vsc-foreground box-border w-full rounded border border-solid py-0.5 pl-2 text-xs focus:outline-none" - onChange={(event) => setQuery(event.target.value)} - placeholder="Type to search files..." - onKeyDown={(e) => { - if (e.key === "Escape" && !open) { - void onEscape(); - } - }} - /> - - - {filteredFiles.length > 0 ? ( - filteredFiles.map((file) => ( - - `relative flex w-full cursor-pointer px-2 py-1 text-left text-xs ${ - active - ? "bg-list-active text-list-active-foreground" - : "" - }` - } - > - {({ active, selected }) => ( -
-
- - {file.title} -
- - - {file.description} - -
- )} -
- )) - ) : ( -
- No results -
- )} -
-
- )} -
-
- ); -} diff --git a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx index 1d50c4368..1bd310f20 100644 --- a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx +++ b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx @@ -1,30 +1,16 @@ -import { PlusIcon, XMarkIcon } from "@heroicons/react/24/outline"; import type { CodeToEdit } from "core"; -import { useContext, useState } from "react"; +import { useContext } from "react"; import { useDispatch } from "react-redux"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppSelector } from "../../redux/hooks"; -import { - addCodeToEdit, - clearCodeToEdit, -} from "../../redux/slices/editModeState"; -import AddFileButton from "./AddFileButton"; -import AddFileCombobox from "./AddFileCombobox"; +import { clearCodeToEdit } from "../../redux/slices/editModeState"; import CodeToEditListItem from "./CodeToEditListItem"; export default function CodeToEditCard() { const dispatch = useDispatch(); const ideMessenger = useContext(IdeMessengerContext); - const [showAddFileCombobox, setShowAddFileCombobox] = useState(false); const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); - const itemCount = - codeToEdit.length === 0 - ? "" - : codeToEdit.length === 1 - ? "(1 item)" - : `(${codeToEdit.length} items)`; - function onDelete() { dispatch(clearCodeToEdit()); } @@ -41,35 +27,8 @@ export default function CodeToEditCard() { } } - async function onSelectFilesToAdd(uris: string[]) { - const filePromises = uris.map(async (uri) => { - const contents = await ideMessenger.ide.readFile(uri); - return { contents, filepath: uri }; - }); - - const fileResults = await Promise.all(filePromises); - - for (const file of fileResults) { - dispatch( - addCodeToEdit({ - codeToEdit: file, - fromEditor: false, - }), - ); - } - } - return (
-
-
- Code to edit - {itemCount} -
- - setShowAddFileCombobox(true)} /> -
- {codeToEdit.length > 0 ? (
    {codeToEdit.map((code, i) => ( @@ -82,32 +41,7 @@ export default function CodeToEditCard() { ))}
) : ( - !showAddFileCombobox && ( -
setShowAddFileCombobox(true)} - > - - Add a file to get started -
- ) - )} - - {showAddFileCombobox && ( -
-
- setShowAddFileCombobox(false)} - /> -
- { - setShowAddFileCombobox(false); - }} - className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground mb-2 h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20" - /> -
+
Highlight code and select Cmd + I to edit a file
)}
); diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index a5b3ba70e..0b07a7405 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -6,7 +6,7 @@ import { AuthProvider } from "../context/Auth"; import { LocalStorageProvider } from "../context/LocalStorage"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; -import { addCodeToEdit } from "../redux/slices/editModeState"; +import { setCodeToEdit } from "../redux/slices/editModeState"; import { setShowDialog } from "../redux/slices/uiSlice"; import { enterEditMode, exitEditMode } from "../redux/thunks/editMode"; import { saveCurrentSession } from "../redux/thunks/session"; @@ -150,10 +150,10 @@ const Layout = () => { ); useWebviewListener( - "addCodeToEdit", + "setCodeToEdit", async (payload) => { dispatch( - addCodeToEdit({ + setCodeToEdit({ codeToEdit: payload, fromEditor: true, }), diff --git a/gui/src/components/StepContainer/EditActions.tsx b/gui/src/components/StepContainer/EditActions.tsx index 4dec48d27..901b7ea00 100644 --- a/gui/src/components/StepContainer/EditActions.tsx +++ b/gui/src/components/StepContainer/EditActions.tsx @@ -3,7 +3,6 @@ import { ChatHistoryItem } from "core"; import { renderChatMessage } from "core/util/messageContent"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { exitEditMode } from "../../redux/thunks/editMode"; -import { loadLastSession } from "../../redux/thunks/session"; import AcceptRejectAllButtons from "../AcceptRejectAllButtons"; import FeedbackButtons from "../FeedbackButtons"; import { CopyIconButton } from "../gui/CopyIconButton"; @@ -14,62 +13,33 @@ export interface EditActionsProps { } export default function EditActions({ index, item }: EditActionsProps) { - // const curCheckpointIndex = useSelector( - // (store: RootState) => store.state.curCheckpointIndex, - // ); const dispatch = useAppDispatch(); - const isStreaming = useAppSelector((state) => state.session.isStreaming); - - const applyStates = useAppSelector( - (state) => state.session.codeBlockApplyStates.states, - ); - - const pendingApplyStates = applyStates.filter( - (state) => state.status === "done", - ); - - const hasClosedAllStreams = applyStates.every( - (state) => state.status === "closed", - ); - - // const isCurCheckpoint = Math.floor(index / 2) === curCheckpointIndex; - const hasPendingApplies = pendingApplyStates.length > 0; - - if (isStreaming) return null; + const applyState = useAppSelector((store) => store.editModeState.applyState); + if ( + applyState.status === "not-started" || + applyState.status === "streaming" + ) { + return null; + } return (
- {/* {isCurCheckpoint && ( -
- {hasPendingApplies && ( - - )} - {hasClosedAllStreams && } -
- )} */} -
- {hasPendingApplies && ( + {applyState.status === "done" && ( { if (outcome === "acceptDiff") { - await dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); dispatch(exitEditMode({})); } }} /> )} - {/* {hasClosedAllStreams && } */}
diff --git a/gui/src/components/mainInput/TipTapEditor/extensions/AddCodeToEdit.ts b/gui/src/components/mainInput/TipTapEditor/extensions/AddCodeToEdit.ts deleted file mode 100644 index 87b524435..000000000 --- a/gui/src/components/mainInput/TipTapEditor/extensions/AddCodeToEdit.ts +++ /dev/null @@ -1,189 +0,0 @@ -import { mergeAttributes, Node } from "@tiptap/core"; -import { PluginKey } from "@tiptap/pm/state"; -import Suggestion from "@tiptap/suggestion"; -import { MentionOptions } from "./types"; - -export const AddCodeToEdit = Node.create({ - name: "add-code-to-edit", - - addOptions() { - return { - HTMLAttributes: { - class: "add-code-to-edit", - }, - renderHTML({ options, node }) { - return [ - "span", - this.HTMLAttributes, - `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`, - ]; - }, - suggestion: { - char: "#", - pluginKey: new PluginKey(this.name), - allow: ({ state, range }) => { - const $from = state.doc.resolve(range.from); - const type = state.schema.nodes[this.name]; - const allow = !!$from.parent.type.contentMatch.matchType(type); - - // Check if there's a space after the "#" - const textFrom = range.from; - const textTo = state.selection.$to.pos; - const text = state.doc.textBetween(textFrom, textTo); - const hasSpace = text.includes(" "); - - return allow && !hasSpace; - }, - }, - }; - }, - - group: "inline", - - inline: true, - - selectable: false, - - atom: true, - - addAttributes() { - return { - id: { - default: null, - parseHTML: (element) => element.getAttribute("data-id"), - renderHTML: (attributes) => { - if (!attributes.id) { - return {}; - } - - return { - "data-id": attributes.id, - }; - }, - }, - - label: { - default: null, - parseHTML: (element) => element.getAttribute("data-label"), - renderHTML: (attributes) => { - if (!attributes.label) { - return {}; - } - - return { - "data-label": attributes.label, - }; - }, - }, - - renderInlineAs: { - default: null, - parseHTML: (element) => element.getAttribute("data-renderInlineAs"), - renderHTML: (attributes) => { - if (typeof attributes.renderInlineAs !== "string") { - return {}; - } - - return { - "data-renderInlineAs": attributes.renderInlineAs, - }; - }, - }, - - query: { - default: null, - parseHTML: (element) => element.getAttribute("data-query"), - renderHTML: (attributes) => { - if (!attributes.query) { - return {}; - } - - return { - "data-query": attributes.query, - }; - }, - }, - - itemType: { - default: null, - parseHTML: (element) => element.getAttribute("data-itemType"), - renderHTML: (attributes) => { - if (!attributes.itemType) { - return {}; - } - - return { - "data-itemType": attributes.itemType, - }; - }, - }, - }; - }, - - parseHTML() { - return [ - { - tag: `span[data-type="${this.name}"]`, - }, - ]; - }, - - renderHTML({ node, HTMLAttributes }) { - const html = this.options.renderHTML({ - options: this.options, - node, - }); - - if (typeof html === "string") { - return [ - "span", - mergeAttributes( - { "data-type": this.name }, - this.options.HTMLAttributes, - HTMLAttributes, - ), - html, - ]; - } - return html; - }, - - addKeyboardShortcuts() { - return { - Backspace: () => - this.editor.commands.command(({ tr, state }) => { - let isMention = false; - const { selection } = state; - const { empty, anchor } = selection; - - if (!empty) { - return false; - } - - state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => { - if (node.type.name === this.name) { - isMention = true; - tr.insertText( - this.options.suggestion.char || "", - pos, - pos + node.nodeSize, - ); - - return false; - } - }); - - return isMention; - }), - }; - }, - - addProseMirrorPlugins() { - return [ - Suggestion({ - editor: this.editor, - ...this.options.suggestion, - }), - ]; - }, -}); diff --git a/gui/src/components/mainInput/TipTapEditor/extensions/index.ts b/gui/src/components/mainInput/TipTapEditor/extensions/index.ts index 06426b9c3..717557fdc 100644 --- a/gui/src/components/mainInput/TipTapEditor/extensions/index.ts +++ b/gui/src/components/mainInput/TipTapEditor/extensions/index.ts @@ -1,4 +1,3 @@ -export * from "./AddCodeToEdit"; export * from "./CodeBlock"; export * from "./Mention"; export * from "./Prompt"; diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index 2212928d4..421130a29 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -22,8 +22,8 @@ import useUpdatingRef from "../../../../hooks/useUpdatingRef"; import { useAppSelector } from "../../../../redux/hooks"; import { selectUseActiveFile } from "../../../../redux/selectors"; import { selectSelectedChatModel } from "../../../../redux/slices/configSlice"; -import { addCodeToEdit } from "../../../../redux/slices/editModeState"; import { AppDispatch } from "../../../../redux/store"; +import { exitEditMode } from "../../../../redux/thunks"; import { getFontSize, isJetBrains } from "../../../../util"; import * as ContinueExtensions from "../extensions"; import { TipTapEditorProps } from "../TipTapEditor"; @@ -270,11 +270,11 @@ export function createEditorConfig(options: { ideMessenger.post("focusEditor", undefined); return true; } - // dispatch( - // exitEditMode({ - // openNewSession: false, - // }), - // ); + dispatch( + exitEditMode({ + openNewSession: false, + }), + ); return true; }, @@ -315,45 +315,6 @@ export function createEditorConfig(options: { ideMessenger, ), }), - ContinueExtensions.AddCodeToEdit.configure({ - suggestion: { - ...getContextProviderDropdownOptions( - availableContextProvidersRef, - getSubmenuContextItemsRef, - enterSubmenu, - onClose, - onOpen, - inSubmenuRef, - ideMessenger, - ), - allow: () => modeRef.current !== "edit", - command: async ({ editor, range, props }) => { - editor.chain().focus().insertContentAt(range, "").run(); - const filepath = props.id; - const contents = await ideMessenger.ide.readFile(filepath); - dispatch( - addCodeToEdit({ - codeToEdit: { - filepath, - contents, - }, - fromEditor: false, - }), - ); - }, - items: async ({ query }) => { - // Only display files in the dropdown - const results = getSubmenuContextItemsRef.current("file", query); - return results.map((result) => ({ - ...result, - label: result.title, - type: "file", - query: result.id, - icon: result.icon, - })); - }, - }, - }), ContinueExtensions.SlashCommand.configure({ suggestion: getSlashCommandDropdownOptions( availableSlashCommandsRef, diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index 68d22fded..01fd290cb 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -42,7 +42,7 @@ export const editModeStateSlice = createSlice({ setEditStateApplyState: (state, { payload }: PayloadAction) => { state.applyState = payload; }, - addCodeToEdit: ( + setCodeToEdit: ( state, { payload, @@ -78,7 +78,7 @@ export const { setReturnToModeAfterEdit, setReturnCursorToEditorAfterEdit, clearCodeToEdit, - addCodeToEdit, + setCodeToEdit, setEditStateApplyStatus, setEditStateApplyState, } = editModeStateSlice.actions; From 3d6cf7504bdb97d3a590660f1f72fef1a3c29193 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 21:28:17 -0700 Subject: [PATCH 07/25] WIP: code to edit progress --- extensions/vscode/src/commands.ts | 1 + .../CodeToEditCard/CodeToEditCard.tsx | 48 ----- .../CodeToEditCard/CodeToEditListItem.tsx | 142 ------------- gui/src/components/CodeToEditCard/index.ts | 1 - .../components/mainInput/CodeToEditCard.tsx | 201 ++++++++++++++++++ gui/src/components/mainInput/InputToolbar.tsx | 4 +- .../components/modelSelection/ModeSelect.tsx | 2 +- gui/src/pages/gui/Chat.tsx | 2 +- gui/src/redux/slices/editModeState.ts | 34 +-- 9 files changed, 209 insertions(+), 226 deletions(-) delete mode 100644 gui/src/components/CodeToEditCard/CodeToEditCard.tsx delete mode 100644 gui/src/components/CodeToEditCard/CodeToEditListItem.tsx delete mode 100644 gui/src/components/CodeToEditCard/index.ts create mode 100644 gui/src/components/mainInput/CodeToEditCard.tsx diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 7465eb2e2..af9c8a232 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -574,6 +574,7 @@ const getCommandsMap: ( const range = args?.range ?? new vscode.Range(startFromCharZero, endAtCharLast); + editDecorationManager.clear(); editDecorationManager.addDecorations(editor, [range]); const rangeInFileWithContents = getRangeInFileWithContents(true, range); diff --git a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx deleted file mode 100644 index 1bd310f20..000000000 --- a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import type { CodeToEdit } from "core"; -import { useContext } from "react"; -import { useDispatch } from "react-redux"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useAppSelector } from "../../redux/hooks"; -import { clearCodeToEdit } from "../../redux/slices/editModeState"; -import CodeToEditListItem from "./CodeToEditListItem"; - -export default function CodeToEditCard() { - const dispatch = useDispatch(); - const ideMessenger = useContext(IdeMessengerContext); - const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); - - function onDelete() { - dispatch(clearCodeToEdit()); - } - - async function onClickFilename(code: CodeToEdit) { - if ("range" in code) { - await ideMessenger.ide.showLines( - code.filepath, - code.range.start.line, - code.range.end.line, - ); - } else { - await ideMessenger.ide.openFile(code.filepath); - } - } - - return ( -
- {codeToEdit.length > 0 ? ( -
    - {codeToEdit.map((code, i) => ( - - ))} -
- ) : ( -
Highlight code and select Cmd + I to edit a file
- )} -
- ); -} diff --git a/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx b/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx deleted file mode 100644 index 9651ec235..000000000 --- a/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx +++ /dev/null @@ -1,142 +0,0 @@ -import { - ChevronDownIcon, - ChevronRightIcon, - XMarkIcon, -} from "@heroicons/react/24/outline"; -import { CodeToEdit } from "core"; -import { getMarkdownLanguageTagForFile } from "core/util"; -import { - getLastNUriRelativePathParts, - getUriPathBasename, -} from "core/util/uri"; -import { useState } from "react"; -import styled from "styled-components"; -import FileIcon from "../FileIcon"; -import StyledMarkdownPreview from "../StyledMarkdownPreview"; - -export interface CodeToEditListItemProps { - code: CodeToEdit; - onDelete: (codeToEdit: CodeToEdit) => void | Promise; - onClickFilename: (codeToEdit: CodeToEdit) => void | Promise; -} - -const NoPaddingWrapper = styled.div` - > * { - margin: 0 !important; - padding: 0 !important; - } - - pre { - margin: 0 !important; - padding: 0px 0px 0px 10px !important; - } -`; - -export default function CodeToEditListItem({ - code, - onDelete, - onClickFilename, -}: CodeToEditListItemProps) { - const [showCodeSnippet, setShowCodeSnippet] = useState(false); - - const fileName = getUriPathBasename(code.filepath); - const last2Parts = getLastNUriRelativePathParts( - window.workspacePaths ?? [], - code.filepath, - 2, - ); - - let isInsertion = false; - let title = fileName; - - if ("range" in code) { - const start = code.range.start.line + 1; - const end = code.range.end.line + 1; - - isInsertion = start === end; - - title += isInsertion - ? ` - Inserting at line ${start}` - : ` (${start} - ${end})`; - } - - const source = - "```" + - getMarkdownLanguageTagForFile(code.filepath) + - "\n" + - code.contents + - "\n" + - "```"; - - return ( -
  • { - if (!isInsertion) { - setShowCodeSnippet((showCodeSnippet) => !showCodeSnippet); - } - }} - > -
    -
    - -
    - { - e.stopPropagation(); - void onClickFilename(code); - }} - > - {title} - - - {last2Parts} - -
    -
    - -
    -
    - {showCodeSnippet ? ( - { - e.stopPropagation(); - setShowCodeSnippet(false); - }} - className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20" - /> - ) : ( - { - e.stopPropagation(); - setShowCodeSnippet(true); - }} - className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20" - /> - )} -
    -
    - { - e.stopPropagation(); - void onDelete(code); - }} - className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20" - /> -
    -
    -
    - - {showCodeSnippet && ( -
    - - - -
    - )} -
  • - ); -} diff --git a/gui/src/components/CodeToEditCard/index.ts b/gui/src/components/CodeToEditCard/index.ts deleted file mode 100644 index 2e7d342eb..000000000 --- a/gui/src/components/CodeToEditCard/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./CodeToEditCard"; diff --git a/gui/src/components/mainInput/CodeToEditCard.tsx b/gui/src/components/mainInput/CodeToEditCard.tsx new file mode 100644 index 000000000..5c00bcd8b --- /dev/null +++ b/gui/src/components/mainInput/CodeToEditCard.tsx @@ -0,0 +1,201 @@ +import { + ChevronDownIcon, + ChevronRightIcon, + CodeBracketIcon, + XMarkIcon, +} from "@heroicons/react/24/outline"; +import { CodeToEdit } from "core"; +import { getMarkdownLanguageTagForFile } from "core/util"; +import { getUriPathBasename } from "core/util/uri"; +import { useContext, useMemo, useState } from "react"; +import { useDispatch } from "react-redux"; +import styled from "styled-components"; +import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { useAppSelector } from "../../redux/hooks"; +import { clearCodeToEdit } from "../../redux/slices/editModeState"; +import { getMetaKeyLabel } from "../../util"; +import FileIcon from "../FileIcon"; +import Shortcut from "../gui/Shortcut"; +import StyledMarkdownPreview from "../StyledMarkdownPreview"; +import { useFontSize } from "../ui/font"; + +const NoPaddingWrapper = styled.div` + > * { + margin: 0 !important; + padding: 0 !important; + } + + pre { + margin: 0 !important; + padding: 0px 0px 0px 10px !important; + } +`; + +interface CodeToEditItemProps { + code: CodeToEdit; +} + +function CodeToEditItem({ code }: CodeToEditItemProps) { + const dispatch = useDispatch(); + + function onDelete() { + dispatch(clearCodeToEdit()); + } + + const ideMessenger = useContext(IdeMessengerContext); + const [showCodeSnippet, setShowCodeSnippet] = useState(false); + + const fileName = getUriPathBasename(code.filepath); + + let isInsertion = false; + let title = fileName; + + if ("range" in code) { + const start = code.range.start.line + 1; + const end = code.range.end.line + 1; + + isInsertion = start === end; + + title += isInsertion + ? ` - Inserting at line ${start}` + : ` (${start} - ${end})`; + } + + const source = + "```" + + getMarkdownLanguageTagForFile(code.filepath) + + "\n" + + code.contents + + "\n" + + "```"; + + async function onClickFilename() { + if ("range" in code) { + await ideMessenger.ide.showLines( + code.filepath, + code.range.start.line, + code.range.end.line, + ); + } else { + await ideMessenger.ide.openFile(code.filepath); + } + } + + const smallFont = useFontSize(-3); + + const iconClass = + "text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20"; + + return ( +
    +
    + + Code to edit + + +
    { + if (!isInsertion) { + setShowCodeSnippet((showCodeSnippet) => !showCodeSnippet); + } + }} + > +
    + + { + e.stopPropagation(); + void onClickFilename(); + }} + > + {title} + +
    + +
    +
    + {showCodeSnippet ? ( + { + e.stopPropagation(); + setShowCodeSnippet(false); + }} + className={iconClass} + /> + ) : ( + { + e.stopPropagation(); + setShowCodeSnippet(true); + }} + className="" + /> + )} +
    +
    + { + e.stopPropagation(); + void onDelete(); + }} + className={iconClass} + /> +
    +
    +
    +
    + {showCodeSnippet && ( +
    + + + +
    + )} +
    + ); +} +export default function CodeToEditCard() { + // Array from previous multi-file edit + const codeToEditArray = useAppSelector( + (state) => state.editModeState.codeToEdit, + ); + const codeToEdit = useMemo(() => { + return codeToEditArray[0]; + }, [codeToEditArray]); + + const metaKeyLabel = useMemo(() => { + return getMetaKeyLabel(); + }, []); + + const tinyFont = useFontSize(-3); + + return ( +
    + {codeToEdit ? ( + + ) : ( + // + // Highlight code and select Cmd + I to edit a file + // + <> + + {`To edit code, highlight it and press`} + + meta I + + )} +
    + ); +} diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index d6f45d864..a937e0f59 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -85,13 +85,13 @@ function InputToolbar(props: InputToolbarProps) { }} >
    - + Select Mode - + Select Model diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index 35acc2dd9..069f0dd96 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -136,7 +136,7 @@ function ModeSelect() {
    , ) => { state.returnCursorToEditorAfterEdit = payload.fromEditor; - const entries = Array.isArray(payload.codeToEdit) + state.codeToEdit = Array.isArray(payload.codeToEdit) ? payload.codeToEdit : [payload.codeToEdit]; - - const newEntries = entries.filter( - (entry) => - !state.codeToEdit.some((existingEntry) => - isCodeToEditEqual(existingEntry, entry), - ), - ); - - if (newEntries.length > 0) { - state.codeToEdit.push(...newEntries); - } }, clearCodeToEdit: (state) => { state.codeToEdit = []; @@ -83,22 +74,3 @@ export const { setEditStateApplyState, } = editModeStateSlice.actions; export default editModeStateSlice.reducer; - -function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) { - if (a.filepath !== b.filepath || a.contents !== b.contents) { - return false; - } - - if ("range" in a && "range" in b) { - const rangeA = a.range; - const rangeB = b.range; - - return ( - rangeA.start.line === rangeB.start.line && - rangeA.end.line === rangeB.end.line - ); - } - - // If neither has a range, they are considered equal in this context - return !("range" in a) && !("range" in b); -} From b0117f732b23c9f5291e28107789b215dd747232 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 22:22:32 -0700 Subject: [PATCH 08/25] notch toolbar fixes --- core/protocol/ideWebview.ts | 4 +- .../vscode/src/extension/VsCodeMessenger.ts | 3 +- .../components/mainInput/CodeToEditCard.tsx | 57 +++------ .../components/mainInput/ContinueInputBox.tsx | 3 +- .../Lump/BlockSettingsTopToolbar.tsx | 17 +-- gui/src/pages/error.tsx | 22 ++-- gui/src/pages/gui/Chat.tsx | 114 +++++++----------- gui/src/redux/thunks/editMode.ts | 53 +++++++- 8 files changed, 141 insertions(+), 132 deletions(-) diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 1549c0b26..2c6b6a0ee 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -49,9 +49,9 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { prompt: MessageContent; range: RangeInFileWithContents; }, - void, + string | undefined, ]; - "edit/exit": [{ shouldFocusEditor: boolean }, void]; + "edit/clearDecorations": [{ shouldFocusEditor: boolean }, void]; }; export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 7f63f4a02..7fde6fcb6 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -218,8 +218,9 @@ export class VsCodeMessenger { ), rules: config.rules, }); + return fileAfterEdit; }); - this.onWebview("edit/exit", async (msg) => { + this.onWebview("edit/clearDecorations", async (msg) => { if (msg.data.shouldFocusEditor) { const activeEditor = vscode.window.activeTextEditor; diff --git a/gui/src/components/mainInput/CodeToEditCard.tsx b/gui/src/components/mainInput/CodeToEditCard.tsx index 5c00bcd8b..0926fe53e 100644 --- a/gui/src/components/mainInput/CodeToEditCard.tsx +++ b/gui/src/components/mainInput/CodeToEditCard.tsx @@ -1,9 +1,4 @@ -import { - ChevronDownIcon, - ChevronRightIcon, - CodeBracketIcon, - XMarkIcon, -} from "@heroicons/react/24/outline"; +import { ChevronRightIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { CodeToEdit } from "core"; import { getMarkdownLanguageTagForFile } from "core/util"; import { getUriPathBasename } from "core/util/uri"; @@ -15,7 +10,6 @@ import { useAppSelector } from "../../redux/hooks"; import { clearCodeToEdit } from "../../redux/slices/editModeState"; import { getMetaKeyLabel } from "../../util"; import FileIcon from "../FileIcon"; -import Shortcut from "../gui/Shortcut"; import StyledMarkdownPreview from "../StyledMarkdownPreview"; import { useFontSize } from "../ui/font"; @@ -37,14 +31,16 @@ interface CodeToEditItemProps { function CodeToEditItem({ code }: CodeToEditItemProps) { const dispatch = useDispatch(); + const ideMessenger = useContext(IdeMessengerContext); + const [showCodeSnippet, setShowCodeSnippet] = useState(false); function onDelete() { dispatch(clearCodeToEdit()); + ideMessenger.post("edit/clearDecorations", { + shouldFocusEditor: false, + }); } - const ideMessenger = useContext(IdeMessengerContext); - const [showCodeSnippet, setShowCodeSnippet] = useState(false); - const fileName = getUriPathBasename(code.filepath); let isInsertion = false; @@ -87,17 +83,17 @@ function CodeToEditItem({ code }: CodeToEditItemProps) { "text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20"; return ( -
    -
    +
    +
    Code to edit - + {/* */}
    { @@ -120,25 +116,13 @@ function CodeToEditItem({ code }: CodeToEditItemProps) {
    -
    - {showCodeSnippet ? ( - { - e.stopPropagation(); - setShowCodeSnippet(false); - }} - className={iconClass} - /> - ) : ( - { - e.stopPropagation(); - setShowCodeSnippet(true); - }} - className="" - /> - )} -
    + { + e.stopPropagation(); + setShowCodeSnippet((val) => !val); + }} + className={`text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20 ${showCodeSnippet ? "rotate-90" : ""} ${isInsertion ? "hidden" : ""}`} + />
    { @@ -181,9 +165,6 @@ export default function CodeToEditCard() { {codeToEdit ? ( ) : ( - // - // Highlight code and select Cmd + I to edit a file - // <> - {`To edit code, highlight it and press`} + {`To edit code, highlight it and press `} + {metaKeyLabel} I - meta I )}
    diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index c6ce86a3d..c9a151079 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -102,8 +102,7 @@ function ContinueInputBox(props: ContinueInputBoxProps) { }, [availableContextProviders, mode]); const historyKey = mode === "edit" ? "edit" : "chat"; - const placeholder = - mode === "edit" ? "Describe changes, '#' to add files" : undefined; + const placeholder = mode === "edit" ? "Describe changes" : undefined; const toolbarOptions: ToolbarOptions = mode === "edit" diff --git a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx index b9b27aa92..eaf3771f8 100644 --- a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx +++ b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx @@ -12,9 +12,9 @@ import { import { ReactNode } from "react"; import { vscBadgeForeground } from "../.."; import { useAppSelector } from "../../../redux/hooks"; -import { fontSize } from "../../../util"; import { ToolTip } from "../../gui/Tooltip"; import AssistantSelect from "../../modelSelection/platform/AssistantSelect"; +import { useFontSize } from "../../ui/font"; import HoverItem from "../InputToolbar/HoverItem"; import { useLump } from "./LumpContext"; import { ErrorsSectionTooltip } from "./sections/errors/ErrorsSectionTooltip"; @@ -74,8 +74,9 @@ function BlockSettingsToolbarIcon( const isErrorSection = props.sectionId === "error"; const id = `block-settings-toolbar-icon-${props.sectionId}`; - return ( + const fontSize = useFontSize(-3); + return ( <>
    - {props.tooltip} @@ -156,7 +156,7 @@ export function BlockSettingsTopToolbar() { ); return ( -
    +
    - + Select Assistant diff --git a/gui/src/pages/error.tsx b/gui/src/pages/error.tsx index 92c064019..0738696a6 100644 --- a/gui/src/pages/error.tsx +++ b/gui/src/pages/error.tsx @@ -1,13 +1,13 @@ -import { useDispatch } from "react-redux"; -import { useNavigate, useRouteError } from "react-router-dom"; -import { newSession } from "../redux/slices/sessionSlice"; -import { GithubIcon } from "../components/svg/GithubIcon"; -import { DiscordIcon } from "../components/svg/DiscordIcon"; -import { useContext, useEffect, useState } from "react"; -import { IdeMessengerContext } from "../context/IdeMessenger"; -import { Button, SecondaryButton } from "../components"; import { ArrowPathIcon, FlagIcon } from "@heroicons/react/24/outline"; import { DISCORD_LINK, GITHUB_LINK } from "core/util/constants"; +import { useContext, useEffect, useState } from "react"; +import { useDispatch } from "react-redux"; +import { useNavigate, useRouteError } from "react-router-dom"; +import { Button, SecondaryButton } from "../components"; +import { DiscordIcon } from "../components/svg/DiscordIcon"; +import { GithubIcon } from "../components/svg/GithubIcon"; +import { IdeMessengerContext } from "../context/IdeMessenger"; +import { newSession } from "../redux/slices/sessionSlice"; const ErrorPage: React.FC = () => { const error: any = useRouteError(); @@ -61,16 +61,16 @@ const ErrorPage: React.FC = () => { Report the issue on GitHub or Discord:

    -
    +
    openUrl(GITHUB_LINK)} - className="flex w-full items-center justify-center space-x-2 rounded-lg px-4 py-2 text-base text-white" + className="flex items-center justify-center space-x-2 rounded-lg px-4 py-2 text-base text-white" > GitHub openUrl(DISCORD_LINK)} - className="flex w-full items-center justify-center rounded-lg text-base" + className="flex items-center justify-center rounded-lg text-base" > Discord diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index d6ef82413..43f37418f 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -5,9 +5,9 @@ import { ExclamationTriangleIcon, } from "@heroicons/react/24/outline"; import { Editor, JSONContent } from "@tiptap/react"; -import { InputModifiers, RangeInFileWithContents } from "core"; +import { InputModifiers } from "core"; import { streamResponse } from "core/llm/stream"; -import { renderChatMessage, stripImages } from "core/util/messageContent"; +import { renderChatMessage } from "core/util/messageContent"; import { usePostHog } from "posthog-js/react"; import { useCallback, useContext, useEffect, useRef, useState } from "react"; import { ErrorBoundary } from "react-error-boundary"; @@ -21,7 +21,6 @@ import TimelineItem from "../../components/gui/TimelineItem"; import { NewSessionButton } from "../../components/mainInput/belowMainInput/NewSessionButton"; import ThinkingBlockPeek from "../../components/mainInput/belowMainInput/ThinkingBlockPeek"; import ContinueInputBox from "../../components/mainInput/ContinueInputBox"; -import { resolveEditorContent } from "../../components/mainInput/TipTapEditor/utils"; import { useOnboardingCard } from "../../components/OnboardingCard"; import StepContainer from "../../components/StepContainer"; import { TabBar } from "../../components/TabBar/TabBar"; @@ -32,8 +31,6 @@ import { selectCurrentToolCall, selectCurrentToolCallApplyState, } from "../../redux/selectors/selectCurrentToolCall"; -import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { setEditStateApplyStatus } from "../../redux/slices/editModeState"; import { newSession, updateToolCallOutput, @@ -44,7 +41,7 @@ import { setShowDialog, } from "../../redux/slices/uiSlice"; import { cancelStream } from "../../redux/thunks/cancelStream"; -import { exitEditMode } from "../../redux/thunks/editMode"; +import { exitEditMode, streamEditThunk } from "../../redux/thunks/editMode"; import { loadLastSession } from "../../redux/thunks/session"; import { streamResponseThunk } from "../../redux/thunks/streamResponse"; import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; @@ -103,7 +100,9 @@ export function Chat() { const showSessionTabs = useAppSelector( (store) => store.config.config.ui?.showSessionTabs, ); - const selectedChatModel = useAppSelector(selectSelectedChatModel); + const selectedModels = useAppSelector( + (store) => store.config?.config.selectedModelByRole, + ); const isStreaming = useAppSelector((state) => state.session.isStreaming); const [stepsOpen, setStepsOpen] = useState<(boolean | undefined)[]>([]); const mainTextInputRef = useRef(null); @@ -172,7 +171,20 @@ export function Chat() { "Cannot submit message while awaiting tool call apply", ); } - if (selectedChatModel?.provider === "free-trial") { + + const model = + mode === "edit" + ? (selectedModels?.edit ?? selectedModels?.chat) + : selectedModels?.chat; + if (!model) { + return; + } + + if (mode === "edit" && codeToEdit.length === 0) { + return; + } + + if (model.provider === "free-trial") { const newCount = incrementFreeTrialCount(); if (newCount === FREE_TRIAL_LIMIT_REQUESTS) { @@ -200,14 +212,18 @@ export function Chat() { } if (mode === "edit") { - handleSingleRangeEditOrInsertion(editorState); - return; - } + dispatch( + streamEditThunk({ + editorState, + codeToEdit, + }), + ); + } else { + dispatch(streamResponseThunk({ editorState, modifiers, index })); - dispatch(streamResponseThunk({ editorState, modifiers, index })); - - if (editorToClearOnSend) { - editorToClearOnSend.commands.clearContent(); + if (editorToClearOnSend) { + editorToClearOnSend.commands.clearContent(); + } } // Increment localstorage counter for popup @@ -223,47 +239,9 @@ export function Chat() { setLocalStorage("mainTextEntryCounter", 1); } }, - [ - history, - selectedChatModel, - streamResponse, - mode, - codeToEdit, - toolCallState, - ], + [history, selectedModels, streamResponse, mode, codeToEdit, toolCallState], ); - async function handleSingleRangeEditOrInsertion(editorState: JSONContent) { - if (!selectedChatModel) { - console.error("No selected chat model"); - return; - } - - const [contextItems, __, userInstructions, _] = await resolveEditorContent({ - editorState, - modifiers: { - noContext: true, - useCodebase: false, - }, - ideMessenger, - defaultContextProviders: [], - availableSlashCommands: [], - dispatch, - }); - - const prompt = [ - ...contextItems.map((item) => item.content), - stripImages(userInstructions), - ].join("\n\n"); - - ideMessenger.post("edit/sendPrompt", { - prompt, - range: codeToEdit[0] as RangeInFileWithContents, - }); - - dispatch(setEditStateApplyStatus("streaming")); - } - useWebviewListener( "newSession", async () => { @@ -327,13 +305,13 @@ export function Chat() { > {item.message.role === "user" ? ( <> - {mode === "edit" && } + {/* {mode === "edit" && } */} sendInput(editorState, modifiers, index) } isLastUserInput={isLastUserInput(index)} - isMainInput={mode === "edit"} + isMainInput={false} editorState={item.editorState} contextItems={item.contextItems} inputId={item.message.id} @@ -405,19 +383,17 @@ export function Chat() { ))}
    - {mode === "edit" && history.length > 0 ? null : ( - <> - {mode === "edit" && } - - sendInput(editorState, modifiers, undefined, editor) - } - inputId={MAIN_EDITOR_INPUT_ID} - /> - - )} + <> + {mode === "edit" && } + + sendInput(editorState, modifiers, undefined, editor) + } + inputId={MAIN_EDITOR_INPUT_ID} + /> +
    ( + "chat/streamResponse", + async ({ editorState, codeToEdit }, { dispatch, extra, getState }) => { + await dispatch( + streamThunkWrapper(async () => { + const [contextItems, __, userInstructions, _] = + await resolveEditorContent({ + editorState, + modifiers: { + noContext: true, + useCodebase: false, + }, + ideMessenger: extra.ideMessenger, + defaultContextProviders: [], + availableSlashCommands: [], + dispatch, + }); + + const prompt = [ + ...contextItems.map((item) => item.content), + stripImages(userInstructions), + ].join("\n\n"); + + const response = await extra.ideMessenger.request("edit/sendPrompt", { + prompt, + range: codeToEdit[0] as RangeInFileWithContents, + }); + + if (response.status === "error") { + throw new Error(response.error); + } + + dispatch(setEditStateApplyStatus("streaming")); + }), + ); + }, +); export const exitEditMode = createAsyncThunk< void, @@ -44,7 +93,7 @@ export const exitEditMode = createAsyncThunk< dispatch(setMode(goToMode ?? state.editModeState.returnToMode)); - extra.ideMessenger.post("edit/exit", { + extra.ideMessenger.post("edit/clearDecorations", { shouldFocusEditor: state.editModeState.returnCursorToEditorAfterEdit, }); }, From dfc57bef872d7264299c676a408b7bacdc1a79bc Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 23:21:21 -0700 Subject: [PATCH 09/25] progress on apply states --- gui/src/components/AcceptRejectAllButtons.tsx | 43 +++++++++++--- gui/src/components/Layout.tsx | 6 -- .../components/StepContainer/EditActions.tsx | 57 ------------------- .../StepContainer/ResponseActions.tsx | 8 --- .../components/mainInput/EditModeDetails.tsx | 28 +++++++++ gui/src/components/mainInput/InputToolbar.tsx | 2 +- .../TipTapEditor/utils/editorConfig.ts | 2 +- .../components/modelSelection/ModeSelect.tsx | 3 +- gui/src/hooks/useSetup.ts | 1 + gui/src/pages/gui/Chat.tsx | 51 ++++++++--------- gui/src/pages/gui/ToolCallDiv/EditFile.tsx | 11 +--- gui/src/redux/slices/editModeState.ts | 9 +-- gui/src/redux/thunks/editMode.ts | 23 +++++--- gui/src/redux/thunks/index.ts | 1 - 14 files changed, 107 insertions(+), 138 deletions(-) delete mode 100644 gui/src/components/StepContainer/EditActions.tsx create mode 100644 gui/src/components/mainInput/EditModeDetails.tsx diff --git a/gui/src/components/AcceptRejectAllButtons.tsx b/gui/src/components/AcceptRejectAllButtons.tsx index 5ffbabbf1..c85d97373 100644 --- a/gui/src/components/AcceptRejectAllButtons.tsx +++ b/gui/src/components/AcceptRejectAllButtons.tsx @@ -3,20 +3,25 @@ import { ApplyState } from "core"; import { useContext } from "react"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { getMetaKeyLabel } from "../util"; +import { useFontSize } from "./ui/font"; export interface AcceptRejectAllButtonsProps { - pendingApplyStates: ApplyState[]; + applyStates: ApplyState[]; onAcceptOrReject?: (outcome: AcceptOrRejectOutcome) => void; } export type AcceptOrRejectOutcome = "acceptDiff" | "rejectDiff"; export default function AcceptRejectAllButtons({ - pendingApplyStates, + applyStates, onAcceptOrReject, }: AcceptRejectAllButtonsProps) { + const pendingApplyStates = applyStates.filter( + (state) => state.status === "done", + ); const ideMessenger = useContext(IdeMessengerContext); + const tinyFont = useFontSize(-3); async function handleAcceptOrReject(status: AcceptOrRejectOutcome) { for (const { filepath = "", streamId } of pendingApplyStates) { ideMessenger.post(status, { @@ -30,23 +35,45 @@ export default function AcceptRejectAllButtons({ } } + if (!pendingApplyStates.length) { + return null; + } + return ( -
    +
    ); diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 0b07a7405..20f28cc05 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -158,12 +158,6 @@ const Layout = () => { fromEditor: true, }), ); - dispatch( - enterEditMode({ - returnCursorToEditor: true, - returnToMode: mode, - }), - ); }, [mode], ); diff --git a/gui/src/components/StepContainer/EditActions.tsx b/gui/src/components/StepContainer/EditActions.tsx deleted file mode 100644 index 901b7ea00..000000000 --- a/gui/src/components/StepContainer/EditActions.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { ChatHistoryItem } from "core"; - -import { renderChatMessage } from "core/util/messageContent"; -import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { exitEditMode } from "../../redux/thunks/editMode"; -import AcceptRejectAllButtons from "../AcceptRejectAllButtons"; -import FeedbackButtons from "../FeedbackButtons"; -import { CopyIconButton } from "../gui/CopyIconButton"; - -export interface EditActionsProps { - index: number; - item: ChatHistoryItem; -} - -export default function EditActions({ index, item }: EditActionsProps) { - const dispatch = useAppDispatch(); - - const applyState = useAppSelector((store) => store.editModeState.applyState); - - if ( - applyState.status === "not-started" || - applyState.status === "streaming" - ) { - return null; - } - return ( -
    -
    - -
    - {applyState.status === "done" && ( - { - if (outcome === "acceptDiff") { - dispatch(exitEditMode({})); - } - }} - /> - )} -
    - -
    - - - -
    -
    - ); -} diff --git a/gui/src/components/StepContainer/ResponseActions.tsx b/gui/src/components/StepContainer/ResponseActions.tsx index c49daccda..5bd7f3a54 100644 --- a/gui/src/components/StepContainer/ResponseActions.tsx +++ b/gui/src/components/StepContainer/ResponseActions.tsx @@ -1,11 +1,9 @@ import { BarsArrowDownIcon, TrashIcon } from "@heroicons/react/24/outline"; import { ChatHistoryItem } from "core"; import { renderChatMessage } from "core/util/messageContent"; -import { useAppSelector } from "../../redux/hooks"; import FeedbackButtons from "../FeedbackButtons"; import { CopyIconButton } from "../gui/CopyIconButton"; import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; -import EditActions from "./EditActions"; export interface ResponseActionsProps { isTruncated: boolean; @@ -22,12 +20,6 @@ export default function ResponseActions({ isTruncated, onDelete, }: ResponseActionsProps) { - const mode = useAppSelector((store) => store.session.mode); - - if (mode === "edit") { - return ; - } - return (
    {isTruncated && ( diff --git a/gui/src/components/mainInput/EditModeDetails.tsx b/gui/src/components/mainInput/EditModeDetails.tsx new file mode 100644 index 000000000..3ccddd691 --- /dev/null +++ b/gui/src/components/mainInput/EditModeDetails.tsx @@ -0,0 +1,28 @@ +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { exitEditMode } from "../../redux/thunks/editMode"; +import AcceptRejectAllButtons from "../AcceptRejectAllButtons"; + +const EditModeDetails = () => { + const isStreaming = useAppSelector((store) => store.session.isStreaming); + const mode = useAppSelector((store) => store.session.mode); + const dispatch = useAppDispatch(); + const editApplyState = useAppSelector( + (store) => store.editModeState.applyState, + ); + + if (isStreaming || mode !== "edit") { + return null; + } + return ( + { + if (outcome === "acceptDiff") { + dispatch(exitEditMode({})); + } + }} + /> + ); +}; + +export default EditModeDetails; diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index a937e0f59..981db1496 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -9,7 +9,7 @@ import { selectCurrentToolCallApplyState, } from "../../redux/selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { exitEditMode } from "../../redux/thunks"; +import { exitEditMode } from "../../redux/thunks/editMode"; import { getAltKeyLabel, getMetaKeyLabel, diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index 421130a29..1b0ac93c9 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -23,7 +23,7 @@ import { useAppSelector } from "../../../../redux/hooks"; import { selectUseActiveFile } from "../../../../redux/selectors"; import { selectSelectedChatModel } from "../../../../redux/slices/configSlice"; import { AppDispatch } from "../../../../redux/store"; -import { exitEditMode } from "../../../../redux/thunks"; +import { exitEditMode } from "../../../../redux/thunks/editMode"; import { getFontSize, isJetBrains } from "../../../../util"; import * as ContinueExtensions from "../extensions"; import { TipTapEditorProps } from "../TipTapEditor"; diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index 069f0dd96..99519d5bb 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -14,8 +14,7 @@ import { lightGray } from ".."; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { setMode } from "../../redux/slices/sessionSlice"; -import { exitEditMode } from "../../redux/thunks"; -import { enterEditMode } from "../../redux/thunks/editMode"; +import { enterEditMode, exitEditMode } from "../../redux/thunks/editMode"; import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util"; import { Listbox, diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index dcfab3e29..5b445952d 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -262,6 +262,7 @@ function useSetup() { "updateApplyState", async (state) => { if (state.streamId === EDIT_MODE_STREAM_ID) { + console.log(state); dispatch(setEditStateApplyState(state)); } else { // chat or agent diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 43f37418f..3c3abaf47 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -9,7 +9,14 @@ import { InputModifiers } from "core"; import { streamResponse } from "core/llm/stream"; import { renderChatMessage } from "core/util/messageContent"; import { usePostHog } from "posthog-js/react"; -import { useCallback, useContext, useEffect, useRef, useState } from "react"; +import { + useCallback, + useContext, + useEffect, + useMemo, + useRef, + useState, +} from "react"; import { ErrorBoundary } from "react-error-boundary"; import styled from "styled-components"; import { Button, lightGray, vscBackground } from "../../components"; @@ -41,7 +48,7 @@ import { setShowDialog, } from "../../redux/slices/uiSlice"; import { cancelStream } from "../../redux/thunks/cancelStream"; -import { exitEditMode, streamEditThunk } from "../../redux/thunks/editMode"; +import { streamEditThunk } from "../../redux/thunks/editMode"; import { loadLastSession } from "../../redux/thunks/session"; import { streamResponseThunk } from "../../redux/thunks/streamResponse"; import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; @@ -51,6 +58,7 @@ import { } from "../../util/freeTrial"; import CodeToEditCard from "../../components/mainInput/CodeToEditCard"; +import EditModeDetails from "../../components/mainInput/EditModeDetails"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; @@ -113,19 +121,18 @@ export function Chat() { ); const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); const toolCallState = useAppSelector(selectCurrentToolCall); + const mode = useAppSelector((store) => store.session.mode); const applyStates = useAppSelector( (state) => state.session.codeBlockApplyStates.states, ); - const pendingApplyStates = applyStates.filter( - (state) => state.status === "done", - ); - const hasPendingApplies = pendingApplyStates.length > 0; - const mode = useAppSelector((store) => store.session.mode); + const lastSessionId = useAppSelector((state) => state.session.lastSessionId); const hasDismissedExploreDialog = useAppSelector( (state) => state.ui.hasDismissedExploreDialog, ); - const jetbrains = isJetBrains(); + const jetbrains = useMemo(() => { + return isJetBrains(); + }, []); useEffect(() => { // Cmd + Backspace to delete current step @@ -143,7 +150,7 @@ export function Chat() { return () => { window.removeEventListener("keydown", listener); }; - }, [isStreaming]); + }, [isStreaming, jetbrains]); const { widget, highlights } = useFindWidget(stepsDivRef); @@ -305,7 +312,6 @@ export function Chat() { > {item.message.role === "user" ? ( <> - {/* {mode === "edit" && } */} sendInput(editorState, modifiers, index) @@ -384,6 +390,12 @@ export function Chat() {
    <> + {!isStreaming && mode !== "edit" && ( + {}} + /> + )} {mode === "edit" && } +
    - - {hasPendingApplies && ( - { - if (outcome === "acceptDiff") { - await dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); - dispatch(exitEditMode({})); - } - }} - /> - )} - {!hasDismissedExploreDialog && } - {history.length === 0 && ( )} diff --git a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx index 35b9d1a5f..d6a13aead 100644 --- a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx @@ -1,7 +1,6 @@ import { getMarkdownLanguageTagForFile } from "core/util"; import { useEffect } from "react"; import { v4 as uuidv4 } from "uuid"; -import AcceptRejectAllButtons from "../../../components/AcceptRejectAllButtons"; import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; import { @@ -50,20 +49,14 @@ export function EditFile(props: EditToolCallProps) { expandCodeblocks={false} itemIndex={props.historyIndex} /> - {/* TODO better indicator of generation at bottom */} - {/* {isStreaming && applyState?.status === "streaming" && ( -
    - Generating... -
    - )} */} - {!isStreaming && applyState?.status === "done" && ( + {/* {!isStreaming && applyState?.status === "done" && (
    {}} />
    - )} + )} */} ); } diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index fc8d6ab32..6e2c40e08 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -1,5 +1,5 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { ApplyState, ApplyStateStatus, CodeToEdit, MessageModes } from "core"; +import { ApplyState, CodeToEdit, MessageModes } from "core"; import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; export interface EditModeState { // Array because of previous multi-file edit functionality @@ -35,12 +35,6 @@ export const editModeStateSlice = createSlice({ ) => { state.returnToMode = payload; }, - setEditStateApplyStatus: ( - state, - { payload }: PayloadAction, - ) => { - state.applyState.status = payload; - }, setEditStateApplyState: (state, { payload }: PayloadAction) => { state.applyState = payload; }, @@ -70,7 +64,6 @@ export const { setReturnCursorToEditorAfterEdit, clearCodeToEdit, setCodeToEdit, - setEditStateApplyStatus, setEditStateApplyState, } = editModeStateSlice.actions; export default editModeStateSlice.reducer; diff --git a/gui/src/redux/thunks/editMode.ts b/gui/src/redux/thunks/editMode.ts index 150daf4f3..48d6c1ad5 100644 --- a/gui/src/redux/thunks/editMode.ts +++ b/gui/src/redux/thunks/editMode.ts @@ -1,15 +1,16 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import { JSONContent } from "@tiptap/core"; import { CodeToEdit, MessageModes, RangeInFileWithContents } from "core"; +import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; import { stripImages } from "core/util/messageContent"; import { resolveEditorContent } from "../../components/mainInput/TipTapEditor"; import { clearCodeToEdit, - setEditStateApplyStatus, + setEditStateApplyState, setReturnCursorToEditorAfterEdit, setReturnToModeAfterEdit, } from "../slices/editModeState"; -import { newSession, setMode } from "../slices/sessionSlice"; +import { newSession, setActive, setMode } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; import { loadLastSession, saveCurrentSession } from "./session"; import { streamThunkWrapper } from "./streamThunkWrapper"; @@ -26,6 +27,7 @@ export const streamEditThunk = createAsyncThunk< async ({ editorState, codeToEdit }, { dispatch, extra, getState }) => { await dispatch( streamThunkWrapper(async () => { + dispatch(setActive()); const [contextItems, __, userInstructions, _] = await resolveEditorContent({ editorState, @@ -52,8 +54,6 @@ export const streamEditThunk = createAsyncThunk< if (response.status === "error") { throw new Error(response.error); } - - dispatch(setEditStateApplyStatus("streaming")); }), ); }, @@ -79,6 +79,10 @@ export const exitEditMode = createAsyncThunk< }); } + extra.ideMessenger.post("edit/clearDecorations", { + shouldFocusEditor: state.editModeState.returnCursorToEditorAfterEdit, + }); + dispatch(clearCodeToEdit()); if (openNewSession) { @@ -92,10 +96,6 @@ export const exitEditMode = createAsyncThunk< } dispatch(setMode(goToMode ?? state.editModeState.returnToMode)); - - extra.ideMessenger.post("edit/clearDecorations", { - shouldFocusEditor: state.editModeState.returnCursorToEditorAfterEdit, - }); }, ); @@ -125,7 +125,12 @@ export const enterEditMode = createAsyncThunk< generateTitle: false, }), ); - dispatch(setEditStateApplyStatus("not-started")); + dispatch( + setEditStateApplyState({ + streamId: EDIT_MODE_STREAM_ID, + status: "not-started", + }), + ); dispatch(setMode("edit")); }, ); diff --git a/gui/src/redux/thunks/index.ts b/gui/src/redux/thunks/index.ts index 9c619d785..7fe098e70 100644 --- a/gui/src/redux/thunks/index.ts +++ b/gui/src/redux/thunks/index.ts @@ -1,4 +1,3 @@ -export { exitEditMode } from "./editMode"; export { gatherContext } from "./gatherContext"; export { resetStateForNewMessage } from "./resetStateForNewMessage"; export { streamNormalInput } from "./streamNormalInput"; From 41791cd51fa6221f20e7766fa413624e7bfb72f9 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 29 Apr 2025 23:30:11 -0700 Subject: [PATCH 10/25] last chat or agent session empty --- gui/src/hooks/useSetup.ts | 17 ++++++++++++----- gui/src/redux/slices/editModeState.ts | 9 +++++++++ gui/src/redux/thunks/editMode.ts | 8 ++++---- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 5b445952d..5d13d6583 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -12,11 +12,11 @@ import { } from "../redux"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { selectCurrentToolCallApplyState } from "../redux/selectors/selectCurrentToolCall"; +import { setConfigResult } from "../redux/slices/configSlice"; import { - selectSelectedChatModel, - setConfigResult, -} from "../redux/slices/configSlice"; -import { setEditStateApplyState } from "../redux/slices/editModeState"; + setEditStateApplyState, + setLastNonEditSessionEmpty, +} from "../redux/slices/editModeState"; import { updateIndexingStatus } from "../redux/slices/indexingSlice"; import { acceptToolCall, @@ -37,7 +37,7 @@ function useSetup() { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const history = useAppSelector((store) => store.session.history); - const defaultModel = useAppSelector(selectSelectedChatModel); + const selectedProfileId = useAppSelector( (store) => store.profiles.selectedProfileId, ); @@ -295,6 +295,13 @@ function useSetup() { }, [currentToolCallApplyState, history], ); + + const mode = useAppSelector((store) => store.session.mode); + useEffect(() => { + if (mode !== "edit") { + dispatch(setLastNonEditSessionEmpty(history.length === 0)); + } + }, [mode, history]); } export default useSetup; diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts index 6e2c40e08..a741db759 100644 --- a/gui/src/redux/slices/editModeState.ts +++ b/gui/src/redux/slices/editModeState.ts @@ -8,6 +8,7 @@ export interface EditModeState { applyState: ApplyState; returnCursorToEditorAfterEdit: boolean; returnToMode: MessageModes; + lastNonEditSessionWasEmpty: boolean; } const initialState: EditModeState = { @@ -17,6 +18,7 @@ const initialState: EditModeState = { codeToEdit: [], returnCursorToEditorAfterEdit: false, returnToMode: "chat", + lastNonEditSessionWasEmpty: false, }; export const editModeStateSlice = createSlice({ @@ -55,6 +57,12 @@ export const editModeStateSlice = createSlice({ clearCodeToEdit: (state) => { state.codeToEdit = []; }, + setLastNonEditSessionEmpty: ( + state, + { payload }: PayloadAction, + ) => { + state.lastNonEditSessionWasEmpty = payload; + }, }, selectors: {}, }); @@ -65,5 +73,6 @@ export const { clearCodeToEdit, setCodeToEdit, setEditStateApplyState, + setLastNonEditSessionEmpty, } = editModeStateSlice.actions; export default editModeStateSlice.reducer; diff --git a/gui/src/redux/thunks/editMode.ts b/gui/src/redux/thunks/editMode.ts index 48d6c1ad5..472dcc275 100644 --- a/gui/src/redux/thunks/editMode.ts +++ b/gui/src/redux/thunks/editMode.ts @@ -85,7 +85,7 @@ export const exitEditMode = createAsyncThunk< dispatch(clearCodeToEdit()); - if (openNewSession) { + if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) { dispatch(newSession()); } else { await dispatch( @@ -111,13 +111,13 @@ export const enterEditMode = createAsyncThunk< ) => { const state = getState(); - dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode)); - dispatch(setReturnCursorToEditorAfterEdit(returnCursorToEditor ?? false)); - if (state.session.mode === "edit") { return; } + dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode)); + dispatch(setReturnCursorToEditorAfterEdit(returnCursorToEditor ?? false)); + await dispatch( saveCurrentSession({ openNewSession: true, From 577af64909527a3bbebbcbe6ba776a53f5cc5d4e Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 30 Apr 2025 00:01:01 -0700 Subject: [PATCH 11/25] apply state fixes --- extensions/vscode/src/commands.ts | 2 +- gui/src/components/AcceptRejectAllButtons.tsx | 27 +++++++++++-------- .../components/mainInput/EditModeDetails.tsx | 27 ++++++++++++------- .../sections/errors/ErrorsSectionTooltip.tsx | 2 +- gui/src/hooks/useSetup.ts | 4 +-- gui/src/pages/gui/ToolCallDiv/EditFile.tsx | 26 ++++++------------ gui/src/redux/slices/editModeState.ts | 21 ++++++++++----- gui/src/redux/thunks/editMode.ts | 11 +++----- 8 files changed, 64 insertions(+), 56 deletions(-) diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index af9c8a232..5241dc1dc 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -282,7 +282,7 @@ async function processDiff( }); } - await sidebar.webviewProtocol.request("exitEditMode", undefined); + // await sidebar.webviewProtocol.request("exitEditMode", undefined); // Save the file await ide.saveFile(newOrCurrentUri); diff --git a/gui/src/components/AcceptRejectAllButtons.tsx b/gui/src/components/AcceptRejectAllButtons.tsx index c85d97373..6f6147ad2 100644 --- a/gui/src/components/AcceptRejectAllButtons.tsx +++ b/gui/src/components/AcceptRejectAllButtons.tsx @@ -40,17 +40,20 @@ export default function AcceptRejectAllButtons({ } return ( -
    +
    - - {shouldRenderRedo && ( - - )} -
    - ); -} diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index b20701ba2..e81545d8b 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -43,7 +43,6 @@ type SessionState = { title: string; id: string; streamAborter: AbortController; - curCheckpointIndex: number; mainEditorContentTrigger?: JSONContent | undefined; symbols: FileSymbolMap; mode: MessageModes; @@ -60,7 +59,6 @@ const initialState: SessionState = { isStreaming: false, title: NEW_SESSION_TITLE, id: uuidv4(), - curCheckpointIndex: 0, streamAborter: new AbortController(), symbols: {}, mode: "chat", @@ -178,8 +176,6 @@ export const sessionSlice = createSlice({ }, contextItems: [], }); - - state.curCheckpointIndex = Math.floor(index / 2); } else { // New input/response messages state.history = state.history.concat([ @@ -201,8 +197,6 @@ export const sessionSlice = createSlice({ contextItems: [], }, ]); - - state.curCheckpointIndex = Math.floor((state.history.length - 1) / 2); // TODO this feels really fragile } state.isStreaming = true; @@ -432,12 +426,10 @@ export const sessionSlice = createSlice({ state.history = payload.history as any; state.title = payload.title; state.id = payload.sessionId; - state.curCheckpointIndex = 0; } else { state.history = []; state.title = NEW_SESSION_TITLE; state.id = uuidv4(); - state.curCheckpointIndex = 0; } }, updateSessionTitle: (state, { payload }: PayloadAction) => { @@ -529,19 +521,6 @@ export const sessionSlice = createSlice({ state.history[state.history.length - 1].contextItems = contextItems; }, - - updateCurCheckpoint: ( - state, - { payload }: PayloadAction<{ filepath: string; content: string }>, - ) => { - const checkpoint = state.history[state.curCheckpointIndex].checkpoint; - if (checkpoint) { - checkpoint[payload.filepath] = payload.content; - } - }, - setCurCheckpointIndex: (state, { payload }: PayloadAction) => { - state.curCheckpointIndex = payload; - }, updateApplyState: (state, { payload }: PayloadAction) => { const applyState = state.codeBlockApplyStates.states.find( (state) => state.streamId === payload.streamId, @@ -732,8 +711,6 @@ export const { setMainEditorContentTrigger, deleteMessage, setIsGatheringContext, - updateCurCheckpoint, - setCurCheckpointIndex, resetNextCodeBlockToApplyIndex, updateApplyState, abortStream, diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 6591e72c5..983f7bb6c 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -51,7 +51,6 @@ const saveSubsetFilters = [ // higher risk to persist // codeBlockApplyStates // symbols - // curCheckpointIndex ]), createFilter("editModeState", [ "returnToMode", From fc3f7ac54ef7e3ea1c85582caee6c330170e0148 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 30 Apr 2025 19:33:38 -0700 Subject: [PATCH 20/25] fix toggling focus and history -> edit mode --- extensions/vscode/src/commands.ts | 3 --- gui/src/components/History/HistoryTableRow.tsx | 2 ++ gui/src/components/Layout.tsx | 4 ++-- gui/src/components/modelSelection/ModeSelect.tsx | 2 +- gui/src/redux/thunks/editMode.ts | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index c62a340b4..c651f1eb2 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -117,10 +117,7 @@ async function processDiff( return; } - // if (!currentFile || newOrCurrentUri !== currentFile.path) { await ide.openFile(newOrCurrentUri); - // focusGUI(); - // } // Clear vertical diffs depending on action verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept"); diff --git a/gui/src/components/History/HistoryTableRow.tsx b/gui/src/components/History/HistoryTableRow.tsx index 8b7f3ba38..91854a274 100644 --- a/gui/src/components/History/HistoryTableRow.tsx +++ b/gui/src/components/History/HistoryTableRow.tsx @@ -6,6 +6,7 @@ import { useNavigate } from "react-router-dom"; import { Input } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { exitEditMode } from "../../redux/thunks/editMode"; import { deleteSession, getSession, @@ -68,6 +69,7 @@ export function HistoryTableRow({ data-testid={`history-row-${index}`} className="hover:bg-vsc-editor-background relative box-border flex cursor-pointer overflow-hidden rounded-lg p-3" onClick={async () => { + await dispatch(exitEditMode({})); if (sessionMetadata.sessionId !== currentSessionId) { await dispatch( loadSession({ diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 381904afd..46d681c8d 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -164,7 +164,7 @@ const Layout = () => { }), ); }, - [mode], + [], ); useWebviewListener( @@ -172,7 +172,7 @@ const Layout = () => { async () => { await dispatch(exitEditMode({})); }, - [mode], + [], ); useEffect(() => { diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index ee6871298..21c0fbf68 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -128,7 +128,7 @@ function ModeSelect() { document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); - }, [dispatch, mode, jetbrains]); + }, [cycleMode]); return ( diff --git a/gui/src/redux/thunks/editMode.ts b/gui/src/redux/thunks/editMode.ts index 8323ed7a5..4341b14a4 100644 --- a/gui/src/redux/thunks/editMode.ts +++ b/gui/src/redux/thunks/editMode.ts @@ -72,9 +72,9 @@ export const exitEditMode = createAsyncThunk< return; } - for (const code of codeToEdit) { + if (codeToEdit[0] && state.editModeState.applyState.numDiffs) { extra.ideMessenger.post("rejectDiff", { - filepath: code.filepath, + filepath: codeToEdit[0].filepath, }); } From d0cdb50d2893162cdcd1c1d0db0188462eb774f0 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 30 Apr 2025 19:46:17 -0700 Subject: [PATCH 21/25] fix clearing content --- gui/src/components/modelSelection/ModeSelect.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index 21c0fbf68..8084e4791 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -13,7 +13,10 @@ import styled from "styled-components"; import { lightGray } from ".."; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { setMode } from "../../redux/slices/sessionSlice"; +import { + setMainEditorContentTrigger, + setMode, +} from "../../redux/slices/sessionSlice"; import { enterEditMode, exitEditMode } from "../../redux/thunks/editMode"; import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util"; import { useMainEditor } from "../mainInput/TipTapEditor"; @@ -34,7 +37,9 @@ function ModeSelect() { const dispatch = useAppDispatch(); const mode = useAppSelector((store) => store.session.mode); const selectedModel = useAppSelector(selectSelectedChatModel); - const agentModeSupported = selectedModel && modelSupportsTools(selectedModel); + const agentModeSupported = useMemo(() => { + return selectedModel && modelSupportsTools(selectedModel); + }, [selectedModel]); const { mainEditor } = useMainEditor(); const jetbrains = useMemo(() => { return isJetBrains(); @@ -70,6 +75,9 @@ function ModeSelect() { : ["chat", "agent", "edit"]; const currentIndex = modes.indexOf(mode); const nextMode = modes[(currentIndex + 1) % modes.length]; + + const mainEditorContent = mainEditor?.getJSON(); + if (mode === "edit") { await dispatch( exitEditMode({ @@ -87,6 +95,7 @@ function ModeSelect() { dispatch(setMode(nextMode)); } } + dispatch(setMainEditorContentTrigger(mainEditorContent)); mainEditor?.commands.focus(); }, [jetbrains, mode, mainEditor]); @@ -95,6 +104,7 @@ function ModeSelect() { if (newMode === mode) { return; } + const mainEditorContent = mainEditor?.getJSON(); if (newMode === "edit") { await dispatch( @@ -113,6 +123,7 @@ function ModeSelect() { dispatch(setMode(newMode)); } } + dispatch(setMainEditorContentTrigger(mainEditorContent)); mainEditor?.commands.focus(); }, [mode, mainEditor], From e00b98758ef435c4dc6d679454e78cd95747d9c9 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 30 Apr 2025 20:14:26 -0700 Subject: [PATCH 22/25] ParallelListeners instead of useSetup --- gui/src/App.tsx | 13 ++++--------- gui/src/components/Layout.tsx | 3 +-- gui/src/components/mainInput/ContinueInputBox.tsx | 2 ++ gui/src/components/modelSelection/ModeSelect.tsx | 13 +++++-------- .../hooks/{useSetup.ts => ParallelListeners.tsx} | 9 +++------ 5 files changed, 15 insertions(+), 25 deletions(-) rename gui/src/hooks/{useSetup.ts => ParallelListeners.tsx} (98%) diff --git a/gui/src/App.tsx b/gui/src/App.tsx index 2f3a94dd8..03b6fb05a 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -3,7 +3,7 @@ import Layout from "./components/Layout"; import { MainEditorProvider } from "./components/mainInput/TipTapEditor"; import { SubmenuContextProvidersProvider } from "./context/SubmenuContextProviders"; import { VscThemeProvider } from "./context/VscTheme"; -import useSetup from "./hooks/useSetup"; +import ParallelListeners from "./hooks/ParallelListeners"; import ConfigPage from "./pages/config"; import ErrorPage from "./pages/error"; import Chat from "./pages/gui"; @@ -42,14 +42,9 @@ const router = createMemoryRouter([ ]); /* - Prevents entire app from rerendering continuously with useSetup in App - TODO - look into a more redux-esque way to do this + ParallelListeners prevents entire app from rerendering on any change in the listeners, + most of which interact with redux etc. */ -export function SetupListeners() { - useSetup(); - return <>; -} - function App() { return ( @@ -58,7 +53,7 @@ function App() { - + ); } diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 46d681c8d..a6368eab4 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -48,7 +48,6 @@ const Layout = () => { const dialogMessage = useAppSelector((state) => state.ui.dialogMessage); const showDialog = useAppSelector((state) => state.ui.showDialog); - const mode = useAppSelector((state) => state.session.mode); useWebviewListener( @@ -97,7 +96,7 @@ const Layout = () => { ); } }, - [location.pathname], + [location.pathname, mode], location.pathname === ROUTES.HOME, ); diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index c9a151079..f00ab77b1 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -85,10 +85,12 @@ function ContinueInputBox(props: ContinueInputBoxProps) { const editModeState = useAppSelector((state) => state.editModeState); const filteredSlashCommands = useMemo(() => { + return availableSlashCommands; return mode === "edit" ? [] : availableSlashCommands; }, [mode, availableSlashCommands]); const filteredContextProviders = useMemo(() => { + return availableContextProviders; if (mode === "edit") { return ( availableContextProviders?.filter( diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index 8084e4791..71f1a821d 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -13,10 +13,7 @@ import styled from "styled-components"; import { lightGray } from ".."; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { - setMainEditorContentTrigger, - setMode, -} from "../../redux/slices/sessionSlice"; +import { setMode } from "../../redux/slices/sessionSlice"; import { enterEditMode, exitEditMode } from "../../redux/thunks/editMode"; import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util"; import { useMainEditor } from "../mainInput/TipTapEditor"; @@ -76,7 +73,7 @@ function ModeSelect() { const currentIndex = modes.indexOf(mode); const nextMode = modes[(currentIndex + 1) % modes.length]; - const mainEditorContent = mainEditor?.getJSON(); + // const mainEditorContent = mainEditor?.getJSON(); if (mode === "edit") { await dispatch( @@ -95,7 +92,7 @@ function ModeSelect() { dispatch(setMode(nextMode)); } } - dispatch(setMainEditorContentTrigger(mainEditorContent)); + // dispatch(setMainEditorContentTrigger(mainEditorContent)); mainEditor?.commands.focus(); }, [jetbrains, mode, mainEditor]); @@ -104,7 +101,7 @@ function ModeSelect() { if (newMode === mode) { return; } - const mainEditorContent = mainEditor?.getJSON(); + // const mainEditorContent = mainEditor?.getJSON(); if (newMode === "edit") { await dispatch( @@ -123,7 +120,7 @@ function ModeSelect() { dispatch(setMode(newMode)); } } - dispatch(setMainEditorContentTrigger(mainEditorContent)); + // dispatch(setMainEditorContentTrigger(mainEditorContent)); mainEditor?.commands.focus(); }, [mode, mainEditor], diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/ParallelListeners.tsx similarity index 98% rename from gui/src/hooks/useSetup.ts rename to gui/src/hooks/ParallelListeners.tsx index 6f7e129ff..a4ae832e9 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/ParallelListeners.tsx @@ -33,7 +33,7 @@ import { isJetBrains } from "../util"; import { setLocalStorage } from "../util/localStorage"; import { useWebviewListener } from "./useWebviewListener"; -function useSetup() { +function ParallelListeners() { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const history = useAppSelector((store) => store.session.history); @@ -83,10 +83,6 @@ function useSetup() { const initialLoadAuthAndConfig = useCallback( async (initial: boolean) => { - // const authResult = await ideMessenger.request( - // "auth/getState", - // undefined - // ) const result = await ideMessenger.request( "config/getSerializedProfileInfo", undefined, @@ -302,6 +298,7 @@ function useSetup() { dispatch(setLastNonEditSessionEmpty(history.length === 0)); } }, [mode, history]); + return <>; } -export default useSetup; +export default ParallelListeners; From 64522f9e49f3561f3a2235506d9fa712a5e64deb Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 30 Apr 2025 20:38:34 -0700 Subject: [PATCH 23/25] cleanup --- gui/src/components/mainInput/ContinueInputBox.tsx | 2 -- .../mainInput/TipTapEditor/TipTapEditor.tsx | 14 ++++++++++---- .../mainInput/TipTapEditor/utils/editorConfig.ts | 3 +-- gui/src/components/modelSelection/ModeSelect.tsx | 7 +------ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index f00ab77b1..c9a151079 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -85,12 +85,10 @@ function ContinueInputBox(props: ContinueInputBoxProps) { const editModeState = useAppSelector((state) => state.editModeState); const filteredSlashCommands = useMemo(() => { - return availableSlashCommands; return mode === "edit" ? [] : availableSlashCommands; }, [mode, availableSlashCommands]); const filteredContextProviders = useMemo(() => { - return availableContextProviders; if (mode === "edit") { return ( availableContextProviders?.filter( diff --git a/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx index b9f341032..435e4e05e 100644 --- a/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx @@ -55,6 +55,9 @@ export function TipTapEditor(props: TipTapEditorProps) { ideMessenger, dispatch, }); + useEffect(() => { + console.log(editor); + }, [editor]); // Register the main editor with the provider useEffect(() => { @@ -81,13 +84,16 @@ export function TipTapEditor(props: TipTapEditorProps) { }, [editor, props.placeholder, historyLength]); useEffect(() => { - if (mode === "edit") { - setShouldHideToolbar(false); - } if (props.isMainInput) { editor?.commands.clearContent(true); } - }, [editor, mode, props.isMainInput]); + }, [editor, props.isMainInput]); + + useEffect(() => { + if (mode === "edit") { + setShouldHideToolbar(false); + } + }, [mode]); const editorFocusedRef = useUpdatingRef(editor?.isFocused, [editor]); diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index 31ec450d8..3fea17ad4 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -269,8 +269,7 @@ export function createEditorConfig(options: { return true; } - if (modeRef.current !== "edit") { - } else { + if (modeRef.current === "edit") { dispatch( exitEditMode({ openNewSession: false, diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index 71f1a821d..c1f1552ef 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -73,8 +73,6 @@ function ModeSelect() { const currentIndex = modes.indexOf(mode); const nextMode = modes[(currentIndex + 1) % modes.length]; - // const mainEditorContent = mainEditor?.getJSON(); - if (mode === "edit") { await dispatch( exitEditMode({ @@ -92,7 +90,6 @@ function ModeSelect() { dispatch(setMode(nextMode)); } } - // dispatch(setMainEditorContentTrigger(mainEditorContent)); mainEditor?.commands.focus(); }, [jetbrains, mode, mainEditor]); @@ -101,8 +98,6 @@ function ModeSelect() { if (newMode === mode) { return; } - // const mainEditorContent = mainEditor?.getJSON(); - if (newMode === "edit") { await dispatch( enterEditMode({ @@ -120,7 +115,7 @@ function ModeSelect() { dispatch(setMode(newMode)); } } - // dispatch(setMainEditorContentTrigger(mainEditorContent)); + mainEditor?.commands.focus(); }, [mode, mainEditor], From 71e55f57d857225edb8ca3ac2ffbbf5a3a1e4022 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 30 Apr 2025 20:47:20 -0700 Subject: [PATCH 24/25] cleanup --- gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx | 3 --- gui/src/hooks/ParallelListeners.tsx | 1 - 2 files changed, 4 deletions(-) diff --git a/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx index 435e4e05e..e9222bcbc 100644 --- a/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx @@ -55,9 +55,6 @@ export function TipTapEditor(props: TipTapEditorProps) { ideMessenger, dispatch, }); - useEffect(() => { - console.log(editor); - }, [editor]); // Register the main editor with the provider useEffect(() => { diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index a4ae832e9..1b609ce39 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -258,7 +258,6 @@ function ParallelListeners() { "updateApplyState", async (state) => { if (state.streamId === EDIT_MODE_STREAM_ID) { - console.log(state); dispatch(updateEditStateApplyState(state)); } else { // chat or agent From 08166402019d22f3812415b7f3f5d3ffdb65337b Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 30 Apr 2025 20:52:25 -0700 Subject: [PATCH 25/25] fix tests --- gui/src/util/test/render.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gui/src/util/test/render.tsx b/gui/src/util/test/render.tsx index 2b9ae5b29..21a7d7e67 100644 --- a/gui/src/util/test/render.tsx +++ b/gui/src/util/test/render.tsx @@ -1,17 +1,16 @@ import type { RenderOptions, RenderResult } from "@testing-library/react"; -import { render } from "@testing-library/react"; +import { act, render } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { PropsWithChildren } from "react"; import { Provider } from "react-redux"; import { MemoryRouter, RouterProps } from "react-router-dom"; +import { LumpProvider } from "../../components/mainInput/Lump/LumpContext"; +import { MainEditorProvider } from "../../components/mainInput/TipTapEditor"; import { AuthProvider } from "../../context/Auth"; import { IdeMessengerProvider } from "../../context/IdeMessenger"; import { MockIdeMessenger } from "../../context/MockIdeMessenger"; +import ParallelListeners from "../../hooks/ParallelListeners"; import { setupStore } from "../../redux/store"; -import { SetupListeners } from "../../App"; -import { act } from "@testing-library/react"; -import { LumpProvider } from "../../components/mainInput/Lump/LumpContext"; -import { MainEditorProvider } from "../../components/mainInput/TipTapEditor"; // As a basic setup, import your same slice reducers // This type interface extends the default options for render from RTL, as well @@ -55,7 +54,7 @@ export async function renderWithProviders( {children} - +