From 23f6ab1fc7df207a9b56772bbce6dd3081cff73f Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 4 Apr 2025 18:06:54 +0530 Subject: [PATCH 01/20] add props typing to gui/Tooltip component --- gui/src/components/gui/Tooltip.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gui/src/components/gui/Tooltip.tsx b/gui/src/components/gui/Tooltip.tsx index cf934f750..1eae5b77b 100644 --- a/gui/src/components/gui/Tooltip.tsx +++ b/gui/src/components/gui/Tooltip.tsx @@ -1,9 +1,10 @@ +import { CSSProperties } from "react"; import ReactDOM from "react-dom"; -import { Tooltip } from "react-tooltip"; +import { ITooltip, Tooltip } from "react-tooltip"; import { vscBackground, vscForeground, vscInputBorder } from ".."; import { fontSize } from "../../util"; -const TooltipStyles = { +const TooltipStyles: CSSProperties = { fontSize: fontSize(-2), backgroundColor: vscBackground, outline: `0.5px solid ${vscInputBorder}`, @@ -14,7 +15,7 @@ const TooltipStyles = { textAlign: "center", }; -export function ToolTip(props: any) { +export function ToolTip(props: ITooltip) { const combinedStyles = { ...TooltipStyles, ...props.style, From 5bb5b02d45002c2279a7f4168ce385b246a932d6 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Sat, 5 Apr 2025 11:27:51 +0530 Subject: [PATCH 02/20] fix type check errors --- gui/src/components/mainInput/InputToolbar.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 3d0a38cec..92e607d05 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -153,7 +153,7 @@ function InputToolbar(props: InputToolbarProps) { fileInputRef.current?.click(); }} /> - + Attach an image @@ -166,7 +166,7 @@ function InputToolbar(props: InputToolbarProps) { className="h-3 w-3 hover:brightness-125" /> - + Add context (files, docs, urls, etc.) From 58d9eb7a7e8102940d59f26a65e01edb130681fd Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 11 Apr 2025 17:42:55 -0700 Subject: [PATCH 03/20] feat: consolidate StepContainer --- .../CodeToEditCard/CodeToEditListItem.tsx | 10 +- .../FilenameLink.tsx | 0 .../components/StepContainer/Reasoning.tsx | 2 +- .../StepContainer/StepContainer.tsx | 9 +- .../StepContainerPreToolbar/ApplyActions.tsx | 107 ++++++++++++++++++ .../StepContainerPreToolbar/CopyButton.tsx | 0 .../StepContainerPreToolbar/FileInfo.tsx | 0 .../GeneratingCodeLoader.tsx | 0 .../StepContainerPreToolbar/InsertButton.tsx | 0 .../RunInTerminalButton.tsx | 0 .../StepContainerPreToolbar.tsx | 2 +- .../ToolbarButtonWithTooltip.tsx | 0 .../StepContainerPreToolbar/index.ts | 0 .../StyledMarkdownPreview.tsx | 22 ++-- .../StyledMarkdownPreview}/katex.css | 0 .../StyledMarkdownPreview}/markdown.css | 0 .../StyledMarkdownPreview}/utils.ts | 4 - .../utils/fixDoubleDollarLatex.ts | 0 .../utils/patchNestedMarkdown.ts | 0 .../utils/remarkTables.tsx | 0 .../SymbolLink.tsx | 0 .../SyntaxHighlightedPre.tsx | 0 .../extensions/CodeBlock/CodeBlockPreview.tsx | 2 +- .../belowMainInput/ThinkingBlockPeek.tsx | 2 +- gui/src/pages/gui/ToolCallDiv/CreateFile.tsx | 2 +- gui/src/pages/gui/ToolCallDiv/EditFile.tsx | 2 +- .../gui/ToolCallDiv/RunTerminalCommand.tsx | 2 +- 27 files changed, 132 insertions(+), 34 deletions(-) rename gui/src/components/{markdown => StepContainer}/FilenameLink.tsx (100%) create mode 100644 gui/src/components/StepContainer/StepContainerPreToolbar/ApplyActions.tsx rename gui/src/components/{markdown => StepContainer}/StepContainerPreToolbar/CopyButton.tsx (100%) rename gui/src/components/{markdown => StepContainer}/StepContainerPreToolbar/FileInfo.tsx (100%) rename gui/src/components/{markdown => StepContainer}/StepContainerPreToolbar/GeneratingCodeLoader.tsx (100%) rename gui/src/components/{markdown => StepContainer}/StepContainerPreToolbar/InsertButton.tsx (100%) rename gui/src/components/{markdown => StepContainer}/StepContainerPreToolbar/RunInTerminalButton.tsx (100%) rename gui/src/components/{markdown => StepContainer}/StepContainerPreToolbar/StepContainerPreToolbar.tsx (99%) rename gui/src/components/{markdown => StepContainer}/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx (100%) rename gui/src/components/{markdown => StepContainer}/StepContainerPreToolbar/index.ts (100%) rename gui/src/components/{markdown => StepContainer/StyledMarkdownPreview}/StyledMarkdownPreview.tsx (94%) rename gui/src/components/{markdown => StepContainer/StyledMarkdownPreview}/katex.css (100%) rename gui/src/components/{markdown => StepContainer/StyledMarkdownPreview}/markdown.css (100%) rename gui/src/components/{markdown => StepContainer/StyledMarkdownPreview}/utils.ts (94%) rename gui/src/components/{markdown => StepContainer/StyledMarkdownPreview}/utils/fixDoubleDollarLatex.ts (100%) rename gui/src/components/{markdown => StepContainer/StyledMarkdownPreview}/utils/patchNestedMarkdown.ts (100%) rename gui/src/components/{markdown => StepContainer/StyledMarkdownPreview}/utils/remarkTables.tsx (100%) rename gui/src/components/{markdown => StepContainer}/SymbolLink.tsx (100%) rename gui/src/components/{markdown => StepContainer}/SyntaxHighlightedPre.tsx (100%) diff --git a/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx b/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx index 3d59ac239..c70d2a5ef 100644 --- a/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx +++ b/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx @@ -1,18 +1,18 @@ -import FileIcon from "../FileIcon"; import { ChevronDownIcon, ChevronRightIcon, XMarkIcon, } from "@heroicons/react/24/outline"; -import { useState } from "react"; -import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview"; -import { getMarkdownLanguageTagForFile } from "core/util"; -import styled from "styled-components"; 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 "../StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; export interface CodeToEditListItemProps { code: CodeToEdit; diff --git a/gui/src/components/markdown/FilenameLink.tsx b/gui/src/components/StepContainer/FilenameLink.tsx similarity index 100% rename from gui/src/components/markdown/FilenameLink.tsx rename to gui/src/components/StepContainer/FilenameLink.tsx diff --git a/gui/src/components/StepContainer/Reasoning.tsx b/gui/src/components/StepContainer/Reasoning.tsx index d5537c82b..b1c51cd81 100644 --- a/gui/src/components/StepContainer/Reasoning.tsx +++ b/gui/src/components/StepContainer/Reasoning.tsx @@ -10,7 +10,7 @@ import { vscQuickInputBackground, } from ".."; import { getFontSize } from "../../util"; -import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview"; +import StyledMarkdownPreview from "./StyledMarkdownPreview/StyledMarkdownPreview"; interface ReasoningProps { item: ChatHistoryItem; diff --git a/gui/src/components/StepContainer/StepContainer.tsx b/gui/src/components/StepContainer/StepContainer.tsx index 01560e595..11bfab85c 100644 --- a/gui/src/components/StepContainer/StepContainer.tsx +++ b/gui/src/components/StepContainer/StepContainer.tsx @@ -8,9 +8,9 @@ import { useAppSelector } from "../../redux/hooks"; import { selectUIConfig } from "../../redux/slices/configSlice"; import { deleteMessage } from "../../redux/slices/sessionSlice"; import { getFontSize } from "../../util"; -import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview"; import Reasoning from "./Reasoning"; import ResponseActions from "./ResponseActions"; +import StyledMarkdownPreview from "./StyledMarkdownPreview/StyledMarkdownPreview"; import ThinkingIndicator from "./ThinkingIndicator"; interface StepContainerProps { @@ -43,9 +43,6 @@ export default function StepContainer(props: StepContainerProps) { historyItemAfterThis?.message.role === "thinking"; const hideActions = hideActionSpace || (isStreaming && props.isLast); - // const isStepAheadOfCurCheckpoint = - // isInEditMode && Math.floor(props.index / 2) > curCheckpointIndex; - useEffect(() => { if (!isStreaming) { const content = renderChatMessage(props.item.message).trim(); @@ -83,9 +80,7 @@ export default function StepContainer(props: StepContainerProps) { } return ( -
+
{uiConfig?.displayRawMarkdown ? (
 void;
+  onClickReject: () => void;
+  onClickApply: () => void;
+}
+
+export default function ApplyActions(props: ApplyActionsProps) {
+  const [hasRejected, setHasRejected] = useState(false);
+  const [showApplied, setShowApplied] = useState(false);
+  const isClosed = props.applyState?.status === "closed";
+  const isSuccessful = !hasRejected && props.applyState?.numDiffs === 0;
+
+  useEffect(() => {
+    if (isClosed && isSuccessful) {
+      setShowApplied(true);
+      const timer = setTimeout(() => {
+        setShowApplied(false);
+      }, 3_000);
+      return () => clearTimeout(timer);
+    }
+  }, [isClosed, isSuccessful]);
+
+  function onClickReject() {
+    props.onClickReject();
+    setHasRejected(true);
+  }
+
+  const applyButton = (text: string) => (
+    
+  );
+
+  switch (props.applyState ? props.applyState.status : null) {
+    case "streaming":
+      return (
+        
+ + Applying + + +
+ ); + case "done": + return ( +
+ + {`${props.applyState?.numDiffs === 1 ? "1 diff" : `${props.applyState?.numDiffs} diffs`}`} + {` remaining`} + + +
+ + + + + + + +
+
+ ); + case "closed": + if (!hasRejected && props.applyState?.numDiffs === 0) { + if (showApplied) { + return ( + + Applied + + + ); + } + if (props.disableManualApply) { + return null; + } + return applyButton("Reapply"); + } + default: + if (props.disableManualApply) { + return null; + } + return applyButton("Apply"); + } +} diff --git a/gui/src/components/markdown/StepContainerPreToolbar/CopyButton.tsx b/gui/src/components/StepContainer/StepContainerPreToolbar/CopyButton.tsx similarity index 100% rename from gui/src/components/markdown/StepContainerPreToolbar/CopyButton.tsx rename to gui/src/components/StepContainer/StepContainerPreToolbar/CopyButton.tsx diff --git a/gui/src/components/markdown/StepContainerPreToolbar/FileInfo.tsx b/gui/src/components/StepContainer/StepContainerPreToolbar/FileInfo.tsx similarity index 100% rename from gui/src/components/markdown/StepContainerPreToolbar/FileInfo.tsx rename to gui/src/components/StepContainer/StepContainerPreToolbar/FileInfo.tsx diff --git a/gui/src/components/markdown/StepContainerPreToolbar/GeneratingCodeLoader.tsx b/gui/src/components/StepContainer/StepContainerPreToolbar/GeneratingCodeLoader.tsx similarity index 100% rename from gui/src/components/markdown/StepContainerPreToolbar/GeneratingCodeLoader.tsx rename to gui/src/components/StepContainer/StepContainerPreToolbar/GeneratingCodeLoader.tsx diff --git a/gui/src/components/markdown/StepContainerPreToolbar/InsertButton.tsx b/gui/src/components/StepContainer/StepContainerPreToolbar/InsertButton.tsx similarity index 100% rename from gui/src/components/markdown/StepContainerPreToolbar/InsertButton.tsx rename to gui/src/components/StepContainer/StepContainerPreToolbar/InsertButton.tsx diff --git a/gui/src/components/markdown/StepContainerPreToolbar/RunInTerminalButton.tsx b/gui/src/components/StepContainer/StepContainerPreToolbar/RunInTerminalButton.tsx similarity index 100% rename from gui/src/components/markdown/StepContainerPreToolbar/RunInTerminalButton.tsx rename to gui/src/components/StepContainer/StepContainerPreToolbar/RunInTerminalButton.tsx diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/StepContainer/StepContainerPreToolbar/StepContainerPreToolbar.tsx similarity index 99% rename from gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx rename to gui/src/components/StepContainer/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 0397603f3..bca64e6c7 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/StepContainer/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -15,7 +15,7 @@ import { selectIsInEditMode, } from "../../../redux/slices/sessionSlice"; import { getFontSize } from "../../../util"; -import { isTerminalCodeBlock } from "../utils"; +import { isTerminalCodeBlock } from "../StyledMarkdownPreview/utils"; import ApplyActions from "./ApplyActions"; import CopyButton from "./CopyButton"; import { FileInfo } from "./FileInfo"; diff --git a/gui/src/components/markdown/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx b/gui/src/components/StepContainer/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx similarity index 100% rename from gui/src/components/markdown/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx rename to gui/src/components/StepContainer/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx diff --git a/gui/src/components/markdown/StepContainerPreToolbar/index.ts b/gui/src/components/StepContainer/StepContainerPreToolbar/index.ts similarity index 100% rename from gui/src/components/markdown/StepContainerPreToolbar/index.ts rename to gui/src/components/StepContainer/StepContainerPreToolbar/index.ts diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview.tsx similarity index 94% rename from gui/src/components/markdown/StyledMarkdownPreview.tsx rename to gui/src/components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview.tsx index 3f7c82bca..0353935b6 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview.tsx @@ -12,19 +12,19 @@ import { vscBackground, vscEditorBackground, vscForeground, -} from ".."; -import useUpdatingRef from "../../hooks/useUpdatingRef"; -import { useAppSelector } from "../../redux/hooks"; -import { selectUIConfig } from "../../redux/slices/configSlice"; -import { getContextItemsFromHistory } from "../../redux/thunks/updateFileSymbols"; -import { getFontSize } from "../../util"; -import { ToolTip } from "../gui/Tooltip"; -import FilenameLink from "./FilenameLink"; +} from "../.."; +import useUpdatingRef from "../../../hooks/useUpdatingRef"; +import { useAppSelector } from "../../../redux/hooks"; +import { selectUIConfig } from "../../../redux/slices/configSlice"; +import { getContextItemsFromHistory } from "../../../redux/thunks/updateFileSymbols"; +import { getFontSize } from "../../../util"; +import { ToolTip } from "../../gui/Tooltip"; +import FilenameLink from "../FilenameLink"; +import StepContainerPreToolbar from "../StepContainerPreToolbar"; +import SymbolLink from "../SymbolLink"; +import { SyntaxHighlightedPre } from "../SyntaxHighlightedPre"; import "./katex.css"; import "./markdown.css"; -import StepContainerPreToolbar from "./StepContainerPreToolbar"; -import SymbolLink from "./SymbolLink"; -import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre"; import { isSymbolNotRif, matchCodeToSymbolOrFile } from "./utils"; import { fixDoubleDollarNewLineLatex } from "./utils/fixDoubleDollarLatex"; import { patchNestedMarkdown } from "./utils/patchNestedMarkdown"; diff --git a/gui/src/components/markdown/katex.css b/gui/src/components/StepContainer/StyledMarkdownPreview/katex.css similarity index 100% rename from gui/src/components/markdown/katex.css rename to gui/src/components/StepContainer/StyledMarkdownPreview/katex.css diff --git a/gui/src/components/markdown/markdown.css b/gui/src/components/StepContainer/StyledMarkdownPreview/markdown.css similarity index 100% rename from gui/src/components/markdown/markdown.css rename to gui/src/components/StepContainer/StyledMarkdownPreview/markdown.css diff --git a/gui/src/components/markdown/utils.ts b/gui/src/components/StepContainer/StyledMarkdownPreview/utils.ts similarity index 94% rename from gui/src/components/markdown/utils.ts rename to gui/src/components/StepContainer/StyledMarkdownPreview/utils.ts index 3961f11d0..8b2af26c8 100644 --- a/gui/src/components/markdown/utils.ts +++ b/gui/src/components/StepContainer/StyledMarkdownPreview/utils.ts @@ -23,10 +23,6 @@ const commonTerminalCommands = [ "bundle", ]; -export function getTerminalCommand(text: string): string { - return text.startsWith("$ ") ? text.slice(2) : text; -} - export function isTerminalCodeBlock( language: string | undefined | null, text: string, diff --git a/gui/src/components/markdown/utils/fixDoubleDollarLatex.ts b/gui/src/components/StepContainer/StyledMarkdownPreview/utils/fixDoubleDollarLatex.ts similarity index 100% rename from gui/src/components/markdown/utils/fixDoubleDollarLatex.ts rename to gui/src/components/StepContainer/StyledMarkdownPreview/utils/fixDoubleDollarLatex.ts diff --git a/gui/src/components/markdown/utils/patchNestedMarkdown.ts b/gui/src/components/StepContainer/StyledMarkdownPreview/utils/patchNestedMarkdown.ts similarity index 100% rename from gui/src/components/markdown/utils/patchNestedMarkdown.ts rename to gui/src/components/StepContainer/StyledMarkdownPreview/utils/patchNestedMarkdown.ts diff --git a/gui/src/components/markdown/utils/remarkTables.tsx b/gui/src/components/StepContainer/StyledMarkdownPreview/utils/remarkTables.tsx similarity index 100% rename from gui/src/components/markdown/utils/remarkTables.tsx rename to gui/src/components/StepContainer/StyledMarkdownPreview/utils/remarkTables.tsx diff --git a/gui/src/components/markdown/SymbolLink.tsx b/gui/src/components/StepContainer/SymbolLink.tsx similarity index 100% rename from gui/src/components/markdown/SymbolLink.tsx rename to gui/src/components/StepContainer/SymbolLink.tsx diff --git a/gui/src/components/markdown/SyntaxHighlightedPre.tsx b/gui/src/components/StepContainer/SyntaxHighlightedPre.tsx similarity index 100% rename from gui/src/components/markdown/SyntaxHighlightedPre.tsx rename to gui/src/components/StepContainer/SyntaxHighlightedPre.tsx diff --git a/gui/src/components/mainInput/TipTapEditor/extensions/CodeBlock/CodeBlockPreview.tsx b/gui/src/components/mainInput/TipTapEditor/extensions/CodeBlock/CodeBlockPreview.tsx index c414d7f1c..662d6f159 100644 --- a/gui/src/components/mainInput/TipTapEditor/extensions/CodeBlock/CodeBlockPreview.tsx +++ b/gui/src/components/mainInput/TipTapEditor/extensions/CodeBlock/CodeBlockPreview.tsx @@ -6,7 +6,7 @@ import { useContext, useMemo } from "react"; import { vscBadgeBackground } from "../../../.."; import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; import FileIcon from "../../../../FileIcon"; -import StyledMarkdownPreview from "../../../../markdown/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../../../../StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; import { ExpandableToolbarPreview } from "../../components/ExpandableToolbarPreview"; import { NodeViewWrapper } from "../../components/NodeViewWrapper"; diff --git a/gui/src/components/mainInput/belowMainInput/ThinkingBlockPeek.tsx b/gui/src/components/mainInput/belowMainInput/ThinkingBlockPeek.tsx index a89ba2e6a..ba9afd6f8 100644 --- a/gui/src/components/mainInput/belowMainInput/ThinkingBlockPeek.tsx +++ b/gui/src/components/mainInput/belowMainInput/ThinkingBlockPeek.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from "react"; import styled from "styled-components"; import { defaultBorderRadius, lightGray, vscBackground } from "../.."; import { getFontSize } from "../../../util"; -import StyledMarkdownPreview from "../../markdown/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../../StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; const SpoilerButton = styled.div` background-color: ${vscBackground}; diff --git a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx index e3b0002e1..f766d28b6 100644 --- a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx @@ -1,5 +1,5 @@ import { getMarkdownLanguageTagForFile } from "core/util"; -import StyledMarkdownPreview from "../../../components/markdown/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../../../components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; interface CreateFileToolCallProps { relativeFilepath: string; diff --git a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx index f1592a7fe..70003b414 100644 --- a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx @@ -1,7 +1,7 @@ import { getMarkdownLanguageTagForFile } from "core/util"; import { useMemo } from "react"; -import StyledMarkdownPreview from "../../../components/markdown/StyledMarkdownPreview"; import AcceptRejectAllButtons from "../../../components/StepContainer/AcceptRejectAllButtons"; +import StyledMarkdownPreview from "../../../components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; import { useAppSelector } from "../../../redux/hooks"; type EditToolCallProps = { diff --git a/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx b/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx index 4bb104cce..f4c0141aa 100644 --- a/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx +++ b/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx @@ -1,5 +1,5 @@ import { ToolCallState } from "core"; -import StyledMarkdownPreview from "../../../components/markdown/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../../../components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; interface RunTerminalCommandToolCallProps { command: string; From 81c313a81f7cc0ec504bdf9acf3cc179ca667c4c Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 11 Apr 2025 21:21:53 -0700 Subject: [PATCH 04/20] Update ApplyActions.tsx --- .../markdown/StepContainerPreToolbar/ApplyActions.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx index 6a775c16b..5a49f6656 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx @@ -4,7 +4,7 @@ import { useEffect, useState } from "react"; import { lightGray, vscForeground } from "../.."; import { getMetaKeyLabel } from "../../../util"; import Spinner from "../../gui/Spinner"; -import { ToolbarButtonWithTooltip } from "./ToolbarButtonWithTooltip"; +import { ToolbarButtonWithTooltip } from "../../StepContainer/StepContainerPreToolbar/ToolbarButtonWithTooltip"; interface ApplyActionsProps { disableManualApply?: boolean; From d196ae8124315050b54f147487ca496016f775a1 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Sat, 12 Apr 2025 19:03:24 -0700 Subject: [PATCH 05/20] Delete ApplyActions.tsx --- .../StepContainerPreToolbar/ApplyActions.tsx | 107 ------------------ 1 file changed, 107 deletions(-) delete mode 100644 gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx diff --git a/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx deleted file mode 100644 index 5a49f6656..000000000 --- a/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx +++ /dev/null @@ -1,107 +0,0 @@ -import { CheckIcon, PlayIcon, XMarkIcon } from "@heroicons/react/24/outline"; -import { ApplyState } from "core"; -import { useEffect, useState } from "react"; -import { lightGray, vscForeground } from "../.."; -import { getMetaKeyLabel } from "../../../util"; -import Spinner from "../../gui/Spinner"; -import { ToolbarButtonWithTooltip } from "../../StepContainer/StepContainerPreToolbar/ToolbarButtonWithTooltip"; - -interface ApplyActionsProps { - disableManualApply?: boolean; - applyState?: ApplyState; - onClickAccept: () => void; - onClickReject: () => void; - onClickApply: () => void; -} - -export default function ApplyActions(props: ApplyActionsProps) { - const [hasRejected, setHasRejected] = useState(false); - const [showApplied, setShowApplied] = useState(false); - const isClosed = props.applyState?.status === "closed"; - const isSuccessful = !hasRejected && props.applyState?.numDiffs === 0; - - useEffect(() => { - if (isClosed && isSuccessful) { - setShowApplied(true); - const timer = setTimeout(() => { - setShowApplied(false); - }, 5_000); - return () => clearTimeout(timer); - } - }, [isClosed, isSuccessful]); - - function onClickReject() { - props.onClickReject(); - setHasRejected(true); - } - - const applyButton = (text: string) => ( - - ); - - switch (props.applyState ? props.applyState.status : null) { - case "streaming": - return ( -
- - Applying - - -
- ); - case "done": - return ( -
- - {`${props.applyState?.numDiffs === 1 ? "1 diff" : `${props.applyState?.numDiffs} diffs`}`} - {` remaining`} - - -
- - - - - - - -
-
- ); - case "closed": - if (!hasRejected && props.applyState?.numDiffs === 0) { - if (showApplied) { - return ( - - Applied - - - ); - } - if (props.disableManualApply) { - return null; - } - return applyButton("Reapply"); - } - default: - if (props.disableManualApply) { - return null; - } - return applyButton("Apply"); - } -} From 6504bd55659823c8117d04ddb447f91d9932d086 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Sat, 12 Apr 2025 22:34:15 -0700 Subject: [PATCH 06/20] feat: reintroduce lazy apply for full files --- core/edit/lazy/applyCodeBlock.ts | 44 +++++++++++-------- core/edit/lazy/deterministic.ts | 29 +++++++++--- extensions/vscode/src/apply/ApplyManager.ts | 8 ++-- .../Lump/BlockSettingsTopToolbar.tsx | 4 +- 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/core/edit/lazy/applyCodeBlock.ts b/core/edit/lazy/applyCodeBlock.ts index d2323aca3..b117c7dea 100644 --- a/core/edit/lazy/applyCodeBlock.ts +++ b/core/edit/lazy/applyCodeBlock.ts @@ -2,7 +2,7 @@ import { DiffLine, ILLM } from "../.."; import { generateLines } from "../../diff/util"; import { supportedLanguages } from "../../util/treeSitter"; import { getUriFileExtension } from "../../util/uri"; - +import { deterministicApplyLazyEdit } from "./deterministic"; import { streamLazyApply } from "./streamLazyApply"; import { applyUnifiedDiff, isUnifiedDiffFormat } from "./unifiedDiffApply"; @@ -16,32 +16,40 @@ export async function applyCodeBlock( newFile: string, filename: string, llm: ILLM, -): Promise<[boolean, AsyncGenerator]> { - // This was buggy, removed for now, maybe forever - // if (canUseInstantApply(filename)) { - // const diffLines = await deterministicApplyLazyEdit( - // oldFile, - // newFile, - // filename, - // ); +): Promise<{ + isInstantApply: boolean; + diffLinesGenerator: AsyncGenerator; +}> { + if (canUseInstantApply(filename)) { + const diffLines = await deterministicApplyLazyEdit( + oldFile, + newFile, + filename, + ); - // // Fall back to LLM method if we couldn't apply deterministically - // if (diffLines !== undefined) { - // const diffGenerator = generateLines(diffLines!); - // return [true, diffGenerator]; - // } - // } + if (diffLines !== undefined) { + return { + isInstantApply: true, + diffLinesGenerator: generateLines(diffLines!), + }; + } + } // If the code block is a diff if (isUnifiedDiffFormat(newFile)) { try { const diffLines = applyUnifiedDiff(oldFile, newFile); - const diffGenerator = generateLines(diffLines!); - return [true, diffGenerator]; + return { + isInstantApply: true, + diffLinesGenerator: generateLines(diffLines!), + }; } catch (e) { console.error("Failed to apply unified diff", e); } } - return [false, streamLazyApply(oldFile, filename, newFile, llm)]; + return { + isInstantApply: false, + diffLinesGenerator: streamLazyApply(oldFile, filename, newFile, llm), + }; } diff --git a/core/edit/lazy/deterministic.ts b/core/edit/lazy/deterministic.ts index 1e3a0ec4e..b4c6611c9 100644 --- a/core/edit/lazy/deterministic.ts +++ b/core/edit/lazy/deterministic.ts @@ -15,6 +15,19 @@ type AstReplacements = Array<{ replacementNodes: Parser.SyntaxNode[]; }>; +/** + * Using this as a flag to slowly reintroduce lazy applies. + * With this set, we will only attempt to deterministically apply + * when there are no lazy blocks and then just replace the whole file, + * and otherwise never use instant apply + */ +const ONLY_FULL_FILE_REWRITE = true; + +const LAZY_COMMENT_REGEX = /\.{3}\s*(.+?)\s*\.{3}/; +export function isLazyText(text: string): boolean { + return LAZY_COMMENT_REGEX.test(text); +} + function reconstructNewFile( oldFile: string, newFile: string, @@ -135,6 +148,15 @@ export async function deterministicApplyLazyEdit( let newTree = parser.parse(newLazyFile); let reconstructedNewFile: string | undefined = undefined; + // See comments on `ONLY_FULL_FILE_REWRITE` for context + if (ONLY_FULL_FILE_REWRITE) { + if (!isLazyText(newTree.rootNode.text)) { + return myersDiff(oldFile, newLazyFile); + } else { + return undefined; + } + } + // If there is no lazy block anywhere, we add our own to the outsides // so that large chunks of the file don't get removed if (!findInAst(newTree.rootNode, isLazyBlock)) { @@ -198,11 +220,6 @@ export async function deterministicApplyLazyEdit( return diff; } -const LAZY_COMMENT_REGEX = /\.{3}\s*(.+?)\s*\.{3}/; -export function isLazyLine(text: string): boolean { - return LAZY_COMMENT_REGEX.test(text); -} - function isLazyBlock(node: Parser.SyntaxNode): boolean { // Special case for "{/* ... existing code ... */}" if ( @@ -213,7 +230,7 @@ function isLazyBlock(node: Parser.SyntaxNode): boolean { return true; } - return node.type.includes("comment") && isLazyLine(node.text); + return node.type.includes("comment") && isLazyText(node.text); } function stringsWithinLevDistThreshold( diff --git a/extensions/vscode/src/apply/ApplyManager.ts b/extensions/vscode/src/apply/ApplyManager.ts index 4942cb0c1..2741fea0b 100644 --- a/extensions/vscode/src/apply/ApplyManager.ts +++ b/extensions/vscode/src/apply/ApplyManager.ts @@ -116,17 +116,17 @@ export class ApplyManager { return; } - const [instant, diffLines] = await applyCodeBlock( + const { isInstantApply, diffLinesGenerator } = await applyCodeBlock( editor.document.getText(), text, getUriPathBasename(editor.document.uri.toString()), llm, ); - if (instant) { + if (isInstantApply) { await this.verticalDiffManager.streamDiffLines( - diffLines, - instant, + diffLinesGenerator, + isInstantApply, streamId, toolCallId, ); diff --git a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx index 4ecf299b7..f7464e793 100644 --- a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx +++ b/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx @@ -116,7 +116,7 @@ export function BlockSettingsTopToolbar() { ); return ( -
+
-
+
From acaa04e0241c33233bd22d0ca8e6f51bf7568177 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Sun, 13 Apr 2025 21:51:39 -0700 Subject: [PATCH 07/20] Update apply.mdx --- docs/docs/customize/model-roles/apply.mdx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/docs/customize/model-roles/apply.mdx b/docs/docs/customize/model-roles/apply.mdx index 78574b096..040cdaa2e 100644 --- a/docs/docs/customize/model-roles/apply.mdx +++ b/docs/docs/customize/model-roles/apply.mdx @@ -10,9 +10,15 @@ import Tabs from "@theme/Tabs"; When editing code, Chat and Edit model output often doesn't clearly align with existing code. A model with the `apply` role is used to generate a more precise diff to apply changes to a file. -Generally speaking, models proficient in chat and edit can also be used for applying code. +## Recommended Apply models -Explore apply models in [the hub](https://hub.continue.dev/explore/models?roles=apply). +We recommend [Relace's Instant Apply model](https://hub.continue.dev/relace/instant-apply) for the fastest Apply experience. You can get an API key [here](https://app.relace.ai/settings/api-keys). + +However, most Chat models can also be used for applying code changes. We recommend smaller/cheaper models for the task, such as Claude 3.5 Haiku. + +:::info +Explore all apply models in [the Hub](https://hub.continue.dev/explore/models?roles=apply) +::: ## Prompt templating From 6852ed148631aadd8f1813e5c507a4a7e2b6d297 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 10:07:29 -0700 Subject: [PATCH 08/20] Update deterministic.test.ts --- core/edit/lazy/deterministic.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/edit/lazy/deterministic.test.ts b/core/edit/lazy/deterministic.test.ts index 7590e5025..33140a0a5 100644 --- a/core/edit/lazy/deterministic.test.ts +++ b/core/edit/lazy/deterministic.test.ts @@ -83,7 +83,8 @@ async function expectDiff(file: string) { ); } -describe("deterministicApplyLazyEdit(", () => { +// Skipped while we have `ONLY_FULL_FILE_REWRITE` enabled +describe.skip("deterministicApplyLazyEdit(", () => { test("no changes", async () => { const file = dedent` function test() { From b0492ddfee2e6050d833d4ad07a942dbdd830c55 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 10:49:10 -0700 Subject: [PATCH 09/20] feat: more moving around --- .../AcceptRejectAllButtons.tsx | 10 ++++----- .../CodeToEditCard/CodeToEditListItem.tsx | 2 +- .../{StepContainer => }/FeedbackButtons.tsx | 10 ++++----- .../components/StepContainer/EditActions.tsx | 6 ++--- .../components/StepContainer/Reasoning.tsx | 2 +- .../StepContainer/ResponseActions.tsx | 6 ++--- .../StepContainer/StepContainer.tsx | 2 +- .../StepContainerPreToolbar/index.ts | 1 - .../FilenameLink.tsx | 0 .../StepContainerPreToolbar/ApplyActions.tsx | 0 .../StepContainerPreToolbar/CopyButton.tsx | 0 .../StepContainerPreToolbar/FileInfo.tsx | 0 .../GeneratingCodeLoader.tsx | 0 .../StepContainerPreToolbar/InsertButton.tsx | 0 .../RunInTerminalButton.tsx | 0 .../StepContainerPreToolbar.tsx | 4 ++-- .../ToolbarButtonWithTooltip.tsx | 2 +- .../StepContainerPreToolbar/index.ts | 1 + .../SyntaxHighlightedPre.tsx | 0 .../index.tsx} | 22 +++++++++---------- .../StyledMarkdownPreview/katex.css | 0 .../StyledMarkdownPreview/markdown.css | 0 .../StyledMarkdownPreview/utils.ts | 0 .../utils/fixDoubleDollarLatex.ts | 0 .../utils/patchNestedMarkdown.ts | 0 .../utils/remarkTables.tsx | 0 .../extensions/CodeBlock/CodeBlockPreview.tsx | 2 +- .../belowMainInput/ThinkingBlockPeek.tsx | 2 +- gui/src/pages/gui/Chat.tsx | 2 +- gui/src/pages/gui/ToolCallDiv/CreateFile.tsx | 2 +- gui/src/pages/gui/ToolCallDiv/EditFile.tsx | 4 ++-- .../gui/ToolCallDiv/RunTerminalCommand.tsx | 2 +- 32 files changed, 41 insertions(+), 41 deletions(-) rename gui/src/components/{StepContainer => }/AcceptRejectAllButtons.tsx (90%) rename gui/src/components/{StepContainer => }/FeedbackButtons.tsx (86%) delete mode 100644 gui/src/components/StepContainer/StepContainerPreToolbar/index.ts rename gui/src/components/{StepContainer => StyledMarkdownPreview}/FilenameLink.tsx (100%) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/StepContainerPreToolbar/ApplyActions.tsx (100%) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/StepContainerPreToolbar/CopyButton.tsx (100%) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/StepContainerPreToolbar/FileInfo.tsx (100%) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/StepContainerPreToolbar/GeneratingCodeLoader.tsx (100%) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/StepContainerPreToolbar/InsertButton.tsx (100%) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/StepContainerPreToolbar/RunInTerminalButton.tsx (100%) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/StepContainerPreToolbar/StepContainerPreToolbar.tsx (98%) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx (100%) create mode 100644 gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.ts rename gui/src/components/{StepContainer => StyledMarkdownPreview}/SyntaxHighlightedPre.tsx (100%) rename gui/src/components/{StepContainer/StyledMarkdownPreview/StyledMarkdownPreview.tsx => StyledMarkdownPreview/index.tsx} (94%) rename gui/src/components/{StepContainer => }/StyledMarkdownPreview/katex.css (100%) rename gui/src/components/{StepContainer => }/StyledMarkdownPreview/markdown.css (100%) rename gui/src/components/{StepContainer => }/StyledMarkdownPreview/utils.ts (100%) rename gui/src/components/{StepContainer => }/StyledMarkdownPreview/utils/fixDoubleDollarLatex.ts (100%) rename gui/src/components/{StepContainer => }/StyledMarkdownPreview/utils/patchNestedMarkdown.ts (100%) rename gui/src/components/{StepContainer => }/StyledMarkdownPreview/utils/remarkTables.tsx (100%) diff --git a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx b/gui/src/components/AcceptRejectAllButtons.tsx similarity index 90% rename from gui/src/components/StepContainer/AcceptRejectAllButtons.tsx rename to gui/src/components/AcceptRejectAllButtons.tsx index 8d2e59dd3..7a9c28062 100644 --- a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx +++ b/gui/src/components/AcceptRejectAllButtons.tsx @@ -1,10 +1,10 @@ -import { useContext } from "react"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { ApplyState } from "core"; -import { getMetaKeyLabel } from "../../util"; -import { useAppSelector } from "../../redux/hooks"; -import { selectIsSingleRangeEditOrInsertion } from "../../redux/slices/sessionSlice"; +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 { pendingApplyStates: ApplyState[]; diff --git a/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx b/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx index c70d2a5ef..9651ec235 100644 --- a/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx +++ b/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx @@ -12,7 +12,7 @@ import { import { useState } from "react"; import styled from "styled-components"; import FileIcon from "../FileIcon"; -import StyledMarkdownPreview from "../StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../StyledMarkdownPreview"; export interface CodeToEditListItemProps { code: CodeToEdit; diff --git a/gui/src/components/StepContainer/FeedbackButtons.tsx b/gui/src/components/FeedbackButtons.tsx similarity index 86% rename from gui/src/components/StepContainer/FeedbackButtons.tsx rename to gui/src/components/FeedbackButtons.tsx index 4ef09a833..6ad0992df 100644 --- a/gui/src/components/StepContainer/FeedbackButtons.tsx +++ b/gui/src/components/FeedbackButtons.tsx @@ -1,12 +1,12 @@ import { - HandThumbUpIcon, HandThumbDownIcon, + HandThumbUpIcon, } from "@heroicons/react/24/outline"; -import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; import { ChatHistoryItem } from "core"; -import { useState, useContext } from "react"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useAppSelector } from "../../redux/hooks"; +import { useContext, useState } from "react"; +import { IdeMessengerContext } from "../context/IdeMessenger"; +import { useAppSelector } from "../redux/hooks"; +import HeaderButtonWithToolTip from "./gui/HeaderButtonWithToolTip"; export interface FeedbackButtonsProps { item: ChatHistoryItem; diff --git a/gui/src/components/StepContainer/EditActions.tsx b/gui/src/components/StepContainer/EditActions.tsx index d40ed72b9..08a61e2e3 100644 --- a/gui/src/components/StepContainer/EditActions.tsx +++ b/gui/src/components/StepContainer/EditActions.tsx @@ -1,12 +1,12 @@ import { ChatHistoryItem } from "core"; -import AcceptRejectAllButtons from "./AcceptRejectAllButtons"; -import FeedbackButtons from "./FeedbackButtons"; import { renderChatMessage } from "core/util/messageContent"; -import { CopyIconButton } from "../gui/CopyIconButton"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { exitEditMode } from "../../redux/thunks/exitEditMode"; import { loadLastSession } from "../../redux/thunks/session"; +import AcceptRejectAllButtons from "../AcceptRejectAllButtons"; +import FeedbackButtons from "../FeedbackButtons"; +import { CopyIconButton } from "../gui/CopyIconButton"; export interface EditActionsProps { index: number; diff --git a/gui/src/components/StepContainer/Reasoning.tsx b/gui/src/components/StepContainer/Reasoning.tsx index b1c51cd81..b2c7ec19e 100644 --- a/gui/src/components/StepContainer/Reasoning.tsx +++ b/gui/src/components/StepContainer/Reasoning.tsx @@ -10,7 +10,7 @@ import { vscQuickInputBackground, } from ".."; import { getFontSize } from "../../util"; -import StyledMarkdownPreview from "./StyledMarkdownPreview/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../StyledMarkdownPreview"; interface ReasoningProps { item: ChatHistoryItem; diff --git a/gui/src/components/StepContainer/ResponseActions.tsx b/gui/src/components/StepContainer/ResponseActions.tsx index f016b3474..dce39ea6f 100644 --- a/gui/src/components/StepContainer/ResponseActions.tsx +++ b/gui/src/components/StepContainer/ResponseActions.tsx @@ -1,12 +1,12 @@ 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"; import EditActions from "./EditActions"; -import FeedbackButtons from "./FeedbackButtons"; -import { useAppSelector } from "../../redux/hooks"; -import { selectIsInEditMode } from "../../redux/slices/sessionSlice"; export interface ResponseActionsProps { isTruncated: boolean; diff --git a/gui/src/components/StepContainer/StepContainer.tsx b/gui/src/components/StepContainer/StepContainer.tsx index 11bfab85c..aac4b877a 100644 --- a/gui/src/components/StepContainer/StepContainer.tsx +++ b/gui/src/components/StepContainer/StepContainer.tsx @@ -8,9 +8,9 @@ import { useAppSelector } from "../../redux/hooks"; import { selectUIConfig } from "../../redux/slices/configSlice"; import { deleteMessage } from "../../redux/slices/sessionSlice"; import { getFontSize } from "../../util"; +import StyledMarkdownPreview from "../StyledMarkdownPreview"; import Reasoning from "./Reasoning"; import ResponseActions from "./ResponseActions"; -import StyledMarkdownPreview from "./StyledMarkdownPreview/StyledMarkdownPreview"; import ThinkingIndicator from "./ThinkingIndicator"; interface StepContainerProps { diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/index.ts b/gui/src/components/StepContainer/StepContainerPreToolbar/index.ts deleted file mode 100644 index 6e974689a..000000000 --- a/gui/src/components/StepContainer/StepContainerPreToolbar/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./StepContainerPreToolbar"; diff --git a/gui/src/components/StepContainer/FilenameLink.tsx b/gui/src/components/StyledMarkdownPreview/FilenameLink.tsx similarity index 100% rename from gui/src/components/StepContainer/FilenameLink.tsx rename to gui/src/components/StyledMarkdownPreview/FilenameLink.tsx diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx similarity index 100% rename from gui/src/components/StepContainer/StepContainerPreToolbar/ApplyActions.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/CopyButton.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/CopyButton.tsx similarity index 100% rename from gui/src/components/StepContainer/StepContainerPreToolbar/CopyButton.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/CopyButton.tsx diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/FileInfo.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/FileInfo.tsx similarity index 100% rename from gui/src/components/StepContainer/StepContainerPreToolbar/FileInfo.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/FileInfo.tsx diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/GeneratingCodeLoader.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx similarity index 100% rename from gui/src/components/StepContainer/StepContainerPreToolbar/GeneratingCodeLoader.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/InsertButton.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/InsertButton.tsx similarity index 100% rename from gui/src/components/StepContainer/StepContainerPreToolbar/InsertButton.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/InsertButton.tsx diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/RunInTerminalButton.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx similarity index 100% rename from gui/src/components/StepContainer/StepContainerPreToolbar/RunInTerminalButton.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx similarity index 98% rename from gui/src/components/StepContainer/StepContainerPreToolbar/StepContainerPreToolbar.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx index bca64e6c7..6da63b36b 100644 --- a/gui/src/components/StepContainer/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -15,7 +15,7 @@ import { selectIsInEditMode, } from "../../../redux/slices/sessionSlice"; import { getFontSize } from "../../../util"; -import { isTerminalCodeBlock } from "../StyledMarkdownPreview/utils"; +import { isTerminalCodeBlock } from "../utils"; import ApplyActions from "./ApplyActions"; import CopyButton from "./CopyButton"; import { FileInfo } from "./FileInfo"; @@ -59,7 +59,7 @@ export interface StepContainerPreToolbarProps { disableManualApply?: boolean; } -export default function StepContainerPreToolbar({ +export function StepContainerPreToolbar({ codeBlockContent, language, relativeFilepath, diff --git a/gui/src/components/StepContainer/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx similarity index 100% rename from gui/src/components/StepContainer/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx index 9ffed883c..b60691d7b 100644 --- a/gui/src/components/StepContainer/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ToolbarButtonWithTooltip.tsx @@ -1,7 +1,7 @@ import { ReactNode, useMemo } from "react"; import { Tooltip } from "react-tooltip"; -import { lightGray, vscForeground } from "../.."; import styled from "styled-components"; +import { lightGray, vscForeground } from "../.."; import { getFontSize } from "../../../util"; export const ToolbarButton = styled.button` diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.ts b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.ts new file mode 100644 index 000000000..ee0cda3f4 --- /dev/null +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.ts @@ -0,0 +1 @@ +export * from "./StepContainerPreToolbar"; diff --git a/gui/src/components/StepContainer/SyntaxHighlightedPre.tsx b/gui/src/components/StyledMarkdownPreview/SyntaxHighlightedPre.tsx similarity index 100% rename from gui/src/components/StepContainer/SyntaxHighlightedPre.tsx rename to gui/src/components/StyledMarkdownPreview/SyntaxHighlightedPre.tsx diff --git a/gui/src/components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview.tsx b/gui/src/components/StyledMarkdownPreview/index.tsx similarity index 94% rename from gui/src/components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview.tsx rename to gui/src/components/StyledMarkdownPreview/index.tsx index 0353935b6..f80b34e38 100644 --- a/gui/src/components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview.tsx +++ b/gui/src/components/StyledMarkdownPreview/index.tsx @@ -12,19 +12,19 @@ import { vscBackground, vscEditorBackground, vscForeground, -} from "../.."; -import useUpdatingRef from "../../../hooks/useUpdatingRef"; -import { useAppSelector } from "../../../redux/hooks"; -import { selectUIConfig } from "../../../redux/slices/configSlice"; -import { getContextItemsFromHistory } from "../../../redux/thunks/updateFileSymbols"; -import { getFontSize } from "../../../util"; -import { ToolTip } from "../../gui/Tooltip"; -import FilenameLink from "../FilenameLink"; -import StepContainerPreToolbar from "../StepContainerPreToolbar"; -import SymbolLink from "../SymbolLink"; -import { SyntaxHighlightedPre } from "../SyntaxHighlightedPre"; +} from ".."; +import useUpdatingRef from "../../hooks/useUpdatingRef"; +import { useAppSelector } from "../../redux/hooks"; +import { selectUIConfig } from "../../redux/slices/configSlice"; +import { getContextItemsFromHistory } from "../../redux/thunks/updateFileSymbols"; +import { getFontSize } from "../../util"; +import { ToolTip } from "../gui/Tooltip"; +import SymbolLink from "../StepContainer/SymbolLink"; +import FilenameLink from "./FilenameLink"; import "./katex.css"; import "./markdown.css"; +import { StepContainerPreToolbar } from "./StepContainerPreToolbar"; +import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre"; import { isSymbolNotRif, matchCodeToSymbolOrFile } from "./utils"; import { fixDoubleDollarNewLineLatex } from "./utils/fixDoubleDollarLatex"; import { patchNestedMarkdown } from "./utils/patchNestedMarkdown"; diff --git a/gui/src/components/StepContainer/StyledMarkdownPreview/katex.css b/gui/src/components/StyledMarkdownPreview/katex.css similarity index 100% rename from gui/src/components/StepContainer/StyledMarkdownPreview/katex.css rename to gui/src/components/StyledMarkdownPreview/katex.css diff --git a/gui/src/components/StepContainer/StyledMarkdownPreview/markdown.css b/gui/src/components/StyledMarkdownPreview/markdown.css similarity index 100% rename from gui/src/components/StepContainer/StyledMarkdownPreview/markdown.css rename to gui/src/components/StyledMarkdownPreview/markdown.css diff --git a/gui/src/components/StepContainer/StyledMarkdownPreview/utils.ts b/gui/src/components/StyledMarkdownPreview/utils.ts similarity index 100% rename from gui/src/components/StepContainer/StyledMarkdownPreview/utils.ts rename to gui/src/components/StyledMarkdownPreview/utils.ts diff --git a/gui/src/components/StepContainer/StyledMarkdownPreview/utils/fixDoubleDollarLatex.ts b/gui/src/components/StyledMarkdownPreview/utils/fixDoubleDollarLatex.ts similarity index 100% rename from gui/src/components/StepContainer/StyledMarkdownPreview/utils/fixDoubleDollarLatex.ts rename to gui/src/components/StyledMarkdownPreview/utils/fixDoubleDollarLatex.ts diff --git a/gui/src/components/StepContainer/StyledMarkdownPreview/utils/patchNestedMarkdown.ts b/gui/src/components/StyledMarkdownPreview/utils/patchNestedMarkdown.ts similarity index 100% rename from gui/src/components/StepContainer/StyledMarkdownPreview/utils/patchNestedMarkdown.ts rename to gui/src/components/StyledMarkdownPreview/utils/patchNestedMarkdown.ts diff --git a/gui/src/components/StepContainer/StyledMarkdownPreview/utils/remarkTables.tsx b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx similarity index 100% rename from gui/src/components/StepContainer/StyledMarkdownPreview/utils/remarkTables.tsx rename to gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx diff --git a/gui/src/components/mainInput/TipTapEditor/extensions/CodeBlock/CodeBlockPreview.tsx b/gui/src/components/mainInput/TipTapEditor/extensions/CodeBlock/CodeBlockPreview.tsx index 662d6f159..8055e7fa9 100644 --- a/gui/src/components/mainInput/TipTapEditor/extensions/CodeBlock/CodeBlockPreview.tsx +++ b/gui/src/components/mainInput/TipTapEditor/extensions/CodeBlock/CodeBlockPreview.tsx @@ -6,7 +6,7 @@ import { useContext, useMemo } from "react"; import { vscBadgeBackground } from "../../../.."; import { IdeMessengerContext } from "../../../../../context/IdeMessenger"; import FileIcon from "../../../../FileIcon"; -import StyledMarkdownPreview from "../../../../StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../../../../StyledMarkdownPreview"; import { ExpandableToolbarPreview } from "../../components/ExpandableToolbarPreview"; import { NodeViewWrapper } from "../../components/NodeViewWrapper"; diff --git a/gui/src/components/mainInput/belowMainInput/ThinkingBlockPeek.tsx b/gui/src/components/mainInput/belowMainInput/ThinkingBlockPeek.tsx index ba9afd6f8..40e3c8d2b 100644 --- a/gui/src/components/mainInput/belowMainInput/ThinkingBlockPeek.tsx +++ b/gui/src/components/mainInput/belowMainInput/ThinkingBlockPeek.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from "react"; import styled from "styled-components"; import { defaultBorderRadius, lightGray, vscBackground } from "../.."; import { getFontSize } from "../../../util"; -import StyledMarkdownPreview from "../../StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../../StyledMarkdownPreview"; const SpoilerButton = styled.div` background-color: ${vscBackground}; diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 40db6fd8c..751398410 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -13,6 +13,7 @@ import { useCallback, useContext, useEffect, useRef, useState } from "react"; import { ErrorBoundary } from "react-error-boundary"; import styled from "styled-components"; import { Button, lightGray, vscBackground } from "../../components"; +import AcceptRejectAllButtons from "../../components/AcceptRejectAllButtons"; import CodeToEditCard from "../../components/CodeToEditCard"; import FeedbackDialog from "../../components/dialogs/FeedbackDialog"; import FreeTrialOverDialog from "../../components/dialogs/FreeTrialOverDialog"; @@ -24,7 +25,6 @@ import ContinueInputBox from "../../components/mainInput/ContinueInputBox"; import { resolveEditorContent } from "../../components/mainInput/TipTapEditor/utils"; import { useOnboardingCard } from "../../components/OnboardingCard"; import StepContainer from "../../components/StepContainer"; -import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectAllButtons"; import { TabBar } from "../../components/TabBar/TabBar"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useWebviewListener } from "../../hooks/useWebviewListener"; diff --git a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx index f766d28b6..7e50b7305 100644 --- a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx @@ -1,5 +1,5 @@ import { getMarkdownLanguageTagForFile } from "core/util"; -import StyledMarkdownPreview from "../../../components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; interface CreateFileToolCallProps { relativeFilepath: string; diff --git a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx index 70003b414..304dcb4c7 100644 --- a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx @@ -1,7 +1,7 @@ import { getMarkdownLanguageTagForFile } from "core/util"; import { useMemo } from "react"; -import AcceptRejectAllButtons from "../../../components/StepContainer/AcceptRejectAllButtons"; -import StyledMarkdownPreview from "../../../components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; +import AcceptRejectAllButtons from "../../../components/AcceptRejectAllButtons"; +import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; import { useAppSelector } from "../../../redux/hooks"; type EditToolCallProps = { diff --git a/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx b/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx index f4c0141aa..e8c9772a9 100644 --- a/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx +++ b/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx @@ -1,5 +1,5 @@ import { ToolCallState } from "core"; -import StyledMarkdownPreview from "../../../components/StepContainer/StyledMarkdownPreview/StyledMarkdownPreview"; +import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; interface RunTerminalCommandToolCallProps { command: string; From e3bbd6b7cfa04183f7a60470a55e4a2618083a21 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 10:51:25 -0700 Subject: [PATCH 10/20] feat: move SymbolLink --- .../{StepContainer => StyledMarkdownPreview}/SymbolLink.tsx | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename gui/src/components/{StepContainer => StyledMarkdownPreview}/SymbolLink.tsx (100%) diff --git a/gui/src/components/StepContainer/SymbolLink.tsx b/gui/src/components/StyledMarkdownPreview/SymbolLink.tsx similarity index 100% rename from gui/src/components/StepContainer/SymbolLink.tsx rename to gui/src/components/StyledMarkdownPreview/SymbolLink.tsx From b5256376cfff2eb5ac7470bfcaa12f36f77b3940 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 10:52:08 -0700 Subject: [PATCH 11/20] Update index.tsx --- gui/src/components/StyledMarkdownPreview/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/components/StyledMarkdownPreview/index.tsx b/gui/src/components/StyledMarkdownPreview/index.tsx index f80b34e38..40494ee6c 100644 --- a/gui/src/components/StyledMarkdownPreview/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/index.tsx @@ -19,11 +19,11 @@ import { selectUIConfig } from "../../redux/slices/configSlice"; import { getContextItemsFromHistory } from "../../redux/thunks/updateFileSymbols"; import { getFontSize } from "../../util"; import { ToolTip } from "../gui/Tooltip"; -import SymbolLink from "../StepContainer/SymbolLink"; import FilenameLink from "./FilenameLink"; import "./katex.css"; import "./markdown.css"; import { StepContainerPreToolbar } from "./StepContainerPreToolbar"; +import SymbolLink from "./SymbolLink"; import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre"; import { isSymbolNotRif, matchCodeToSymbolOrFile } from "./utils"; import { fixDoubleDollarNewLineLatex } from "./utils/fixDoubleDollarLatex"; From a5619e29c8a0230f578c092c028c7cc6f3066afb Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 10:54:27 -0700 Subject: [PATCH 12/20] feat: unskip tests --- .continue/rules/rules.yaml | 6 +++++ core/edit/lazy/applyCodeBlock.ts | 9 ++++---- core/edit/lazy/deterministic.test.ts | 8 +++---- core/edit/lazy/deterministic.ts | 33 +++++++++++++++------------- 4 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 .continue/rules/rules.yaml diff --git a/.continue/rules/rules.yaml b/.continue/rules/rules.yaml new file mode 100644 index 000000000..a5b63ab33 --- /dev/null +++ b/.continue/rules/rules.yaml @@ -0,0 +1,6 @@ +name: Continue Repo rules +version: 1.0.0 +schema: v1 + +mcpServers: + - uses: continuedev/continue-repo-rules diff --git a/core/edit/lazy/applyCodeBlock.ts b/core/edit/lazy/applyCodeBlock.ts index b117c7dea..c533b34e6 100644 --- a/core/edit/lazy/applyCodeBlock.ts +++ b/core/edit/lazy/applyCodeBlock.ts @@ -13,7 +13,7 @@ function canUseInstantApply(filename: string) { export async function applyCodeBlock( oldFile: string, - newFile: string, + newLazyFile: string, filename: string, llm: ILLM, ): Promise<{ @@ -21,11 +21,12 @@ export async function applyCodeBlock( diffLinesGenerator: AsyncGenerator; }> { if (canUseInstantApply(filename)) { - const diffLines = await deterministicApplyLazyEdit( + const diffLines = await deterministicApplyLazyEdit({ oldFile, - newFile, + newLazyFile, filename, - ); + onlyFullFileRewrite: true, + }); if (diffLines !== undefined) { return { diff --git a/core/edit/lazy/deterministic.test.ts b/core/edit/lazy/deterministic.test.ts index 33140a0a5..728c6d8f9 100644 --- a/core/edit/lazy/deterministic.test.ts +++ b/core/edit/lazy/deterministic.test.ts @@ -21,11 +21,11 @@ async function collectDiffs( ): Promise<{ ourDiffs: DiffLine[]; myersDiffs: any }> { const ourDiffs: DiffLine[] = []; - for (const diffLine of (await deterministicApplyLazyEdit( + for (const diffLine of (await deterministicApplyLazyEdit({ oldFile, - newFile, + newLazyFile: newFile, filename, - )) ?? []) { + })) ?? []) { ourDiffs.push(diffLine); } @@ -84,7 +84,7 @@ async function expectDiff(file: string) { } // Skipped while we have `ONLY_FULL_FILE_REWRITE` enabled -describe.skip("deterministicApplyLazyEdit(", () => { +describe("deterministicApplyLazyEdit(", () => { test("no changes", async () => { const file = dedent` function test() { diff --git a/core/edit/lazy/deterministic.ts b/core/edit/lazy/deterministic.ts index b4c6611c9..947f628e4 100644 --- a/core/edit/lazy/deterministic.ts +++ b/core/edit/lazy/deterministic.ts @@ -15,14 +15,6 @@ type AstReplacements = Array<{ replacementNodes: Parser.SyntaxNode[]; }>; -/** - * Using this as a flag to slowly reintroduce lazy applies. - * With this set, we will only attempt to deterministically apply - * when there are no lazy blocks and then just replace the whole file, - * and otherwise never use instant apply - */ -const ONLY_FULL_FILE_REWRITE = true; - const LAZY_COMMENT_REGEX = /\.{3}\s*(.+?)\s*\.{3}/; export function isLazyText(text: string): boolean { return LAZY_COMMENT_REGEX.test(text); @@ -134,11 +126,23 @@ function nodeSurroundedInLazyBlocks( } // TODO: If we don't have high confidence, return undefined to fall back to slower methods -export async function deterministicApplyLazyEdit( - oldFile: string, - newLazyFile: string, - filename: string, -): Promise { +export async function deterministicApplyLazyEdit({ + oldFile, + newLazyFile, + filename, + /** + * Using this as a flag to slowly reintroduce lazy applies. + * With this set, we will only attempt to deterministically apply + * when there are no lazy blocks and then just replace the whole file, + * and otherwise never use instant apply + */ + onlyFullFileRewrite = false, +}: { + oldFile: string; + newLazyFile: string; + filename: string; + onlyFullFileRewrite?: boolean; +}): Promise { const parser = await getParserForFile(filename); if (!parser) { return undefined; @@ -148,8 +152,7 @@ export async function deterministicApplyLazyEdit( let newTree = parser.parse(newLazyFile); let reconstructedNewFile: string | undefined = undefined; - // See comments on `ONLY_FULL_FILE_REWRITE` for context - if (ONLY_FULL_FILE_REWRITE) { + if (onlyFullFileRewrite) { if (!isLazyText(newTree.rootNode.text)) { return myersDiff(oldFile, newLazyFile); } else { From d7e91548870c2d8a3299930a3ce531eab3db2f24 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 10:55:23 -0700 Subject: [PATCH 13/20] Delete rules.yaml --- .continue/rules/rules.yaml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .continue/rules/rules.yaml diff --git a/.continue/rules/rules.yaml b/.continue/rules/rules.yaml deleted file mode 100644 index a5b63ab33..000000000 --- a/.continue/rules/rules.yaml +++ /dev/null @@ -1,6 +0,0 @@ -name: Continue Repo rules -version: 1.0.0 -schema: v1 - -mcpServers: - - uses: continuedev/continue-repo-rules From 1c018592d2811cf00cab27c68eea1bcf228928d9 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 11:00:55 -0700 Subject: [PATCH 14/20] Update deterministic.test.ts --- core/edit/lazy/deterministic.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/core/edit/lazy/deterministic.test.ts b/core/edit/lazy/deterministic.test.ts index 728c6d8f9..adfaafa5e 100644 --- a/core/edit/lazy/deterministic.test.ts +++ b/core/edit/lazy/deterministic.test.ts @@ -83,7 +83,6 @@ async function expectDiff(file: string) { ); } -// Skipped while we have `ONLY_FULL_FILE_REWRITE` enabled describe("deterministicApplyLazyEdit(", () => { test("no changes", async () => { const file = dedent` From 2436bc2437e67ee7c45176b4a1b1b159e216a6bf Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 11:05:44 -0700 Subject: [PATCH 15/20] Update applyCodeBlock.ts --- core/edit/lazy/applyCodeBlock.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/edit/lazy/applyCodeBlock.ts b/core/edit/lazy/applyCodeBlock.ts index c533b34e6..8ca9a8154 100644 --- a/core/edit/lazy/applyCodeBlock.ts +++ b/core/edit/lazy/applyCodeBlock.ts @@ -37,9 +37,9 @@ export async function applyCodeBlock( } // If the code block is a diff - if (isUnifiedDiffFormat(newFile)) { + if (isUnifiedDiffFormat(newLazyFile)) { try { - const diffLines = applyUnifiedDiff(oldFile, newFile); + const diffLines = applyUnifiedDiff(oldFile, newLazyFile); return { isInstantApply: true, diffLinesGenerator: generateLines(diffLines!), @@ -51,6 +51,6 @@ export async function applyCodeBlock( return { isInstantApply: false, - diffLinesGenerator: streamLazyApply(oldFile, filename, newFile, llm), + diffLinesGenerator: streamLazyApply(oldFile, filename, newLazyFile, llm), }; } From 268f55b001e880fec92ef87df6be2bdf8fc25649 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 11:34:54 -0700 Subject: [PATCH 16/20] feat: create file button in toolbar --- .../StepContainerPreToolbar/ApplyActions.tsx | 13 ++-- .../StepContainerPreToolbar/CopyButton.tsx | 10 +-- .../CreateFileButton.tsx | 22 ++++++ .../StepContainerPreToolbar/FileInfo.tsx | 41 +++++++--- .../GeneratingCodeLoader.tsx | 4 +- .../StepContainerPreToolbar/InsertButton.tsx | 12 +-- .../RunInTerminalButton.tsx | 8 +- .../StepContainerPreToolbar.tsx | 76 +++++++++++-------- gui/src/hooks/index.ts | 2 + gui/src/hooks/useFileExists.ts | 45 +++++++++++ gui/src/hooks/useIdeMessengerRequest.ts | 37 +++++++++ 11 files changed, 198 insertions(+), 72 deletions(-) create mode 100644 gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/CreateFileButton.tsx create mode 100644 gui/src/hooks/index.ts create mode 100644 gui/src/hooks/useFileExists.ts create mode 100644 gui/src/hooks/useIdeMessengerRequest.ts diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx index 2c4e286c7..e645e68c9 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx @@ -1,7 +1,6 @@ import { CheckIcon, PlayIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { ApplyState } from "core"; import { useEffect, useState } from "react"; -import { lightGray, vscForeground } from "../.."; import { getMetaKeyLabel } from "../../../util"; import Spinner from "../../gui/Spinner"; import { ToolbarButtonWithTooltip } from "./ToolbarButtonWithTooltip"; @@ -14,7 +13,7 @@ interface ApplyActionsProps { onClickApply: () => void; } -export default function ApplyActions(props: ApplyActionsProps) { +export function ApplyActions(props: ApplyActionsProps) { const [hasRejected, setHasRejected] = useState(false); const [showApplied, setShowApplied] = useState(false); const isClosed = props.applyState?.status === "closed"; @@ -37,11 +36,10 @@ export default function ApplyActions(props: ApplyActionsProps) { const applyButton = (text: string) => ( + + ); +} diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/FileInfo.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/FileInfo.tsx index 7b204190b..550d1fd28 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/FileInfo.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/FileInfo.tsx @@ -1,25 +1,42 @@ import { getLastNPathParts } from "core/util/uri"; import FileIcon from "../../FileIcon"; +import { ToolTip } from "../../gui/Tooltip"; export interface FileInfoProps { filepath: string; - onClick: () => void; + onClick?: () => void; range?: string; } +const TOOLTIP_ID = "file-info-tooltip"; + export const FileInfo = ({ filepath, range, onClick }: FileInfoProps) => { return ( -
-
- + <> +
+
+ +
+ + {getLastNPathParts(filepath, 1)} + {range && ` ${range}`} +
- - {getLastNPathParts(filepath, 1)} - {range && ` ${range}`} - -
+ + ); }; diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx index c430c8d62..b730b30e5 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx @@ -5,7 +5,7 @@ export interface GeneratingCodeLoaderProps { codeBlockContent: string; } -export default function GeneratingCodeLoader({ +export function GeneratingCodeLoader({ showLineCount, codeBlockContent, }: GeneratingCodeLoaderProps) { @@ -16,7 +16,7 @@ export default function GeneratingCodeLoader({ : `${numLinesCodeBlock} lines generated`; return ( - + {showLineCount ? linesGeneratedText : "Generating"} diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/InsertButton.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/InsertButton.tsx index 7d56e012b..b8784dd07 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/InsertButton.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/InsertButton.tsx @@ -1,5 +1,4 @@ import { ArrowLeftEndOnRectangleIcon } from "@heroicons/react/24/outline"; -import { lightGray } from "../.."; /** * Button that inserts code at the current cursor position @@ -8,17 +7,14 @@ interface InsertButtonProps { onInsert: () => void; } -export default function InsertButton({ onInsert }: InsertButtonProps) { +export function InsertButton({ onInsert }: InsertButtonProps) { return (
-
- +
+
); diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx index 35bc54349..07da9e7da 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx @@ -7,9 +7,7 @@ interface RunInTerminalButtonProps { command: string; } -export default function RunInTerminalButton({ - command, -}: RunInTerminalButtonProps) { +export function RunInTerminalButton({ command }: RunInTerminalButtonProps) { const ideMessenger = useContext(IdeMessengerContext); function runInTerminal() { @@ -18,7 +16,7 @@ export default function RunInTerminalButton({ return (
<> - Run + Run
diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 6da63b36b..9c0dcad82 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -16,12 +16,13 @@ import { } from "../../../redux/slices/sessionSlice"; import { getFontSize } from "../../../util"; import { isTerminalCodeBlock } from "../utils"; -import ApplyActions from "./ApplyActions"; -import CopyButton from "./CopyButton"; +import { ApplyActions } from "./ApplyActions"; +import { CopyButton } from "./CopyButton"; +import { CreateFileButton } from "./CreateFileButton"; import { FileInfo } from "./FileInfo"; -import GeneratingCodeLoader from "./GeneratingCodeLoader"; -import InsertButton from "./InsertButton"; -import RunInTerminalButton from "./RunInTerminalButton"; +import { GeneratingCodeLoader } from "./GeneratingCodeLoader"; +import { InsertButton } from "./InsertButton"; +import { RunInTerminalButton } from "./RunInTerminalButton"; const TopDiv = styled.div` display: flex; @@ -59,7 +60,7 @@ export interface StepContainerPreToolbarProps { disableManualApply?: boolean; } -export function StepContainerPreToolbar({ +export default function StepContainerPreToolbar({ codeBlockContent, language, relativeFilepath, @@ -77,11 +78,8 @@ export function StepContainerPreToolbar({ expanded ?? (isInEditMode ? false : true), ); - // We store the resolved file URI to ensure we use the same file when - // accepting/rejecting diffs, even if no `relativeFilepath` is provided - const [resolvedFileUri, setResolvedFileUri] = useState( - undefined, - ); + const { fileExists, refreshFileExists } = useFileExists(relativeFilepath); + const nextCodeBlockIndex = useAppSelector( (state) => state.session.codeBlockApplyStates.curIndex, ); @@ -90,16 +88,27 @@ export function StepContainerPreToolbar({ selectApplyStateByStreamId(state, codeBlockStreamId), ); + /** + * In the case where `relativeFilepath` is defined, this will just be the resolved URI + * of `relativeFilepath`. However, if no `relativeFilepath` is defined, then this will + * be the URI of the currently open file at the time the user clicks "Apply". + */ + const [appliedFileUri, setAppliedFileUri] = useState( + undefined, + ); + const isNextCodeBlock = nextCodeBlockIndex === codeBlockIndex; const hasFileExtension = relativeFilepath && /\.[0-9a-z]+$/i.test(relativeFilepath); - const displayFilepath = relativeFilepath ?? resolvedFileUri; + // If we are creating a file, we already render that in the button + // so we don't want to dispaly it twice here + const displayFilepath = relativeFilepath ?? appliedFileUri; - async function getFileUri() { + async function getFileUriToApplyTo() { // If we've already resolved a file URI (from clicking apply), use that - if (resolvedFileUri) { - return resolvedFileUri; + if (appliedFileUri) { + return appliedFileUri; } // If a relative filepath was provided, try to resolve it @@ -120,23 +129,24 @@ export function StepContainerPreToolbar({ } async function onClickApply() { - const fileUri = await getFileUri(); + const fileUri = await getFileUriToApplyTo(); if (!fileUri) { ideMessenger.ide.showToast( "error", "Could not resolve filepath to apply changes", ); - return; } - setResolvedFileUri(fileUri); - + // applyToFile will create the file if it doesn't exist ideMessenger.post("applyToFile", { streamId: codeBlockStreamId, filepath: fileUri, text: codeBlockContent, }); + + setAppliedFileUri(fileUri); + refreshFileExists(); } function onClickInsertAtCursor() { @@ -153,7 +163,7 @@ export function StepContainerPreToolbar({ ); async function handleDiffAction(action: "accept" | "reject") { - const filepath = await getFileUri(); + const filepath = await getFileUriToApplyTo(); if (!filepath) { ideMessenger.ide.showToast( "error", @@ -167,13 +177,13 @@ export function StepContainerPreToolbar({ streamId: codeBlockStreamId, }); - setResolvedFileUri(undefined); + setAppliedFileUri(undefined); } function onClickFilename() { - if (resolvedFileUri) { + if (appliedFileUri) { ideMessenger.post("showFile", { - filepath: resolvedFileUri, + filepath: appliedFileUri, }); } @@ -184,8 +194,8 @@ export function StepContainerPreToolbar({ } } - // We want until there is an extension in the filepath to avoid rendering - // an incomplete filepath + // We wait until there is an extension in the filepath to avoid rendering + // an incomplete filepath if (relativeFilepath && !hasFileExtension) { return children; } @@ -196,7 +206,7 @@ export function StepContainerPreToolbar({
setIsExpanded(!isExpanded)} - className={`h-3.5 w-3.5 flex-shrink-0 cursor-pointer text-gray-400 hover:brightness-125 ${ + className={`text-lightgray h-3.5 w-3.5 flex-shrink-0 cursor-pointer hover:brightness-125 ${ isExpanded ? "rotate-0" : "-rotate-90" }`} /> @@ -204,10 +214,12 @@ export function StepContainerPreToolbar({ ) : ( - {language} + + {language} + )}
@@ -219,11 +231,15 @@ export function StepContainerPreToolbar({ /> ) : ( <> - - +
+ + +
{isTerminalCodeBlock(language, codeBlockContent) ? ( + ) : !fileExists ? ( + ) : ( (null); + + const { result: fileExists, refresh: refreshFileExists } = + useIdeMessengerRequest( + "fileExists", + resolvedUri ? { filepath: resolvedUri } : null, + ); + + useEffect(() => { + async function resolveUri() { + if (!filepath) { + setResolvedUri(null); + return; + } + + try { + const uri = await inferResolvedUriFromRelativePath( + filepath, + ideMessenger.ide, + ); + setResolvedUri(uri); + } catch (err) { + console.error("Failed to resolve URI:", err); + } + } + + resolveUri(); + }, [filepath, ideMessenger.ide]); + + console.log({ fileExists, resolvedUri }); + + return { fileExists, refreshFileExists }; +} diff --git a/gui/src/hooks/useIdeMessengerRequest.ts b/gui/src/hooks/useIdeMessengerRequest.ts new file mode 100644 index 000000000..af2dfb5ad --- /dev/null +++ b/gui/src/hooks/useIdeMessengerRequest.ts @@ -0,0 +1,37 @@ +import type { FromWebviewProtocol } from "core/protocol"; +import type { SuccessWebviewSingleMessage } from "core/protocol/util"; +import { useContext, useEffect, useState } from "react"; +import { IdeMessengerContext } from "../context/IdeMessenger"; + +/** + * Generic hook for making IDE messenger requests with automatic error handling and refresh capability + */ +export function useIdeMessengerRequest( + messageType: T, + data: FromWebviewProtocol[T][0] | null, +) { + const ideMessenger = useContext(IdeMessengerContext); + const [result, setResult] = useState< + SuccessWebviewSingleMessage["content"] | null + >(null); + + async function makeRequest() { + if (!data) { + setResult(null); + return; + } + + const response = await ideMessenger.request(messageType, data); + if (response.status === "success") { + setResult(response.content); + } else { + console.error(`Error in ${messageType} request:`, response.error); + } + } + + useEffect(() => { + makeRequest(); + }, [data, messageType]); + + return { result, refresh: makeRequest }; +} From 979bcb97ec88d91d0ed0bd14fd5b6b7dc4c670ae Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 11:53:30 -0700 Subject: [PATCH 17/20] feat: move `StepContainerPreToolbar` --- .../StyledMarkdownPreview/StepContainerPreToolbar/index.ts | 1 - .../{StepContainerPreToolbar.tsx => index.tsx} | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.ts rename gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/{StepContainerPreToolbar.tsx => index.tsx} (98%) diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.ts b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.ts deleted file mode 100644 index ee0cda3f4..000000000 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./StepContainerPreToolbar"; diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx similarity index 98% rename from gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx rename to gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index 9c0dcad82..72e4279bd 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -8,6 +8,7 @@ import { vscEditorBackground, } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { useFileExists } from "../../../hooks"; import { useWebviewListener } from "../../../hooks/useWebviewListener"; import { useAppSelector } from "../../../redux/hooks"; import { @@ -60,7 +61,7 @@ export interface StepContainerPreToolbarProps { disableManualApply?: boolean; } -export default function StepContainerPreToolbar({ +export function StepContainerPreToolbar({ codeBlockContent, language, relativeFilepath, From 1aef47ebe891187ef65e627f7aff067e89bf3678 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 12:43:04 -0700 Subject: [PATCH 18/20] Update useFileExists.ts --- gui/src/hooks/useFileExists.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/gui/src/hooks/useFileExists.ts b/gui/src/hooks/useFileExists.ts index ea0762b5e..1755a22bd 100644 --- a/gui/src/hooks/useFileExists.ts +++ b/gui/src/hooks/useFileExists.ts @@ -39,7 +39,5 @@ export function useFileExists(filepath?: string) { resolveUri(); }, [filepath, ideMessenger.ide]); - console.log({ fileExists, resolvedUri }); - return { fileExists, refreshFileExists }; } From 2b34ee8c4156c544a3abd9616080f4d8e0b565a1 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 14:05:09 -0700 Subject: [PATCH 19/20] feat: remove useFileExists --- .../StepContainerPreToolbar/index.tsx | 101 ++++++++++++------ gui/src/hooks/index.ts | 1 - gui/src/hooks/useFileExists.ts | 43 -------- gui/src/hooks/useIdeMessengerRequest.ts | 18 ++-- 4 files changed, 80 insertions(+), 83 deletions(-) delete mode 100644 gui/src/hooks/useFileExists.ts diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index 72e4279bd..111359fc8 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -1,6 +1,6 @@ import { ChevronDownIcon } from "@heroicons/react/24/outline"; import { inferResolvedUriFromRelativePath } from "core/util/ideUtils"; -import { useContext, useState } from "react"; +import { useContext, useEffect, useMemo, useState } from "react"; import styled from "styled-components"; import { defaultBorderRadius, @@ -8,7 +8,7 @@ import { vscEditorBackground, } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; -import { useFileExists } from "../../../hooks"; +import { useIdeMessengerRequest } from "../../../hooks"; import { useWebviewListener } from "../../../hooks/useWebviewListener"; import { useAppSelector } from "../../../redux/hooks"; import { @@ -79,7 +79,20 @@ export function StepContainerPreToolbar({ expanded ?? (isInEditMode ? false : true), ); - const { fileExists, refreshFileExists } = useFileExists(relativeFilepath); + const [relativeFilepathUri, setRelativeFilepathUri] = useState( + null, + ); + + const fileExistsInput = useMemo( + () => (relativeFilepathUri ? { filepath: relativeFilepathUri } : null), + [relativeFilepathUri], + ); + + const { + result: fileExists, + refresh: refreshFileExists, + isLoading: isLoadingFileExists, + } = useIdeMessengerRequest("fileExists", fileExistsInput); const nextCodeBlockIndex = useAppSelector( (state) => state.session.codeBlockApplyStates.curIndex, @@ -90,8 +103,8 @@ export function StepContainerPreToolbar({ ); /** - * In the case where `relativeFilepath` is defined, this will just be the resolved URI - * of `relativeFilepath`. However, if no `relativeFilepath` is defined, then this will + * In the case where `relativeFilepath` is defined, this will just be `relativeFilepathUri`. + * However, if no `relativeFilepath` is defined, then this will * be the URI of the currently open file at the time the user clicks "Apply". */ const [appliedFileUri, setAppliedFileUri] = useState( @@ -106,18 +119,37 @@ export function StepContainerPreToolbar({ // so we don't want to dispaly it twice here const displayFilepath = relativeFilepath ?? appliedFileUri; + // TODO: This logic should be moved to a thunk + // Handle apply keyboard shortcut + useWebviewListener( + "applyCodeFromChat", + async () => onClickApply(), + [isNextCodeBlock, codeBlockContent], + !isNextCodeBlock, + ); + + useEffect(() => { + const getRelativeFilepathUri = async () => { + if (relativeFilepath) { + const resolvedUri = await inferResolvedUriFromRelativePath( + relativeFilepath, + ideMessenger.ide, + ); + setRelativeFilepathUri(resolvedUri); + } + }; + getRelativeFilepathUri(); + }, [relativeFilepath, ideMessenger.ide]); + async function getFileUriToApplyTo() { // If we've already resolved a file URI (from clicking apply), use that if (appliedFileUri) { return appliedFileUri; } - // If a relative filepath was provided, try to resolve it - if (relativeFilepath) { - return await inferResolvedUriFromRelativePath( - relativeFilepath, - ideMessenger.ide, - ); + // If we have the `relativeFilepathUri`, use that + if (relativeFilepathUri) { + return relativeFilepathUri; } // If no filepath was provided, get the current file @@ -154,15 +186,6 @@ export function StepContainerPreToolbar({ ideMessenger.post("insertAtCursor", { text: codeBlockContent }); } - // TODO: This logic should be moved to a thunk - // Handle apply keyboard shortcut - useWebviewListener( - "applyCodeFromChat", - async () => onClickApply(), - [isNextCodeBlock, codeBlockContent], - !isNextCodeBlock, - ); - async function handleDiffAction(action: "accept" | "reject") { const filepath = await getFileUriToApplyTo(); if (!filepath) { @@ -195,6 +218,30 @@ export function StepContainerPreToolbar({ } } + const renderActionButtons = () => { + if (isTerminalCodeBlock(language, codeBlockContent)) { + return ; + } + + if (isLoadingFileExists) { + return null; + } + + if (fileExists) { + return ( + handleDiffAction("accept")} + onClickReject={() => handleDiffAction("reject")} + /> + ); + } + + return ; + }; + // We wait until there is an extension in the filepath to avoid rendering // an incomplete filepath if (relativeFilepath && !hasFileExtension) { @@ -237,19 +284,7 @@ export function StepContainerPreToolbar({
- {isTerminalCodeBlock(language, codeBlockContent) ? ( - - ) : !fileExists ? ( - - ) : ( - handleDiffAction("accept")} - onClickReject={() => handleDiffAction("reject")} - /> - )} + {renderActionButtons()} )}
diff --git a/gui/src/hooks/index.ts b/gui/src/hooks/index.ts index b5b569cd0..8688c91e5 100644 --- a/gui/src/hooks/index.ts +++ b/gui/src/hooks/index.ts @@ -1,2 +1 @@ -export * from "./useFileExists"; export * from "./useIdeMessengerRequest"; diff --git a/gui/src/hooks/useFileExists.ts b/gui/src/hooks/useFileExists.ts deleted file mode 100644 index 1755a22bd..000000000 --- a/gui/src/hooks/useFileExists.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { inferResolvedUriFromRelativePath } from "core/util/ideUtils"; -import { useContext, useEffect, useState } from "react"; -import { IdeMessengerContext } from "../context/IdeMessenger"; -import { useIdeMessengerRequest } from "./useIdeMessengerRequest"; - -/** - * Wrapper around useIdeMessengerRequest specifically for checking file existence. - * We maintain this as a separate hook because the conversion from relative filepath - * to URI requires an async call. - */ -export function useFileExists(filepath?: string) { - const ideMessenger = useContext(IdeMessengerContext); - const [resolvedUri, setResolvedUri] = useState(null); - - const { result: fileExists, refresh: refreshFileExists } = - useIdeMessengerRequest( - "fileExists", - resolvedUri ? { filepath: resolvedUri } : null, - ); - - useEffect(() => { - async function resolveUri() { - if (!filepath) { - setResolvedUri(null); - return; - } - - try { - const uri = await inferResolvedUriFromRelativePath( - filepath, - ideMessenger.ide, - ); - setResolvedUri(uri); - } catch (err) { - console.error("Failed to resolve URI:", err); - } - } - - resolveUri(); - }, [filepath, ideMessenger.ide]); - - return { fileExists, refreshFileExists }; -} diff --git a/gui/src/hooks/useIdeMessengerRequest.ts b/gui/src/hooks/useIdeMessengerRequest.ts index af2dfb5ad..201427758 100644 --- a/gui/src/hooks/useIdeMessengerRequest.ts +++ b/gui/src/hooks/useIdeMessengerRequest.ts @@ -14,6 +14,7 @@ export function useIdeMessengerRequest( const [result, setResult] = useState< SuccessWebviewSingleMessage["content"] | null >(null); + const [isLoading, setIsLoading] = useState(false); async function makeRequest() { if (!data) { @@ -21,11 +22,16 @@ export function useIdeMessengerRequest( return; } - const response = await ideMessenger.request(messageType, data); - if (response.status === "success") { - setResult(response.content); - } else { - console.error(`Error in ${messageType} request:`, response.error); + setIsLoading(true); + try { + const response = await ideMessenger.request(messageType, data); + if (response.status === "success") { + setResult(response.content); + } else { + console.error(`Error in ${messageType} request:`, response.error); + } + } finally { + setIsLoading(false); } } @@ -33,5 +39,5 @@ export function useIdeMessengerRequest( makeRequest(); }, [data, messageType]); - return { result, refresh: makeRequest }; + return { result, isLoading, refresh: makeRequest }; } From 50521e7a22ea8874ea9be32e769539ac76e6fce8 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 14 Apr 2025 14:12:51 -0700 Subject: [PATCH 20/20] Update useIdeMessengerRequest.ts --- gui/src/hooks/useIdeMessengerRequest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/src/hooks/useIdeMessengerRequest.ts b/gui/src/hooks/useIdeMessengerRequest.ts index 201427758..f03a17571 100644 --- a/gui/src/hooks/useIdeMessengerRequest.ts +++ b/gui/src/hooks/useIdeMessengerRequest.ts @@ -29,6 +29,7 @@ export function useIdeMessengerRequest( setResult(response.content); } else { console.error(`Error in ${messageType} request:`, response.error); + setResult(null); } } finally { setIsLoading(false);