Skip to content

Commit

Permalink
symbols working for codeblock toolbars
Browse files Browse the repository at this point in the history
  • Loading branch information
RomneyDa committed Jan 3, 2025
1 parent 38db234 commit 5b31f75
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
28 changes: 2 additions & 26 deletions gui/src/components/markdown/StyledMarkdownPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { selectUIConfig } from "../../redux/slices/configSlice";
import { ToolTip } from "../gui/Tooltip";
import { v4 as uuidv4 } from "uuid";
import { ContextItemWithId, RangeInFileWithContents } from "core";
import { getContextItemsFromHistory } from "../../redux/thunks/updateFileSymbols";

const StyledMarkdown = styled.div<{
fontSize?: number;
Expand Down Expand Up @@ -154,32 +155,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
rifs: [],
};
}
const pastHistoryItems = history.filter((_, i) => i <= index);

const pastNormalContextItems = pastHistoryItems.flatMap((item) => {
return (
item.contextItems?.filter(
(item) => item.uri?.type === "file" && item.uri?.value,
) ?? []
);
});

const pastToolbarContextItems: ContextItemWithId[] = pastHistoryItems
.filter((item) => item.editorState && Array.isArray(item.editorState))
.flatMap((item) => item.editorState)
.filter(
(content) =>
content?.type === "codeBlock" &&
content?.attrs?.item &&
content.attrs.item.uri?.type === "file" &&
content.attrs.item.uri?.value,
)
.map((content) => content.attrs!.item!);

const pastContextItems = [
...pastNormalContextItems,
...pastToolbarContextItems,
];
const pastContextItems = getContextItemsFromHistory(history, index);
const rifs = pastContextItems.map((item) =>
ctxItemToRifWithContents(item, true),
);
Expand Down
38 changes: 34 additions & 4 deletions gui/src/redux/thunks/updateFileSymbols.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
import { ThunkApiType } from "../store";
import { updateFileSymbols } from "../slices/sessionSlice";
import { ContextItemWithId, RangeInFile } from "core";
import { ChatHistoryItem, ContextItemWithId } from "core";

export function getContextItemsFromHistory(
historyItems: ChatHistoryItem[],
priorToIndex?: number,
) {
const pastHistoryItems = historyItems.filter(
(_, i) => i <= (priorToIndex ?? historyItems.length - 1),
);

const pastNormalContextItems = pastHistoryItems.flatMap((item) => {
return (
item.contextItems?.filter(
(item) => item.uri?.type === "file" && item.uri?.value,
) ?? []
);
});
const pastToolbarContextItems: ContextItemWithId[] = pastHistoryItems
.filter(
(item) => item.editorState && Array.isArray(item.editorState.content),
)
.flatMap((item) => item.editorState.content)
.filter(
(content) =>
content?.type === "codeBlock" &&
content?.attrs?.item?.uri?.value &&
content.attrs.item.uri?.type === "file",
)
.map((content) => content.attrs!.item!);

return [...pastNormalContextItems, ...pastToolbarContextItems];
}

/*
Get file symbols for given context items
Expand Down Expand Up @@ -48,9 +79,8 @@ export const updateFileSymbolsFromHistory = createAsyncThunk<
const state = getState();

// Get unique context item file uris from all history
const contextItems = state.session.history.flatMap(
(item) => item.contextItems,
);
const contextItems = getContextItemsFromHistory(state.session.history);

const uniqueUris = new Set(
contextItems
.filter((item) => item.uri?.type === "file" && item?.uri?.value)
Expand Down

0 comments on commit 5b31f75

Please sign in to comment.