From 3d5d4569a712d53812d59e4379910651c242f484 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 24 Nov 2024 23:58:48 -0800 Subject: [PATCH 1/4] redux audit --- extensions/vscode/package-lock.json | 6 +- gui/package-lock.json | 8 +- gui/src/App.tsx | 29 +- .../components/mainInput/ContinueInputBox.tsx | 5 +- gui/src/components/mainInput/TipTapEditor.tsx | 6 +- .../StepContainerPreToolbar.tsx | 11 +- .../markdown/StyledMarkdownPreview.tsx | 15 +- gui/src/context/SubmenuContextProviders.ts | 13 - gui/src/context/SubmenuContextProviders.tsx | 322 ++++++++++++++++++ gui/src/context/VscTheme.ts | 3 - .../useVscTheme.ts => context/VscTheme.tsx} | 35 +- gui/src/editorInset/EditorInset.tsx | 4 +- gui/src/hooks/useChatHandler.ts | 14 +- gui/src/hooks/useSetup.ts | 7 +- gui/src/hooks/useSubmenuContextProviders.tsx | 311 ----------------- gui/src/pages/Edit/Edit.tsx | 9 +- gui/src/pages/gui/Chat.tsx | 31 +- gui/src/redux/selectors/index.ts | 25 +- gui/src/redux/selectors/modelSelectors.ts | 19 +- gui/src/redux/slices/stateSlice.ts | 7 +- 20 files changed, 454 insertions(+), 426 deletions(-) delete mode 100644 gui/src/context/SubmenuContextProviders.ts create mode 100644 gui/src/context/SubmenuContextProviders.tsx delete mode 100644 gui/src/context/VscTheme.ts rename gui/src/{hooks/useVscTheme.ts => context/VscTheme.tsx} (86%) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 940503505..8d680fb94 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.232", + "version": "0.9.233", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.232", + "version": "0.9.233", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", @@ -109,7 +109,7 @@ "cheerio": "^1.0.0-rc.12", "commander": "^12.0.0", "comment-json": "^4.2.3", - "dbinfoz": "^0.11.0", + "dbinfoz": "^0.14.0", "diff": "^7.0.0", "dotenv": "^16.4.5", "fastest-levenshtein": "^1.0.16", diff --git a/gui/package-lock.json b/gui/package-lock.json index 3be234fb8..1a9e4fe3f 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -56,7 +56,6 @@ "socket.io-client": "^4.7.2", "styled-components": "^5.3.6", "table": "^6.8.1", - "tailwind-scrollbar-hide": "^1.1.7", "tippy.js": "^6.3.7", "unist-util-visit": "^5.0.0", "uuid": "^9.0.1", @@ -112,7 +111,7 @@ "cheerio": "^1.0.0-rc.12", "commander": "^12.0.0", "comment-json": "^4.2.3", - "dbinfoz": "^0.11.0", + "dbinfoz": "^0.14.0", "diff": "^7.0.0", "dotenv": "^16.4.5", "fastest-levenshtein": "^1.0.16", @@ -8984,11 +8983,6 @@ "node": ">=10.0.0" } }, - "node_modules/tailwind-scrollbar-hide": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/tailwind-scrollbar-hide/-/tailwind-scrollbar-hide-1.1.7.tgz", - "integrity": "sha512-X324n9OtpTmOMqEgDUEA/RgLrNfBF/jwJdctaPZDzB3mppxJk7TLIDmOreEDm1Bq4R9LSPu4Epf8VSdovNU+iA==" - }, "node_modules/tailwindcss": { "version": "3.4.12", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.12.tgz", diff --git a/gui/src/App.tsx b/gui/src/App.tsx index 1e34e6e15..646043629 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -1,11 +1,8 @@ import { useDispatch } from "react-redux"; import { RouterProvider, createMemoryRouter } from "react-router-dom"; import Layout from "./components/Layout"; -import { SubmenuContextProvidersContext } from "./context/SubmenuContextProviders"; -import { VscThemeContext } from "./context/VscTheme"; +import { VscThemeProvider } from "./context/VscTheme"; import useSetup from "./hooks/useSetup"; -import useSubmenuContextProviders from "./hooks/useSubmenuContextProviders"; -import { useVscTheme } from "./hooks/useVscTheme"; import { AddNewModel, ConfigureProvider } from "./pages/AddNewModel"; import ConfigErrorPage from "./pages/config-error"; import Edit from "./pages/Edit"; @@ -18,6 +15,7 @@ import MorePage from "./pages/More"; import SettingsPage from "./pages/settings"; import Stats from "./pages/stats"; import { ROUTES } from "./util/navigation"; +import { SubmenuContextProvidersProvider } from "./context/SubmenuContextProviders"; const router = createMemoryRouter([ { @@ -77,22 +75,25 @@ const router = createMemoryRouter([ }, ]); -function App() { +/* + Prevents entire app from rerendering continuously with useSetup in App + TODO - look into a more redux-esque way to do this +*/ +function SetupListeners() { const dispatch = useDispatch(); useSetup(dispatch); + return <>; +} - const vscTheme = useVscTheme(); - const submenuContextProvidersMethods = useSubmenuContextProviders(); - +function App() { return ( - - + + - - + + + ); } diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index 4fccac8fe..93ac4fddf 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -4,12 +4,11 @@ import { useDispatch, useSelector } from "react-redux"; import styled, { keyframes } from "styled-components"; import { defaultBorderRadius, vscBackground } from ".."; import { useWebviewListener } from "../../hooks/useWebviewListener"; -import { selectSlashCommands } from "../../redux/selectors"; +import { selectSlashCommandComboBoxInputs } from "../../redux/selectors"; import { newSession, setMessageAtIndex } from "../../redux/slices/stateSlice"; import { RootState } from "../../redux/store"; import ContextItemsPeek from "./ContextItemsPeek"; import TipTapEditor from "./TipTapEditor"; - interface ContinueInputBoxProps { isLastUserInput: boolean; isMainInput?: boolean; @@ -64,7 +63,7 @@ function ContinueInputBox(props: ContinueInputBoxProps) { const dispatch = useDispatch(); const active = useSelector((store: RootState) => store.state.active); - const availableSlashCommands = useSelector(selectSlashCommands); + const availableSlashCommands = useSelector(selectSlashCommandComboBoxInputs); const availableContextProviders = useSelector( (store: RootState) => store.state.config.contextProviders, ); diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 7737e5f25..bd7714139 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -37,7 +37,7 @@ import { vscInputBorderFocus, } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { SubmenuContextProvidersContext } from "../../context/SubmenuContextProviders"; +import { useSubmenuContextProviders } from "../../context/SubmenuContextProviders"; import useHistory from "../../hooks/useHistory"; import { useInputHistory } from "../../hooks/useInputHistory"; import useUpdatingRef from "../../hooks/useUpdatingRef"; @@ -168,7 +168,7 @@ function TipTapEditor(props: TipTapEditorProps) { const dispatch = useDispatch(); const ideMessenger = useContext(IdeMessengerContext); - const { getSubmenuContextItems } = useContext(SubmenuContextProvidersContext); + const { getSubmenuContextItems } = useSubmenuContextProviders(); const historyLength = useSelector( (store: RootState) => store.state.history.length, @@ -598,7 +598,7 @@ function TipTapEditor(props: TipTapEditorProps) { if (isOSREnabled) { handleJetBrainsOSRMetaKeyIssues(e, editor); - } else if (!isJetBrains()){ + } else if (!isJetBrains()) { await handleVSCMetaKeyIssues(e, editor); } }; diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 4692e1bb1..6a1d59709 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -1,6 +1,6 @@ import { ChevronDownIcon } from "@heroicons/react/24/outline"; import { debounce } from "lodash"; -import { useContext, useEffect, useRef, useState } from "react"; +import { useContext, useEffect, useMemo, useRef, useState } from "react"; import { useSelector } from "react-redux"; import styled, { css, keyframes } from "styled-components"; import { v4 as uuidv4 } from "uuid"; @@ -80,11 +80,12 @@ export default function StepContainerPreToolbar( (state: RootState) => state.state.nextCodeBlockToApplyIndex, ); - const applyState = useSelector((store: RootState) => - store.state.applyStates.find( - (state) => state.streamId === streamIdRef.current, - ), + const applyStates = useSelector( + (store: RootState) => store.state.applyStates, ); + const applyState = useMemo(() => { + return applyStates.find((state) => state.streamId === streamIdRef.current); + }, [applyStates, streamIdRef]); // This handles an edge case when the last node in the markdown syntax tree is a codeblock. // In this scenario, `isGeneratingCodeBlock` is never set to false since we determine if diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index cdd8babf7..8db7e4253 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -24,6 +24,7 @@ import { RootState } from "../../redux/store"; import { ContextItemWithId, SymbolWithRange } from "core"; import SymbolLink from "./SymbolLink"; import { useSelector } from "react-redux"; +import useUpdatingRef from "../../hooks/useUpdatingRef"; const StyledMarkdown = styled.div<{ fontSize?: number; @@ -155,21 +156,17 @@ function processCodeBlocks(tree: any) { const StyledMarkdownPreview = memo(function StyledMarkdownPreview( props: StyledMarkdownPreviewProps, ) { + // The refs are a workaround because rehype options are stored on initiation + // So they won't use the most up-to-date state values + // So in this case we just put them in refs const contextItems = useSelector( (state: RootState) => state.state.history[props.itemIndex - 1]?.contextItems, ); + const contextItemsRef = useUpdatingRef(contextItems); + const symbols = useSelector((state: RootState) => state.state.symbols); - - // The refs are a workaround because rehype options are stored on initiation - // So they won't use the most up-to-date state values - // So in this case we just put them in refs const symbolsRef = useRef([]); - const contextItemsRef = useRef([]); - - useEffect(() => { - contextItemsRef.current = contextItems || []; - }, [contextItems]); useEffect(() => { // Note, before I was only looking for symbols that matched // Context item files on current history item diff --git a/gui/src/context/SubmenuContextProviders.ts b/gui/src/context/SubmenuContextProviders.ts deleted file mode 100644 index 5be351a08..000000000 --- a/gui/src/context/SubmenuContextProviders.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ContextSubmenuItem } from "core"; -import { createContext } from "react"; - -export const SubmenuContextProvidersContext = createContext<{ - getSubmenuContextItems: ( - providerTitle: string | undefined, - query: string, - ) => (ContextSubmenuItem & { providerTitle: string })[]; - addItem: (providerTitle: string, item: ContextSubmenuItem) => void; -}>({ - getSubmenuContextItems: () => [], - addItem: () => {}, -}); diff --git a/gui/src/context/SubmenuContextProviders.tsx b/gui/src/context/SubmenuContextProviders.tsx new file mode 100644 index 000000000..ba753cfe2 --- /dev/null +++ b/gui/src/context/SubmenuContextProviders.tsx @@ -0,0 +1,322 @@ +import { ContextSubmenuItem } from "core"; +import { createContext } from "react"; +import { + deduplicateArray, + getBasename, + getUniqueFilePath, + groupByLastNPathParts, +} from "core/util"; +import MiniSearch, { SearchResult } from "minisearch"; +import { useCallback, useContext, useEffect, useMemo, useState } from "react"; +import { useSelector } from "react-redux"; +import { IdeMessengerContext } from "./IdeMessenger"; +import { selectContextProviderDescriptions } from "../redux/selectors"; +import { RootState } from "../redux/store"; +import { useWebviewListener } from "../hooks/useWebviewListener"; + +const MINISEARCH_OPTIONS = { + prefix: true, + fuzzy: 2, +}; + +const MAX_LENGTH = 70; + +interface SubtextContextProvidersContextType { + getSubmenuContextItems: ( + providerTitle: string | undefined, + query: string, + ) => (ContextSubmenuItem & { providerTitle: string })[]; + addItem: (providerTitle: string, item: ContextSubmenuItem) => void; +} + +const initialContextProviders: SubtextContextProvidersContextType = { + getSubmenuContextItems: () => [], + addItem: () => {}, +}; + +const SubmenuContextProvidersContext = + createContext(initialContextProviders); + +export const SubmenuContextProvidersProvider = ({ + children, +}: { + children: React.ReactNode; +}) => { + const [minisearches, setMinisearches] = useState<{ + [id: string]: MiniSearch; + }>({}); + const [fallbackResults, setFallbackResults] = useState<{ + [id: string]: ContextSubmenuItem[]; + }>({}); + + const contextProviderDescriptions = useSelector( + selectContextProviderDescriptions, + ); + + const [initialLoadComplete, setInitialLoadComplete] = useState(false); + const [isLoading, setIsLoading] = useState(false); + const [autoLoadTriggered, setAutoLoadTriggered] = useState(false); + + const config = useSelector((store: RootState) => store.state.config); + + const ideMessenger = useContext(IdeMessengerContext); + + const getOpenFilesItems = useCallback(async () => { + const openFiles = await ideMessenger.ide.getOpenFiles(); + const openFileGroups = groupByLastNPathParts(openFiles, 2); + + return openFiles.map((file) => ({ + id: file, + title: getBasename(file), + description: getUniqueFilePath(file, openFileGroups), + providerTitle: "file", + })); + }, [ideMessenger]); + + useWebviewListener("refreshSubmenuItems", async (data) => { + if (!isLoading) { + setInitialLoadComplete(false); + setAutoLoadTriggered((prev) => !prev); // Toggle to trigger effect + } + }); + + useWebviewListener("updateSubmenuItems", async (data) => { + const minisearch = new MiniSearch({ + fields: ["title", "description"], + storeFields: ["id", "title", "description"], + }); + + minisearch.addAll(data.submenuItems); + + setMinisearches((prev) => ({ ...prev, [data.provider]: minisearch })); + + if (data.provider === "file") { + const openFiles = await getOpenFilesItems(); + setFallbackResults((prev) => ({ + ...prev, + file: [ + ...openFiles, + ...data.submenuItems.slice(0, MAX_LENGTH - openFiles.length), + ], + })); + } else { + setFallbackResults((prev) => ({ + ...prev, + [data.provider]: data.submenuItems.slice(0, MAX_LENGTH), + })); + } + }); + + const addItem = useCallback( + (providerTitle: string, item: ContextSubmenuItem) => { + if (!minisearches[providerTitle]) { + return; + } + minisearches[providerTitle].add(item); + }, + [minisearches], + ); + + useEffect(() => { + let isMounted = true; + const refreshOpenFiles = async () => { + if (!isMounted) return; + const openFiles = await getOpenFilesItems(); + setFallbackResults((prev) => ({ + ...prev, + file: deduplicateArray( + [...openFiles, ...(Array.isArray(prev.file) ? prev.file : [])], + (a, b) => a.id === b.id, + ), + })); + }; + + const interval = setInterval(refreshOpenFiles, 2000); + + refreshOpenFiles(); // Initial call + + return () => { + isMounted = false; + clearInterval(interval); + }; + }, [getOpenFilesItems]); + + const getSubmenuSearchResults = useMemo( + () => + (providerTitle: string | undefined, query: string): SearchResult[] => { + if (providerTitle === undefined) { + // Return search combined from all providers + const results = Object.keys(minisearches).map((providerTitle) => { + const results = minisearches[providerTitle].search( + query, + MINISEARCH_OPTIONS, + ); + return results.map((result) => { + return { ...result, providerTitle }; + }); + }); + + return results.flat().sort((a, b) => b.score - a.score); + } + if (!minisearches[providerTitle]) { + return []; + } + + const results = minisearches[providerTitle] + .search(query, MINISEARCH_OPTIONS) + .map((result) => { + return { ...result, providerTitle }; + }); + + return results; + }, + [minisearches], + ); + + const getSubmenuContextItems = useMemo( + () => + ( + providerTitle: string | undefined, + query: string, + limit: number = MAX_LENGTH, + ): (ContextSubmenuItem & { providerTitle: string })[] => { + try { + const results = getSubmenuSearchResults(providerTitle, query); + if (results.length === 0) { + const fallbackItems = (fallbackResults[providerTitle] ?? []) + .slice(0, limit) + .map((result) => { + return { + ...result, + providerTitle, + }; + }); + + if (fallbackItems.length === 0 && !initialLoadComplete) { + return [ + { + id: "loading", + title: "Loading...", + description: "Please wait while items are being loaded", + providerTitle: providerTitle || "unknown", + }, + ]; + } + + return fallbackItems; + } + const limitedResults = results.slice(0, limit).map((result) => { + return { + id: result.id, + title: result.title, + description: result.description, + providerTitle: result.providerTitle, + }; + }); + return limitedResults; + } catch (error) { + console.error("Error in getSubmenuContextItems:", error); + return []; + } + }, + [fallbackResults, getSubmenuSearchResults, initialLoadComplete], + ); + + useEffect(() => { + if (contextProviderDescriptions.length === 0 || isLoading) { + return; + } + setIsLoading(true); + + const loadSubmenuItems = async () => { + try { + await Promise.all( + contextProviderDescriptions.map(async (description) => { + const shouldSkipProvider = + description.dependsOnIndexing && config.disableIndexing; + + if (shouldSkipProvider) { + console.debug( + `Skipping ${description.title} provider due to disabled indexing`, + ); + return; + } + + try { + const minisearch = new MiniSearch({ + fields: ["title", "description"], + storeFields: ["id", "title", "description"], + }); + + const result = await ideMessenger.request( + "context/loadSubmenuItems", + { + title: description.title, + }, + ); + + if (result.status === "error") { + console.error( + `Error loading items for ${description.title}:`, + result.error, + ); + return; + } + const items = result.content; + + minisearch.addAll(items); + + setMinisearches((prev) => ({ + ...prev, + [description.title]: minisearch, + })); + + if (description.title === "file") { + const openFiles = await getOpenFilesItems(); + setFallbackResults((prev) => ({ + ...prev, + file: [ + ...openFiles, + ...items.slice(0, MAX_LENGTH - openFiles.length), + ], + })); + } else { + setFallbackResults((prev) => ({ + ...prev, + [description.title]: items.slice(0, MAX_LENGTH), + })); + } + } catch (error) { + console.error(`Error processing ${description.title}:`, error); + console.error( + "Error details:", + JSON.stringify(error, Object.getOwnPropertyNames(error)), + ); + } + }), + ); + } catch (error) { + console.error("Error in loadSubmenuItems:", error); + } finally { + setInitialLoadComplete(true); + setIsLoading(false); + } + }; + + loadSubmenuItems(); + }, [contextProviderDescriptions, autoLoadTriggered]); + + return ( + + {children} + + ); +}; + +export const useSubmenuContextProviders = () => + useContext(SubmenuContextProvidersContext); diff --git a/gui/src/context/VscTheme.ts b/gui/src/context/VscTheme.ts deleted file mode 100644 index 574427d64..000000000 --- a/gui/src/context/VscTheme.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { createContext } from "react"; - -export const VscThemeContext = createContext(undefined); diff --git a/gui/src/hooks/useVscTheme.ts b/gui/src/context/VscTheme.tsx similarity index 86% rename from gui/src/hooks/useVscTheme.ts rename to gui/src/context/VscTheme.tsx index 959142ba6..dd3343493 100644 --- a/gui/src/hooks/useVscTheme.ts +++ b/gui/src/context/VscTheme.tsx @@ -1,6 +1,6 @@ -import { useState } from "react"; +import { createContext, useContext, useState } from "react"; import { parseHexColor } from "../components"; -import { useWebviewListener } from "./useWebviewListener"; +import { useWebviewListener } from "../hooks/useWebviewListener"; const hljsToTextMate: Record = { ".hljs-comment": ["comment"], @@ -149,9 +149,24 @@ function fallbackTheme() { }; } -export function useVscTheme() { - const [theme, setTheme] = useState( - constructTheme(window.fullColorTheme || {}), +interface VscThemeContextType { + theme: Record; +} + +const initialVscThemeContext: VscThemeContextType = { + theme: constructTheme(window.fullColorTheme || {}), +}; +export const VscThemeContext = createContext( + initialVscThemeContext, +); + +export const VscThemeProvider = ({ + children, +}: { + children: React.ReactNode; +}) => { + const [theme, setTheme] = useState>( + initialVscThemeContext.theme, ); useWebviewListener("setTheme", async (data) => { @@ -159,5 +174,11 @@ export function useVscTheme() { setTheme(constructTheme(data.theme)); }); - return theme; -} + return ( + + {children} + + ); +}; + +export const useVscTheme = () => useContext(VscThemeContext); diff --git a/gui/src/editorInset/EditorInset.tsx b/gui/src/editorInset/EditorInset.tsx index 7e8e5fde1..8ba56f97b 100644 --- a/gui/src/editorInset/EditorInset.tsx +++ b/gui/src/editorInset/EditorInset.tsx @@ -5,7 +5,7 @@ import { defaultBorderRadius } from "../components"; import TipTapEditor from "../components/mainInput/TipTapEditor"; import { IdeMessengerContext } from "../context/IdeMessenger"; import useSetup from "../hooks/useSetup"; -import { selectSlashCommands } from "../redux/selectors"; +import { selectSlashCommandComboBoxInputs } from "../redux/selectors"; import { RootState } from "../redux/store"; const EditorInsetDiv = styled.div` @@ -18,7 +18,7 @@ const EditorInsetDiv = styled.div` function EditorInset() { const dispatch = useDispatch(); - const availableSlashCommands = useSelector(selectSlashCommands); + const availableSlashCommands = useSelector(selectSlashCommandComboBoxInputs); const availableContextProviders = useSelector( (store: RootState) => store.state.config.contextProviders, ); diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index 7dd914dd6..247b8d2cf 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -15,7 +15,7 @@ import { constructMessages } from "core/llm/constructMessages"; import { stripImages } from "core/llm/images"; import { getBasename, getRelativePath } from "core/util"; import { usePostHog } from "posthog-js/react"; -import { useEffect, useRef, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { useSelector } from "react-redux"; import resolveEditorContent, { hasSlashCommandOrContextProvider, @@ -38,18 +38,18 @@ import { resetNextCodeBlockToApplyIndex } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; import useHistory from "./useHistory"; import { updateFileSymbolsFromContextItems } from "../util/symbols"; +import { + selectDefaultContextProviders, + selectSlashCommands, +} from "../redux/selectors"; function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { const posthog = usePostHog(); const defaultModel = useSelector(defaultModelSelector); - const defaultContextProviders = useSelector( - (store: RootState) => store.state.config.experimental?.defaultContext ?? [], - ); + const defaultContextProviders = useSelector(selectDefaultContextProviders); - const slashCommands = useSelector( - (store: RootState) => store.state.config.slashCommands || [], - ); + const slashCommands = useSelector(selectSlashCommands); const history = useSelector((store: RootState) => store.state.history); const active = useSelector((store: RootState) => store.state.active); diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 4bef9da9c..441ffa88e 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -1,5 +1,5 @@ import { Dispatch } from "@reduxjs/toolkit"; -import { useCallback, useContext, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef } from "react"; import { useSelector } from "react-redux"; import { VSC_THEME_COLOR_VARS } from "../components"; import { IdeMessengerContext } from "../context/IdeMessenger"; @@ -15,9 +15,8 @@ import { } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; -import { debounce } from "lodash"; import { isJetBrains } from "../util"; -import { getLocalStorage, setLocalStorage } from "../util/localStorage"; +import { setLocalStorage } from "../util/localStorage"; import useChatHandler from "./useChatHandler"; import { useWebviewListener } from "./useWebviewListener"; import { updateFileSymbolsFromContextItems } from "../util/symbols"; @@ -178,8 +177,6 @@ function useSetup(dispatch: Dispatch) { }, [defaultModelTitle], ); - - } export default useSetup; diff --git a/gui/src/hooks/useSubmenuContextProviders.tsx b/gui/src/hooks/useSubmenuContextProviders.tsx index 67abeb632..e69de29bb 100644 --- a/gui/src/hooks/useSubmenuContextProviders.tsx +++ b/gui/src/hooks/useSubmenuContextProviders.tsx @@ -1,311 +0,0 @@ -import { ContextSubmenuItem } from "core"; -import { WebviewMessengerResult } from "core/protocol/util"; -import { - deduplicateArray, - getBasename, - getUniqueFilePath, - groupByLastNPathParts, -} from "core/util"; -import MiniSearch, { SearchResult } from "minisearch"; -import { useCallback, useContext, useEffect, useMemo, useState } from "react"; -import { useSelector } from "react-redux"; -import { IdeMessengerContext } from "../context/IdeMessenger"; -import { selectContextProviderDescriptions } from "../redux/selectors"; -import { getLocalStorage } from "../util/localStorage"; -import { useWebviewListener } from "./useWebviewListener"; -import { RootState } from "../redux/store"; - -const MINISEARCH_OPTIONS = { - prefix: true, - fuzzy: 2, -}; - -const MAX_LENGTH = 70; - -function useSubmenuContextProviders() { - const [minisearches, setMinisearches] = useState<{ - [id: string]: MiniSearch; - }>({}); - const [fallbackResults, setFallbackResults] = useState<{ - [id: string]: ContextSubmenuItem[]; - }>({}); - - const contextProviderDescriptions = useSelector( - selectContextProviderDescriptions, - ); - - const [loaded, setLoaded] = useState(false); - const [initialLoadComplete, setInitialLoadComplete] = useState(false); - const [isLoading, setIsLoading] = useState(false); - const [autoLoadTriggered, setAutoLoadTriggered] = useState(false); - - const config = useSelector((store: RootState) => store.state.config); - - const ideMessenger = useContext(IdeMessengerContext); - - const memoizedGetOpenFileItems = useMemo(() => { - return async () => { - const openFiles = await ideMessenger.ide.getOpenFiles(); - const openFileGroups = groupByLastNPathParts(openFiles, 2); - - return openFiles.map((file) => ({ - id: file, - title: getBasename(file), - description: getUniqueFilePath(file, openFileGroups), - providerTitle: "file", - })); - }; - }, [ideMessenger]); - - useWebviewListener("refreshSubmenuItems", async (data) => { - if (!isLoading) { - setLoaded(false); - setInitialLoadComplete(false); - setAutoLoadTriggered((prev) => !prev); // Toggle to trigger effect - } - }); - - useWebviewListener("updateSubmenuItems", async (data) => { - const minisearch = new MiniSearch({ - fields: ["title", "description"], - storeFields: ["id", "title", "description"], - }); - - minisearch.addAll(data.submenuItems); - - setMinisearches((prev) => ({ ...prev, [data.provider]: minisearch })); - - if (data.provider === "file") { - const openFiles = await memoizedGetOpenFileItems(); - setFallbackResults((prev) => ({ - ...prev, - file: [ - ...openFiles, - ...data.submenuItems.slice(0, MAX_LENGTH - openFiles.length), - ], - })); - } else { - setFallbackResults((prev) => ({ - ...prev, - [data.provider]: data.submenuItems.slice(0, MAX_LENGTH), - })); - } - }); - - const addItem = useCallback( - (providerTitle: string, item: ContextSubmenuItem) => { - if (!minisearches[providerTitle]) { - return; - } - minisearches[providerTitle].add(item); - }, - [minisearches], - ); - - useEffect(() => { - let isMounted = true; - const refreshOpenFiles = async () => { - if (!isMounted) return; - const openFiles = await memoizedGetOpenFileItems(); - setFallbackResults((prev) => ({ - ...prev, - file: deduplicateArray( - [...openFiles, ...(Array.isArray(prev.file) ? prev.file : [])], - (a, b) => a.id === b.id, - ), - })); - }; - - const interval = setInterval(refreshOpenFiles, 2000); - - refreshOpenFiles(); // Initial call - - return () => { - isMounted = false; - clearInterval(interval); - }; - }, [memoizedGetOpenFileItems]); - - const getSubmenuSearchResults = useMemo( - () => - (providerTitle: string | undefined, query: string): SearchResult[] => { - if (providerTitle === undefined) { - // Return search combined from all providers - const results = Object.keys(minisearches).map((providerTitle) => { - const results = minisearches[providerTitle].search( - query, - MINISEARCH_OPTIONS, - ); - return results.map((result) => { - return { ...result, providerTitle }; - }); - }); - - return results.flat().sort((a, b) => b.score - a.score); - } - if (!minisearches[providerTitle]) { - return []; - } - - const results = minisearches[providerTitle] - .search(query, MINISEARCH_OPTIONS) - .map((result) => { - return { ...result, providerTitle }; - }); - - return results; - }, - [minisearches], - ); - - const getSubmenuContextItems = useMemo( - () => - ( - providerTitle: string | undefined, - query: string, - limit: number = MAX_LENGTH, - ): (ContextSubmenuItem & { providerTitle: string })[] => { - try { - const results = getSubmenuSearchResults(providerTitle, query); - if (results.length === 0) { - const fallbackItems = (fallbackResults[providerTitle] ?? []) - .slice(0, limit) - .map((result) => { - return { - ...result, - providerTitle, - }; - }); - - if (fallbackItems.length === 0 && !initialLoadComplete) { - return [ - { - id: "loading", - title: "Loading...", - description: "Please wait while items are being loaded", - providerTitle: providerTitle || "unknown", - }, - ]; - } - - return fallbackItems; - } - const limitedResults = results.slice(0, limit).map((result) => { - return { - id: result.id, - title: result.title, - description: result.description, - providerTitle: result.providerTitle, - }; - }); - return limitedResults; - } catch (error) { - console.error("Error in getSubmenuContextItems:", error); - return []; - } - }, - [fallbackResults, getSubmenuSearchResults, initialLoadComplete], - ); - - useEffect(() => { - if (contextProviderDescriptions.length === 0 || loaded || isLoading) { - return; - } - setLoaded(true); - setIsLoading(true); - - const loadSubmenuItems = async () => { - try { - await Promise.all( - contextProviderDescriptions.map(async (description) => { - const shouldSkipProvider = - description.dependsOnIndexing && config.disableIndexing; - - if (shouldSkipProvider) { - console.debug( - `Skipping ${description.title} provider due to disabled indexing`, - ); - return; - } - - try { - const minisearch = new MiniSearch({ - fields: ["title", "description"], - storeFields: ["id", "title", "description"], - }); - - const result = await ideMessenger.request( - "context/loadSubmenuItems", - { - title: description.title, - }, - ) - - if (result.status === "error") { - console.error( - `Error loading items for ${description.title}:`, - result.error, - ); - return; - } - const items = result.content; - - minisearch.addAll(items); - - setMinisearches((prev) => ({ - ...prev, - [description.title]: minisearch, - })); - - if (description.title === "file") { - const openFiles = await memoizedGetOpenFileItems(); - setFallbackResults((prev) => ({ - ...prev, - file: [ - ...openFiles, - ...items.slice(0, MAX_LENGTH - openFiles.length), - ], - })); - } else { - setFallbackResults((prev) => ({ - ...prev, - [description.title]: items.slice(0, MAX_LENGTH), - })); - } - } catch (error) { - console.error(`Error processing ${description.title}:`, error); - console.error( - "Error details:", - JSON.stringify(error, Object.getOwnPropertyNames(error)), - ); - } - }), - ); - } catch (error) { - console.error("Error in loadSubmenuItems:", error); - } finally { - setInitialLoadComplete(true); - setIsLoading(false); - } - }; - - loadSubmenuItems().catch((error) => { - console.error("Error in loadSubmenuItems:", error); - setInitialLoadComplete(true); - setIsLoading(false); - }); - }, [contextProviderDescriptions, loaded, autoLoadTriggered]); - - useWebviewListener("configUpdate", async () => { - // When config is updated (for example switching to a different workspace) - // we need to reload the context providers. - setLoaded(false); - }); - - return { - getSubmenuContextItems, - addItem, - }; -} - -export default useSubmenuContextProviders; diff --git a/gui/src/pages/Edit/Edit.tsx b/gui/src/pages/Edit/Edit.tsx index c69200bc1..25647da95 100644 --- a/gui/src/pages/Edit/Edit.tsx +++ b/gui/src/pages/Edit/Edit.tsx @@ -21,6 +21,7 @@ import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectA import ContinueInputBox from "../../components/mainInput/ContinueInputBox"; import StepContainer from "../../components/StepContainer"; import getMultifileEditPrompt from "./getMultifileEditPrompt"; +import { selectApplyState } from "../../redux/selectors"; const EDIT_DISALLOWED_CONTEXT_PROVIDERS = [ "codebase", @@ -50,11 +51,7 @@ export default function Edit() { (state: RootState) => state.state.applyStates, ); - const applyState = useSelector( - (store: RootState) => - store.state.applyStates.find((state) => state.streamId === "edit") - ?.status ?? "closed", - ); + const applyState = useSelector(selectApplyState); const isSingleRangeEdit = editModeState.codeToEdit.length === 0 || @@ -74,8 +71,6 @@ export default function Edit() { } }, [applyState, editModeState.editStatus]); - // const active = useSelector((state: RootState) => state.state.active); - const pendingApplyStates = applyStates.filter( (state) => state.status === "done", ); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index a810dc87a..3a38ca9c4 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -12,6 +12,7 @@ import { useCallback, useContext, useEffect, + useMemo, useRef, useState, } from "react"; @@ -131,10 +132,15 @@ export function Chat() { const mainTextInputRef = useRef(null); const stepsDivRef = useRef(null); const [isAtBottom, setIsAtBottom] = useState(false); - const state = useSelector((state: RootState) => state.state); + const history = useSelector((store: RootState) => store.state.history); + const showChatScrollbar = useSelector( + (store: RootState) => store.state.config?.ui?.showChatScrollbar, + ); const { saveSession, getLastSessionId, loadLastSession } = useHistory(dispatch); + console.log("chat rendering"); + const snapToBottom = useCallback(() => { if (!stepsDivRef.current) return; const elem = stepsDivRef.current; @@ -289,7 +295,7 @@ export function Chat() { setLocalStorage("mainTextEntryCounter", 1); } }, - [state.history, defaultModel, state, streamResponse], + [history, defaultModel, streamResponse], ); useWebviewListener( @@ -303,26 +309,27 @@ export function Chat() { const isLastUserInput = useCallback( (index: number): boolean => { - return !state.history + return !history .slice(index + 1) .some((entry) => entry.message.role === "user"); }, - [state.history], + [history], ); - const showScrollbar = - state.config.ui?.showChatScrollbar || window.innerHeight > 5000; + const showScrollbar = useMemo(() => { + return showChatScrollbar ?? window.innerHeight > 5000; + }, [showChatScrollbar]); return ( <> {widget} 0 ? "flex-1" : ""}`} + className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${history.length > 0 ? "flex-1" : ""}`} onScroll={handleScroll} > {highlights} - {state.history.map((item, index: number) => ( + {history.map((item, index: number) => ( @@ -421,7 +428,7 @@ export function Chat() { >
- {state.history.length === 0 && getLastSessionId() ? ( + {history.length === 0 && getLastSessionId() ? (
{ @@ -440,7 +447,7 @@ export function Chat() {
- {state.history.length === 0 && ( + {history.length === 0 && ( <> {onboardingCard.show && (
@@ -458,7 +465,7 @@ export function Chat() {
diff --git a/gui/src/redux/selectors/index.ts b/gui/src/redux/selectors/index.ts index 88f5c99bc..78403711c 100644 --- a/gui/src/redux/selectors/index.ts +++ b/gui/src/redux/selectors/index.ts @@ -2,7 +2,7 @@ import { createSelector } from "@reduxjs/toolkit"; import { ComboBoxItemType } from "../../components/mainInput/types"; import { RootState } from "../store"; -export const selectSlashCommands = createSelector( +export const selectSlashCommandComboBoxInputs = createSelector( [(store: RootState) => store.state.config.slashCommands], (slashCommands) => { return ( @@ -17,6 +17,13 @@ export const selectSlashCommands = createSelector( }, ); +export const selectSlashCommands = createSelector( + [(store: RootState) => store.state.config.slashCommands], + (slashCommands) => { + return slashCommands || []; + }, +); + export const selectContextProviderDescriptions = createSelector( [(store: RootState) => store.state.config.contextProviders], (providers) => { @@ -24,7 +31,23 @@ export const selectContextProviderDescriptions = createSelector( }, ); +export const selectDefaultContextProviders = createSelector( + [(store: RootState) => store.state.config.experimental?.defaultContext], + (defaultProviders) => { + return defaultProviders ?? []; + }, +); + export const selectUseActiveFile = createSelector( [(store: RootState) => store.state.config.experimental?.defaultContext], (defaultContext) => defaultContext?.includes("activeFile" as any), ); + +export const selectApplyState = createSelector( + [(store: RootState) => store.state.applyStates], + (applyStates) => { + return ( + applyStates.find((state) => state.streamId === "edit")?.status ?? "closed" + ); + }, +); diff --git a/gui/src/redux/selectors/modelSelectors.ts b/gui/src/redux/selectors/modelSelectors.ts index 76be21563..0e831c4a8 100644 --- a/gui/src/redux/selectors/modelSelectors.ts +++ b/gui/src/redux/selectors/modelSelectors.ts @@ -1,11 +1,12 @@ -import { DEFAULT_MAX_TOKENS } from "core/llm/constants"; import { RootState } from "../store"; +import { createSelector } from "@reduxjs/toolkit"; -export const defaultModelSelector = (state: RootState) => { - const title = state.state.defaultModelTitle; - return state.state.config.models.find((model) => model.title === title); -}; - -export const contextLengthSelector = (state: RootState) => { - return defaultModelSelector(state)?.contextLength || DEFAULT_MAX_TOKENS; -}; +export const defaultModelSelector = createSelector( + [ + (store: RootState) => store.state.defaultModelTitle, + (store: RootState) => store.state.config.models, + ], + (defaultModelTitle, models) => { + return models?.find((model) => model.title === defaultModelTitle); + }, +); diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 71e26711d..a979d9b38 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -341,7 +341,7 @@ export const stateSlice = createSlice({ payload.rangeInFileWithContents.range.start.line + 1 }-${payload.rangeInFileWithContents.range.end.line + 1})`; contextItems.push({ - name: `${base} ${lineNums}`, + name: `${base} ${lineNums}s`, description: payload.rangeInFileWithContents.filepath, id: { providerTitle: "code", @@ -367,10 +367,7 @@ export const stateSlice = createSlice({ }; }, setSelectedProfileId: (state, { payload }: PayloadAction) => { - return { - ...state, - selectedProfileId: payload, - }; + state.selectedProfileId = payload; }, setCurCheckpointIndex: (state, { payload }: PayloadAction) => { state.curCheckpointIndex = payload; From f907812bd1b13e178512fddae17363cbf1f4848b Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 25 Nov 2024 00:30:01 -0800 Subject: [PATCH 2/4] fix initial config loading logic --- gui/src/App.tsx | 1 + gui/src/components/Layout.tsx | 64 ++++++++++--------- gui/src/context/SubmenuContextProviders.tsx | 7 +- gui/src/hooks/useSetup.ts | 71 ++++++++++++--------- gui/src/hooks/useWebviewListener.ts | 2 +- 5 files changed, 81 insertions(+), 64 deletions(-) diff --git a/gui/src/App.tsx b/gui/src/App.tsx index 646043629..ea5173db0 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -87,6 +87,7 @@ function SetupListeners() { } function App() { + console.log("app rendering"); return ( diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 2abfd9d47..6727fcd2c 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -75,28 +75,6 @@ const Layout = () => { (state: RootState) => state.uiState.showDialog, ); - const timeline = useSelector((state: RootState) => state.state.history); - - useEffect(() => { - const handleKeyDown = (event: any) => { - if (isMetaEquivalentKeyPressed(event) && event.code === "KeyC") { - const selection = window.getSelection()?.toString(); - if (selection) { - // Copy to clipboard - setTimeout(() => { - navigator.clipboard.writeText(selection); - }, 100); - } - } - }; - - window.addEventListener("keydown", handleKeyDown); - - return () => { - window.removeEventListener("keydown", handleKeyDown); - }; - }, [timeline]); - useWebviewListener( "openDialogMessage", async (message) => { @@ -211,14 +189,42 @@ const Layout = () => { [navigate], ); - useWebviewListener("setEditStatus", async ({ status, fileAfterEdit }) => { - dispatch(setEditStatus({ status, fileAfterEdit })); - }); + useWebviewListener( + "setEditStatus", + async ({ status, fileAfterEdit }) => { + dispatch(setEditStatus({ status, fileAfterEdit })); + }, + [], + ); - useWebviewListener("exitEditMode", async () => { - dispatch(setEditDone()); - navigate("/"); - }); + useWebviewListener( + "exitEditMode", + async () => { + dispatch(setEditDone()); + navigate("/"); + }, + [navigate], + ); + + useEffect(() => { + const handleKeyDown = (event: any) => { + if (isMetaEquivalentKeyPressed(event) && event.code === "KeyC") { + const selection = window.getSelection()?.toString(); + if (selection) { + // Copy to clipboard + setTimeout(() => { + navigator.clipboard.writeText(selection); + }, 100); + } + } + }; + + window.addEventListener("keydown", handleKeyDown); + + return () => { + window.removeEventListener("keydown", handleKeyDown); + }; + }, []); useEffect(() => { if ( diff --git a/gui/src/context/SubmenuContextProviders.tsx b/gui/src/context/SubmenuContextProviders.tsx index ba753cfe2..a2e3973eb 100644 --- a/gui/src/context/SubmenuContextProviders.tsx +++ b/gui/src/context/SubmenuContextProviders.tsx @@ -52,13 +52,14 @@ export const SubmenuContextProvidersProvider = ({ const contextProviderDescriptions = useSelector( selectContextProviderDescriptions, ); + const disableIndexing = useSelector( + (store: RootState) => store.state.config.disableIndexing, + ); const [initialLoadComplete, setInitialLoadComplete] = useState(false); const [isLoading, setIsLoading] = useState(false); const [autoLoadTriggered, setAutoLoadTriggered] = useState(false); - const config = useSelector((store: RootState) => store.state.config); - const ideMessenger = useContext(IdeMessengerContext); const getOpenFilesItems = useCallback(async () => { @@ -233,7 +234,7 @@ export const SubmenuContextProvidersProvider = ({ await Promise.all( contextProviderDescriptions.map(async (description) => { const shouldSkipProvider = - description.dependsOnIndexing && config.disableIndexing; + description.dependsOnIndexing && disableIndexing; if (shouldSkipProvider) { console.debug( diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 441ffa88e..c4d547ae4 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -25,47 +25,56 @@ function useSetup(dispatch: Dispatch) { const ideMessenger = useContext(IdeMessengerContext); const history = useSelector((store: RootState) => store.state.history); - const initialConfigLoad = useRef(false); - const loadConfig = useCallback(async () => { - const result = await ideMessenger.request( - "config/getSerializedProfileInfo", - undefined, - ); - if (result.status === "error") { - return; - } - const { config, profileId } = result.content; - dispatch(setConfig(config)); - dispatch(setSelectedProfileId(profileId)); - initialConfigLoad.current = true; - setLocalStorage("disableIndexing", config.disableIndexing || false); + const hasLoadedConfig = useRef(false); + const loadConfig = useCallback( + async (initial: boolean) => { + const result = await ideMessenger.request( + "config/getSerializedProfileInfo", + undefined, + ); + if (result.status === "error") { + return; + } + const { config, profileId } = result.content; + if (initial && hasLoadedConfig.current) { + return; + } + hasLoadedConfig.current = true; + dispatch(setConfig(config)); + dispatch(setSelectedProfileId(profileId)); - // Perform any actions needed with the config - if (config.ui?.fontSize) { - setLocalStorage("fontSize", config.ui.fontSize); - document.body.style.fontSize = `${config.ui.fontSize}px`; - } - }, [dispatch, ideMessenger, initialConfigLoad]); + // Perform any actions needed with the config + if (config.ui?.fontSize) { + setLocalStorage("fontSize", config.ui.fontSize); + document.body.style.fontSize = `${config.ui.fontSize}px`; + } + }, + [dispatch, ideMessenger, hasLoadedConfig], + ); // Load config from the IDE useEffect(() => { - loadConfig(); + loadConfig(true); const interval = setInterval(() => { - if (initialConfigLoad.current) { + if (hasLoadedConfig.current) { // This triggers sending pending status to the GUI for relevant docs indexes clearInterval(interval); ideMessenger.post("indexing/initStatuses", undefined); return; } - loadConfig(); + // loadConfig(true); }, 2_000); return () => clearInterval(interval); - }, [initialConfigLoad, loadConfig, ideMessenger]); + }, [hasLoadedConfig, loadConfig, ideMessenger]); - useWebviewListener("configUpdate", async () => { - await loadConfig(); - }); + useWebviewListener( + "configUpdate", + async () => { + await loadConfig(false); + }, + [loadConfig], + ); // Load symbols for chat on any session change const sessionId = useSelector((store: RootState) => store.state.sessionId); @@ -116,10 +125,6 @@ function useSetup(dispatch: Dispatch) { const { streamResponse } = useChatHandler(dispatch, ideMessenger); - const defaultModelTitle = useSelector( - (store: RootState) => store.state.defaultModelTitle, - ); - // IDE event listeners useWebviewListener( "getWebviewHistoryLength", @@ -170,6 +175,10 @@ function useSetup(dispatch: Dispatch) { dispatch(updateIndexingStatus(data)); }); + const defaultModelTitle = useSelector( + (store: RootState) => store.state.defaultModelTitle, + ); + useWebviewListener( "getDefaultModelTitle", async () => { diff --git a/gui/src/hooks/useWebviewListener.ts b/gui/src/hooks/useWebviewListener.ts index a710286c0..91d37ecb7 100644 --- a/gui/src/hooks/useWebviewListener.ts +++ b/gui/src/hooks/useWebviewListener.ts @@ -32,6 +32,6 @@ export function useWebviewListener( } }; }, - dependencies ? [...dependencies, skip] : [skip], + dependencies ? [...dependencies, skip, ideMessenger] : [skip, ideMessenger], ); } From 3711d7a2dc9bc659e474ad9f2fe29b6b1b5c64fb Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 25 Nov 2024 00:39:26 -0800 Subject: [PATCH 3/4] lag audit cleanup --- gui/src/App.tsx | 1 - gui/src/hooks/useSetup.ts | 2 +- gui/src/hooks/useSubmenuContextProviders.tsx | 0 gui/src/pages/gui/Chat.tsx | 2 -- gui/src/redux/slices/stateSlice.ts | 2 +- 5 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 gui/src/hooks/useSubmenuContextProviders.tsx diff --git a/gui/src/App.tsx b/gui/src/App.tsx index ea5173db0..646043629 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -87,7 +87,6 @@ function SetupListeners() { } function App() { - console.log("app rendering"); return ( diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index c4d547ae4..141e2b091 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -62,7 +62,7 @@ function useSetup(dispatch: Dispatch) { ideMessenger.post("indexing/initStatuses", undefined); return; } - // loadConfig(true); + loadConfig(true); }, 2_000); return () => clearInterval(interval); diff --git a/gui/src/hooks/useSubmenuContextProviders.tsx b/gui/src/hooks/useSubmenuContextProviders.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 3a38ca9c4..adea3ec80 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -139,8 +139,6 @@ export function Chat() { const { saveSession, getLastSessionId, loadLastSession } = useHistory(dispatch); - console.log("chat rendering"); - const snapToBottom = useCallback(() => { if (!stepsDivRef.current) return; const elem = stepsDivRef.current; diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index a979d9b38..296134087 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -341,7 +341,7 @@ export const stateSlice = createSlice({ payload.rangeInFileWithContents.range.start.line + 1 }-${payload.rangeInFileWithContents.range.end.line + 1})`; contextItems.push({ - name: `${base} ${lineNums}s`, + name: `${base} ${lineNums}`, description: payload.rangeInFileWithContents.filepath, id: { providerTitle: "code", From 5f3298555aca95b8762943be717beb3a3c9e05dd Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 27 Nov 2024 12:24:12 -0700 Subject: [PATCH 4/4] clean up --- gui/src/pages/edit/AddFileCombobox.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/src/pages/edit/AddFileCombobox.tsx b/gui/src/pages/edit/AddFileCombobox.tsx index 3750a448e..e219b01da 100644 --- a/gui/src/pages/edit/AddFileCombobox.tsx +++ b/gui/src/pages/edit/AddFileCombobox.tsx @@ -1,7 +1,7 @@ -import { useState, useContext, useEffect, useRef } from "react"; +import { useState, useEffect, useRef } from "react"; import { ContextSubmenuItemWithProvider, - SubmenuContextProvidersContext, + useSubmenuContextProviders, } from "../../context/SubmenuContextProviders"; import { Combobox } from "@headlessui/react"; import FileIcon from "../../components/FileIcon"; @@ -24,7 +24,7 @@ export default function AddFileCombobox({ const inputRef = useRef(null); const buttonRef = useRef(null); - const { getSubmenuContextItems } = useContext(SubmenuContextProvidersContext); + const { getSubmenuContextItems } = useSubmenuContextProviders(); const allFiles = getSubmenuContextItems("file", ""); const codeToEdit = useSelector( (state: RootState) => state.editModeState.codeToEdit,