Merge pull request #3061 from continuedev/dallin/lag-audit
Performance and redux audit
This commit is contained in:
commit
09db8cef25
20 changed files with 265 additions and 214 deletions
|
|
@ -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,21 +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 (
|
||||
<VscThemeContext.Provider value={vscTheme}>
|
||||
<SubmenuContextProvidersContext.Provider
|
||||
value={submenuContextProvidersMethods}
|
||||
>
|
||||
<VscThemeProvider>
|
||||
<SubmenuContextProvidersProvider>
|
||||
<RouterProvider router={router} />
|
||||
</SubmenuContextProvidersContext.Provider>
|
||||
</VscThemeContext.Provider>
|
||||
</SubmenuContextProvidersProvider>
|
||||
<SetupListeners />
|
||||
</VscThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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 useIsOSREnabled from "../../hooks/useIsOSREnabled";
|
||||
|
|
@ -170,7 +170,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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<SymbolWithRange[]>([]);
|
||||
const contextItemsRef = useRef<ContextItemWithId[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
contextItemsRef.current = contextItems || [];
|
||||
}, [contextItems]);
|
||||
useEffect(() => {
|
||||
// Note, before I was only looking for symbols that matched
|
||||
// Context item files on current history item
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
import { ContextSubmenuItem } from "core";
|
||||
import { createContext } from "react";
|
||||
|
||||
export interface ContextSubmenuItemWithProvider extends ContextSubmenuItem {
|
||||
providerTitle: string;
|
||||
}
|
||||
|
||||
export const SubmenuContextProvidersContext = createContext<{
|
||||
getSubmenuContextItems: (
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
) => ContextSubmenuItemWithProvider[];
|
||||
addItem: (providerTitle: string, item: ContextSubmenuItem) => void;
|
||||
}>({
|
||||
getSubmenuContextItems: () => [],
|
||||
addItem: () => {},
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { ContextSubmenuItem } from "core";
|
||||
import { WebviewMessengerResult } from "core/protocol/util";
|
||||
import { createContext } from "react";
|
||||
import {
|
||||
deduplicateArray,
|
||||
getBasename,
|
||||
|
|
@ -9,11 +9,10 @@ import {
|
|||
import MiniSearch, { SearchResult } from "minisearch";
|
||||
import { useCallback, useContext, useEffect, useMemo, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { IdeMessengerContext } from "./IdeMessenger";
|
||||
import { selectContextProviderDescriptions } from "../redux/selectors";
|
||||
import { getLocalStorage } from "../util/localStorage";
|
||||
import { useWebviewListener } from "./useWebviewListener";
|
||||
import { RootState } from "../redux/store";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
|
||||
const MINISEARCH_OPTIONS = {
|
||||
prefix: true,
|
||||
|
|
@ -22,7 +21,31 @@ const MINISEARCH_OPTIONS = {
|
|||
|
||||
const MAX_LENGTH = 70;
|
||||
|
||||
function useSubmenuContextProviders() {
|
||||
export interface ContextSubmenuItemWithProvider extends ContextSubmenuItem {
|
||||
providerTitle: string;
|
||||
}
|
||||
|
||||
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<SubtextContextProvidersContextType>(initialContextProviders);
|
||||
|
||||
export const SubmenuContextProvidersProvider = ({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) => {
|
||||
const [minisearches, setMinisearches] = useState<{
|
||||
[id: string]: MiniSearch;
|
||||
}>({});
|
||||
|
|
@ -33,33 +56,30 @@ function useSubmenuContextProviders() {
|
|||
const contextProviderDescriptions = useSelector(
|
||||
selectContextProviderDescriptions,
|
||||
);
|
||||
const disableIndexing = useSelector(
|
||||
(store: RootState) => store.state.config.disableIndexing,
|
||||
);
|
||||
|
||||
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);
|
||||
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",
|
||||
}));
|
||||
};
|
||||
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
|
||||
}
|
||||
|
|
@ -76,7 +96,7 @@ function useSubmenuContextProviders() {
|
|||
setMinisearches((prev) => ({ ...prev, [data.provider]: minisearch }));
|
||||
|
||||
if (data.provider === "file") {
|
||||
const openFiles = await memoizedGetOpenFileItems();
|
||||
const openFiles = await getOpenFilesItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: [
|
||||
|
|
@ -106,7 +126,7 @@ function useSubmenuContextProviders() {
|
|||
let isMounted = true;
|
||||
const refreshOpenFiles = async () => {
|
||||
if (!isMounted) return;
|
||||
const openFiles = await memoizedGetOpenFileItems();
|
||||
const openFiles = await getOpenFilesItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: deduplicateArray(
|
||||
|
|
@ -124,7 +144,7 @@ function useSubmenuContextProviders() {
|
|||
isMounted = false;
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, [memoizedGetOpenFileItems]);
|
||||
}, [getOpenFilesItems]);
|
||||
|
||||
const getSubmenuSearchResults = useMemo(
|
||||
() =>
|
||||
|
|
@ -208,10 +228,9 @@ function useSubmenuContextProviders() {
|
|||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (contextProviderDescriptions.length === 0 || loaded || isLoading) {
|
||||
if (contextProviderDescriptions.length === 0 || isLoading) {
|
||||
return;
|
||||
}
|
||||
setLoaded(true);
|
||||
setIsLoading(true);
|
||||
|
||||
const loadSubmenuItems = async () => {
|
||||
|
|
@ -219,7 +238,7 @@ function useSubmenuContextProviders() {
|
|||
await Promise.all(
|
||||
contextProviderDescriptions.map(async (description) => {
|
||||
const shouldSkipProvider =
|
||||
description.dependsOnIndexing && config.disableIndexing;
|
||||
description.dependsOnIndexing && disableIndexing;
|
||||
|
||||
if (shouldSkipProvider) {
|
||||
console.debug(
|
||||
|
|
@ -239,7 +258,7 @@ function useSubmenuContextProviders() {
|
|||
{
|
||||
title: description.title,
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
if (result.status === "error") {
|
||||
console.error(
|
||||
|
|
@ -258,7 +277,7 @@ function useSubmenuContextProviders() {
|
|||
}));
|
||||
|
||||
if (description.title === "file") {
|
||||
const openFiles = await memoizedGetOpenFileItems();
|
||||
const openFiles = await getOpenFilesItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: [
|
||||
|
|
@ -289,23 +308,20 @@ function useSubmenuContextProviders() {
|
|||
}
|
||||
};
|
||||
|
||||
loadSubmenuItems().catch((error) => {
|
||||
console.error("Error in loadSubmenuItems:", error);
|
||||
setInitialLoadComplete(true);
|
||||
setIsLoading(false);
|
||||
});
|
||||
}, [contextProviderDescriptions, loaded, autoLoadTriggered]);
|
||||
loadSubmenuItems();
|
||||
}, [contextProviderDescriptions, 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 (
|
||||
<SubmenuContextProvidersContext.Provider
|
||||
value={{
|
||||
getSubmenuContextItems,
|
||||
addItem,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</SubmenuContextProvidersContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
getSubmenuContextItems,
|
||||
addItem,
|
||||
};
|
||||
}
|
||||
|
||||
export default useSubmenuContextProviders;
|
||||
export const useSubmenuContextProviders = () =>
|
||||
useContext(SubmenuContextProvidersContext);
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { createContext } from "react";
|
||||
|
||||
export const VscThemeContext = createContext<any>(undefined);
|
||||
|
|
@ -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<string, string[]> = {
|
||||
".hljs-comment": ["comment"],
|
||||
|
|
@ -149,9 +149,24 @@ function fallbackTheme() {
|
|||
};
|
||||
}
|
||||
|
||||
export function useVscTheme() {
|
||||
const [theme, setTheme] = useState<any>(
|
||||
constructTheme(window.fullColorTheme || {}),
|
||||
interface VscThemeContextType {
|
||||
theme: Record<string, string>;
|
||||
}
|
||||
|
||||
const initialVscThemeContext: VscThemeContextType = {
|
||||
theme: constructTheme(window.fullColorTheme || {}),
|
||||
};
|
||||
export const VscThemeContext = createContext<VscThemeContextType>(
|
||||
initialVscThemeContext,
|
||||
);
|
||||
|
||||
export const VscThemeProvider = ({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) => {
|
||||
const [theme, setTheme] = useState<Record<string, string>>(
|
||||
initialVscThemeContext.theme,
|
||||
);
|
||||
|
||||
useWebviewListener("setTheme", async (data) => {
|
||||
|
|
@ -159,5 +174,11 @@ export function useVscTheme() {
|
|||
setTheme(constructTheme(data.theme));
|
||||
});
|
||||
|
||||
return theme;
|
||||
}
|
||||
return (
|
||||
<VscThemeContext.Provider value={{ theme }}>
|
||||
{children}
|
||||
</VscThemeContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useVscTheme = () => useContext(VscThemeContext);
|
||||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,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,
|
||||
|
|
@ -37,18 +37,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);
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
@ -16,9 +16,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";
|
||||
|
|
@ -27,33 +26,38 @@ 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) {
|
||||
// Docs init on config load
|
||||
ideMessenger.post("docs/getSuggestedDocs", undefined);
|
||||
ideMessenger.post("docs/initStatuses", undefined);
|
||||
|
|
@ -62,15 +66,19 @@ function useSetup(dispatch: Dispatch) {
|
|||
clearInterval(interval);
|
||||
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);
|
||||
|
|
@ -125,10 +133,6 @@ function useSetup(dispatch: Dispatch) {
|
|||
|
||||
const { streamResponse } = useChatHandler(dispatch, ideMessenger);
|
||||
|
||||
const defaultModelTitle = useSelector(
|
||||
(store: RootState) => store.state.defaultModelTitle,
|
||||
);
|
||||
|
||||
// IDE event listeners
|
||||
useWebviewListener(
|
||||
"getWebviewHistoryLength",
|
||||
|
|
@ -179,6 +183,10 @@ function useSetup(dispatch: Dispatch) {
|
|||
dispatch(updateIndexingStatus(data));
|
||||
});
|
||||
|
||||
const defaultModelTitle = useSelector(
|
||||
(store: RootState) => store.state.defaultModelTitle,
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"getDefaultModelTitle",
|
||||
async () => {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,6 @@ export function useWebviewListener<T extends keyof ToWebviewProtocol>(
|
|||
}
|
||||
};
|
||||
},
|
||||
dependencies ? [...dependencies, skip] : [skip],
|
||||
dependencies ? [...dependencies, skip, ideMessenger] : [skip, ideMessenger],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<HTMLInputElement>(null);
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const { getSubmenuContextItems } = useContext(SubmenuContextProvidersContext);
|
||||
const { getSubmenuContextItems } = useSubmenuContextProviders();
|
||||
const allFiles = getSubmenuContextItems("file", "");
|
||||
const codeToEdit = useSelector(
|
||||
(state: RootState) => state.editModeState.codeToEdit,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
|
|
@ -131,7 +132,10 @@ export function Chat() {
|
|||
const mainTextInputRef = useRef<HTMLInputElement>(null);
|
||||
const stepsDivRef = useRef<HTMLDivElement>(null);
|
||||
const [isAtBottom, setIsAtBottom] = useState<boolean>(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);
|
||||
|
||||
|
|
@ -289,7 +293,7 @@ export function Chat() {
|
|||
setLocalStorage("mainTextEntryCounter", 1);
|
||||
}
|
||||
},
|
||||
[state.history, defaultModel, state, streamResponse],
|
||||
[history, defaultModel, streamResponse],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
|
|
@ -303,26 +307,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}
|
||||
<StepsDiv
|
||||
ref={stepsDivRef}
|
||||
className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${state.history.length > 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) => (
|
||||
<Fragment key={item.message.id}>
|
||||
<ErrorBoundary
|
||||
FallbackComponent={fallbackRender}
|
||||
|
|
@ -368,7 +373,7 @@ export function Chat() {
|
|||
>
|
||||
<StepContainer
|
||||
index={index}
|
||||
isLast={index === state.history.length - 1}
|
||||
isLast={index === history.length - 1}
|
||||
item={item}
|
||||
/>
|
||||
</TimelineItem>
|
||||
|
|
@ -421,7 +426,7 @@ export function Chat() {
|
|||
>
|
||||
<div className="flex flex-row items-center justify-between pb-1 pl-0.5 pr-2">
|
||||
<div className="xs:inline hidden">
|
||||
{state.history.length === 0 && getLastSessionId() ? (
|
||||
{history.length === 0 && getLastSessionId() ? (
|
||||
<div className="xs:inline hidden">
|
||||
<NewSessionButton
|
||||
onClick={async () => {
|
||||
|
|
@ -440,7 +445,7 @@ export function Chat() {
|
|||
<ConfigErrorIndicator />
|
||||
</div>
|
||||
|
||||
{state.history.length === 0 && (
|
||||
{history.length === 0 && (
|
||||
<>
|
||||
{onboardingCard.show && (
|
||||
<div className="mx-2 mt-10">
|
||||
|
|
@ -458,7 +463,7 @@ export function Chat() {
|
|||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={`${state.history.length === 0 ? "h-full" : ""} flex flex-col justify-end`}
|
||||
className={`${history.length === 0 ? "h-full" : ""} flex flex-col justify-end`}
|
||||
>
|
||||
<ChatIndexingPeeks />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -370,10 +370,7 @@ export const stateSlice = createSlice({
|
|||
};
|
||||
},
|
||||
setSelectedProfileId: (state, { payload }: PayloadAction<string>) => {
|
||||
return {
|
||||
...state,
|
||||
selectedProfileId: payload,
|
||||
};
|
||||
state.selectedProfileId = payload;
|
||||
},
|
||||
setCurCheckpointIndex: (state, { payload }: PayloadAction<number>) => {
|
||||
state.curCheckpointIndex = payload;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue