From 82dcfdffad69f6c1061290ea7fb4ee2a163b47dc Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sat, 2 Dec 2023 14:57:52 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20onBlur=20toggle=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/src/client/ContinueGUIClientProtocol.ts | 6 +- gui/src/components/mainInput/ComboBox.tsx | 1 + gui/src/hooks/useSetup.ts | 8 +- gui/src/redux/slices/sessionStateReducer.ts | 93 ++++++++++--------- server/continuedev/core/sdk.py | 22 ++++- server/continuedev/server/protocols/gui.py | 6 +- .../server/protocols/gui_protocol.py | 2 +- 7 files changed, 84 insertions(+), 54 deletions(-) diff --git a/gui/src/client/ContinueGUIClientProtocol.ts b/gui/src/client/ContinueGUIClientProtocol.ts index a67a212ba..8560693ad 100644 --- a/gui/src/client/ContinueGUIClientProtocol.ts +++ b/gui/src/client/ContinueGUIClientProtocol.ts @@ -140,9 +140,9 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol { return this.messenger?.sendAndReceive("get_config", {}); } - onAddContextItem(callback: (item: ContextItem) => void) { - this.messenger?.onMessageType("add_context_item", (data: ContextItem) => { - callback(data); + onAddContextItem(callback: (item: ContextItem, index: number) => void) { + this.messenger?.onMessageType("add_context_item_at_index", (data: any) => { + callback(data.item, data.index); }); } diff --git a/gui/src/components/mainInput/ComboBox.tsx b/gui/src/components/mainInput/ComboBox.tsx index fed059f28..d01be99a9 100644 --- a/gui/src/components/mainInput/ComboBox.tsx +++ b/gui/src/components/mainInput/ComboBox.tsx @@ -892,6 +892,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { onClick={(e) => { setShowContextToggleOn((prev) => !prev); }} + tabIndex={0} id="toggle-context-div" > {showContextToggleOn ? ( diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 466403f33..220cd21b0 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -1,8 +1,8 @@ import { Dispatch } from "@reduxjs/toolkit"; import ContinueGUIClientProtocol from "../client/ContinueGUIClientProtocol"; -import { useCallback, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { - addContextItem, + addContextItemAtIndex, addHighlightedCode, processSessionUpdate, setActive, @@ -69,8 +69,8 @@ function useSetup( dispatch(setIndexingProgress(progress)); }); - client.onAddContextItem((item) => { - dispatch(addContextItem(item)); + client.onAddContextItem((item, index) => { + dispatch(addContextItemAtIndex({ item, index })); }); client.onConfigUpdate((config) => { diff --git a/gui/src/redux/slices/sessionStateReducer.ts b/gui/src/redux/slices/sessionStateReducer.ts index e2c8e4ceb..f441caed8 100644 --- a/gui/src/redux/slices/sessionStateReducer.ts +++ b/gui/src/redux/slices/sessionStateReducer.ts @@ -6,48 +6,6 @@ import { PersistedSessionInfo } from "../../schema/PersistedSessionInfo"; import { v4 } from "uuid"; import { ContextItemId } from "../../schema/ContextItemId"; -const TEST_TIMELINE = [ - { - description: "Hi, please write bubble sort in python", - name: "User Input", - }, - { - description: `\`\`\`python -def bubble_sort(arr): - n = len(arr) - for i in range(n): - for j in range(0, n - i - 1): - if arr[j] > arr[j + 1]: - arr[j], arr[j + 1] = arr[j + 1], arr[j] - return arr -\`\`\``, - name: "Bubble Sort in Python", - }, - { - description: "Now write it in Rust", - name: "User Input", - }, - { - description: "Hello! This is a test...\n\n1, 2, 3, testing...", - name: "Testing", - }, - { - description: `Sure, here's bubble sort written in rust: \n\`\`\`rust -fn bubble_sort(values: &mut[T]) { - let len = values.len(); - for i in 0..len { - for j in 0..(len - i - 1) { - if values[j] > values[j + 1] { - values.swap(j, j + 1); - } - } - } -} -\`\`\`\nIs there anything else I can answer?`, - name: "Rust Bubble Sort", - }, -]; - const TEST_CONTEXT_ITEMS: ContextItem[] = [ { content: "def add(a, b):\n return a + b", @@ -73,6 +31,57 @@ const TEST_CONTEXT_ITEMS: ContextItem[] = [ }, ]; +const TEST_TIMELINE = [ + { + description: "Hi, please write bubble sort in python", + name: "User Input", + params: { context_items: TEST_CONTEXT_ITEMS }, + hide: false, + depth: 0, + }, + { + description: `\`\`\`python +def bubble_sort(arr): + n = len(arr) + for i in range(n): + for j in range(0, n - i - 1): + if arr[j] > arr[j + 1]: + arr[j], arr[j + 1] = arr[j + 1], arr[j] + return arr +\`\`\``, + name: "Bubble Sort in Python", + params: {}, + hide: false, + depth: 0, + }, + { + description: "Now write it in Rust", + name: "User Input", + params: {}, + }, + { + description: "Hello! This is a test...\n\n1, 2, 3, testing...", + name: "Testing", + hide: false, + }, + { + description: `Sure, here's bubble sort written in rust: \n\`\`\`rust +fn bubble_sort(values: &mut[T]) { + let len = values.len(); + for i in 0..len { + for j in 0..(len - i - 1) { + if values[j] > values[j + 1] { + values.swap(j, j + 1); + } + } + } +} +\`\`\`\nIs there anything else I can answer?`, + name: "Rust Bubble Sort", + depth: 0, + }, +]; + export interface SessionFullState { history: StepDescription[]; context_items: ContextItem[]; diff --git a/server/continuedev/core/sdk.py b/server/continuedev/core/sdk.py index 427419ca9..ced55a6b3 100644 --- a/server/continuedev/core/sdk.py +++ b/server/continuedev/core/sdk.py @@ -207,8 +207,26 @@ class ContinueSDK(AbstractContinueSDK): ) async def add_context_item(self, item: ContextItem): - self.__autopilot.session_state.context_items.append(item) - await self.gui.add_context_item(item) + index = len(self.__autopilot.session_state.history) - 1 + while index > 0: + if ( + self.__autopilot.session_state.history[index].step_type + == "UserInputStep" + ): + break + index -= 1 + + await self.add_context_item_at_index(item, index) + + async def add_context_item_at_index(self, item: ContextItem, index: int): + context_items = self.__autopilot.session_state.history[index].params.get( + "context_items", [] + ) + context_items.append(item.dict()) + self.__autopilot.session_state.history[index].params[ + "context_items" + ] = context_items + await self.gui.add_context_item_at_index(item, index) def set_loading_message(self, message: str): # self.__autopilot.set_loading_message(message) diff --git a/server/continuedev/server/protocols/gui.py b/server/continuedev/server/protocols/gui.py index d5cbbd95a..8bc37b880 100644 --- a/server/continuedev/server/protocols/gui.py +++ b/server/continuedev/server/protocols/gui.py @@ -159,8 +159,10 @@ class GUIProtocolServer(AbstractGUIProtocolServer): {}, SessionState, "get_session_state" ) - async def add_context_item(self, item: ContextItem): - await self.messenger.send("add_context_item", item.dict()) + async def add_context_item_at_index(self, item: ContextItem, index: int): + await self.messenger.send( + "add_context_item_at_index", {"item": item.dict(), "index": index} + ) async def send_config_update(self): if config := self.get_config(): diff --git a/server/continuedev/server/protocols/gui_protocol.py b/server/continuedev/server/protocols/gui_protocol.py index b04b4bc95..fc031187b 100644 --- a/server/continuedev/server/protocols/gui_protocol.py +++ b/server/continuedev/server/protocols/gui_protocol.py @@ -11,5 +11,5 @@ class AbstractGUIProtocolServer(ABC): ... @abstractmethod - async def add_context_item(self, item: ContextItem): + async def add_context_item_at_index(self, item: ContextItem, index: int): ...