symbols bug fixes
This commit is contained in:
parent
98145ab406
commit
389b2c94c2
9 changed files with 76 additions and 56 deletions
|
|
@ -1,11 +1,12 @@
|
|||
import { PencilSquareIcon, TrashIcon } from "@heroicons/react/24/outline";
|
||||
import { SessionInfo } from "core";
|
||||
import React, { useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Input } from "..";
|
||||
import useHistory from "../../hooks/useHistory";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
import { RootState } from "../../redux/store";
|
||||
|
||||
function lastPartOfPath(path: string): string {
|
||||
const sep = path.includes("/") ? "/" : "\\";
|
||||
|
|
@ -29,6 +30,9 @@ export function HistoryTableRow({
|
|||
const [sessionTitleEditValue, setSessionTitleEditValue] = useState(
|
||||
session.title,
|
||||
);
|
||||
const currentSessionId = useSelector(
|
||||
(state: RootState) => state.state.sessionId,
|
||||
);
|
||||
|
||||
const { saveSession, deleteSession, loadSession, getSession, updateSession } =
|
||||
useHistory(dispatch);
|
||||
|
|
@ -59,8 +63,11 @@ export function HistoryTableRow({
|
|||
className="hover:bg-vsc-editor-background relative box-border flex max-w-full cursor-pointer overflow-hidden rounded-lg p-3"
|
||||
onClick={async () => {
|
||||
// Save current session
|
||||
await saveSession();
|
||||
await loadSession(session.sessionId);
|
||||
if (session.sessionId !== currentSessionId) {
|
||||
await saveSession();
|
||||
await loadSession(session.sessionId);
|
||||
}
|
||||
|
||||
navigate("/");
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import {
|
|||
setIsGatheringContext,
|
||||
updateFileSymbols,
|
||||
} from "../../redux/slices/stateSlice";
|
||||
import { updateFileSymbolsFromContextItems } from "../../util/symbols";
|
||||
|
||||
interface MentionAttrs {
|
||||
label: string;
|
||||
|
|
@ -174,23 +175,7 @@ async function resolveEditorContent(
|
|||
);
|
||||
contextItems.push(...defaultContextItems.flat());
|
||||
|
||||
const contextItemFileUris = Array.from(
|
||||
new Set(
|
||||
contextItems
|
||||
.filter((item) => item.uri?.type === "file" && item?.uri?.value)
|
||||
.map((item) => item.uri.value),
|
||||
),
|
||||
);
|
||||
|
||||
const symbolsResult = await ideMessenger.request(
|
||||
"context/getSymbolsForFiles",
|
||||
{
|
||||
uris: contextItemFileUris,
|
||||
},
|
||||
);
|
||||
if (symbolsResult.status === "success") {
|
||||
dispatch(updateFileSymbols(symbolsResult.content));
|
||||
}
|
||||
await updateFileSymbolsFromContextItems(contextItems, ideMessenger, dispatch);
|
||||
|
||||
if (contextItemsText !== "") {
|
||||
contextItemsText += "\n";
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ function FilenameLink({ rif }: FilenameLinkProps) {
|
|||
|
||||
return (
|
||||
<span
|
||||
className="mb-0.5 inline-flex cursor-pointer items-center gap-0.5 rounded-md py-0.5 pl-0 pr-1 align-middle hover:bg-stone-800"
|
||||
className="mb-[0.25em] inline-flex cursor-pointer items-center pr-[0.1em] align-middle hover:opacity-70"
|
||||
onClick={onClick}
|
||||
>
|
||||
<FileIcon filename={rif.filepath} height="20px" width="20px" />
|
||||
<span className="align-middle underline decoration-gray-600 underline-offset-2">
|
||||
<span className="align-middle underline underline-offset-2">
|
||||
{getBasename(rif.filepath)}
|
||||
</span>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -164,28 +164,18 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
// 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 symbolsForContextItems = useRef<SymbolWithRange[]>([]);
|
||||
const symbolsRef = useRef<SymbolWithRange[]>([]);
|
||||
const contextItemsRef = useRef<ContextItemWithId[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
contextItemsRef.current = contextItems || [];
|
||||
if (!contextItems) {
|
||||
symbolsForContextItems.current = [];
|
||||
}
|
||||
// Get unique URIs and then find relevant symbols
|
||||
const contextUris = Array.from(
|
||||
new Set(
|
||||
contextItems.filter((item) => item?.uri).map((item) => item.uri!.value),
|
||||
),
|
||||
);
|
||||
const contextSymbols: SymbolWithRange[] = [];
|
||||
contextUris.forEach((uri) => {
|
||||
const fileSymbols = symbols[uri];
|
||||
if (fileSymbols) {
|
||||
contextSymbols.push(...fileSymbols);
|
||||
}
|
||||
});
|
||||
symbolsForContextItems.current = contextSymbols;
|
||||
}, [contextItems, symbols]);
|
||||
}, [contextItems]);
|
||||
useEffect(() => {
|
||||
// Note, before I was only looking for symbols that matched
|
||||
// Context item files on current history item
|
||||
// but in practice global symbols for session makes way more sense
|
||||
symbolsRef.current = Object.values(symbols).flat();
|
||||
}, [symbols]);
|
||||
|
||||
const [reactContent, setMarkdownSource] = useRemark({
|
||||
remarkPlugins: [remarkMath, () => processCodeBlocks],
|
||||
|
|
@ -278,7 +268,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
return <FilenameLink rif={rif} />;
|
||||
}
|
||||
|
||||
const exactSymbol = symbolsForContextItems.current.find(
|
||||
const exactSymbol = symbolsRef.current.find(
|
||||
(s) => s.name === content,
|
||||
);
|
||||
if (exactSymbol) {
|
||||
|
|
@ -286,7 +276,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
}
|
||||
|
||||
// PARTIAL - this is the case where the llm returns e.g. `subtract(number)` instead of `subtract`
|
||||
const partialSymbol = symbolsForContextItems.current.find((s) =>
|
||||
const partialSymbol = symbolsRef.current.find((s) =>
|
||||
content.startsWith(s.name),
|
||||
);
|
||||
if (partialSymbol) {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ function SymbolLink({ symbol, content }: SymbolLinkProps) {
|
|||
|
||||
return (
|
||||
<span
|
||||
className="mb-0.5 inline-flex cursor-pointer items-center gap-0.5 rounded-md py-0.5 pl-0 align-middle hover:bg-stone-800"
|
||||
className="hover: mb-[0.25em] inline-flex cursor-pointer flex-row items-center gap-[0.2rem] align-middle hover:opacity-70"
|
||||
onClick={onClick}
|
||||
>
|
||||
<code className="align-middle underline decoration-gray-600 underline-offset-2">
|
||||
<code className="align-middle underline underline-offset-2">
|
||||
{content}
|
||||
</code>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ import { useSelector } from "react-redux";
|
|||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { useLastSessionContext } from "../context/LastSessionContext";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import { newSession } from "../redux/slices/stateSlice";
|
||||
import { newSession, updateFileSymbols } from "../redux/slices/stateSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
import { getLocalStorage, setLocalStorage } from "../util/localStorage";
|
||||
import { updateFileSymbolsFromContextItems } from "../util/symbols";
|
||||
|
||||
const MAX_TITLE_LENGTH = 100;
|
||||
|
||||
|
|
@ -22,7 +23,6 @@ function truncateText(text: string, maxLength: number) {
|
|||
|
||||
function useHistory(dispatch: Dispatch) {
|
||||
const state = useSelector((state: RootState) => state.state);
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { lastSessionId, setLastSessionId } = useLastSessionContext();
|
||||
|
||||
|
|
@ -122,7 +122,18 @@ function useHistory(dispatch: Dispatch) {
|
|||
if (result.status === "error") {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
|
||||
const persistedSessionInfo = result.content;
|
||||
|
||||
// Update file symbols on session load for all context items
|
||||
await updateFileSymbolsFromContextItems(
|
||||
persistedSessionInfo.history
|
||||
.map((item) => item.contextItems ?? [])
|
||||
.flat(),
|
||||
ideMessenger,
|
||||
dispatch,
|
||||
);
|
||||
|
||||
dispatch(newSession(persistedSessionInfo));
|
||||
return persistedSessionInfo;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ChatHistoryItem,
|
||||
ChatMessage,
|
||||
Checkpoint,
|
||||
ContextItemId,
|
||||
ContextItemWithId,
|
||||
FileSymbolMap,
|
||||
PersistedSessionInfo,
|
||||
|
|
@ -146,7 +145,6 @@ export const stateSlice = createSlice({
|
|||
state.mainEditorContent = undefined;
|
||||
},
|
||||
updateFileSymbols: (state, action: PayloadAction<FileSymbolMap>) => {
|
||||
console.log("UPDATE SYMBOLS", action.payload);
|
||||
state.symbols = Object.assign(state.symbols, action.payload);
|
||||
},
|
||||
setContextItemsAtIndex: (
|
||||
|
|
@ -379,7 +377,7 @@ export const stateSlice = createSlice({
|
|||
curApplyState.numDiffs = payload.numDiffs ?? curApplyState.numDiffs;
|
||||
curApplyState.filepath = payload.filepath ?? curApplyState.filepath;
|
||||
}
|
||||
if(payload.status === "done"){
|
||||
if (payload.status === "done") {
|
||||
state.nextCodeBlockToApplyIndex++;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -39,12 +39,7 @@ const windowIDTransform = (windowID: string) =>
|
|||
);
|
||||
|
||||
const saveSubsetFilters = [
|
||||
createFilter("state", [
|
||||
"history",
|
||||
"sessionId",
|
||||
"defaultModelTitle",
|
||||
"symbols",
|
||||
]),
|
||||
createFilter("state", ["history", "sessionId", "defaultModelTitle"]),
|
||||
];
|
||||
|
||||
const persistConfig = {
|
||||
|
|
|
|||
34
gui/src/util/symbols.ts
Normal file
34
gui/src/util/symbols.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { ContextItemWithId } from "core";
|
||||
import { IIdeMessenger } from "../context/IdeMessenger";
|
||||
import { updateFileSymbols } from "../redux/slices/stateSlice";
|
||||
import { Dispatch } from "@reduxjs/toolkit";
|
||||
|
||||
export async function updateFileSymbolsFromContextItems(
|
||||
contextItems: ContextItemWithId[],
|
||||
ideMessenger: IIdeMessenger,
|
||||
dispatch: Dispatch,
|
||||
) {
|
||||
// Given a list of context items,
|
||||
// Get unique file uris
|
||||
try {
|
||||
const contextUris = Array.from(
|
||||
new Set(
|
||||
contextItems
|
||||
.filter((item) => item.uri?.type === "file" && item?.uri?.value)
|
||||
.map((item) => item.uri.value),
|
||||
),
|
||||
);
|
||||
// And then update symbols for those files
|
||||
if (contextUris.length > 0) {
|
||||
const symbolsResult = await ideMessenger.request(
|
||||
"context/getSymbolsForFiles",
|
||||
{ uris: contextUris },
|
||||
);
|
||||
if (symbolsResult.status === "success") {
|
||||
dispatch(updateFileSymbols(symbolsResult.content));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error updating file symbols from context items", e);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue