diff --git a/core/context/index.ts b/core/context/index.ts index e93d28593..dff6a563b 100644 --- a/core/context/index.ts +++ b/core/context/index.ts @@ -16,6 +16,10 @@ export abstract class ContextProvider { static description: ContextProviderDescription; + get description(): ContextProviderDescription { + return (this.constructor as any).description; + } + // Maybe just include the chat message in here. Should never have to go back to the context provider once you have the information. abstract getContextItems(query: string): Promise; diff --git a/core/context/providers/DiffContextProvider.ts b/core/context/providers/DiffContextProvider.ts index fe2369a69..efcfbaff9 100644 --- a/core/context/providers/DiffContextProvider.ts +++ b/core/context/providers/DiffContextProvider.ts @@ -1,3 +1,4 @@ +import { v4 } from "uuid"; import { ContextProvider, ContextProviderDescription } from ".."; import { ExtensionIde } from "../../ide"; import { ContextItem } from "../../llm/types"; @@ -12,7 +13,18 @@ class DiffContextProvider extends ContextProvider { }; async getContextItems(query: string): Promise { - return [await new ExtensionIde().getDiff()]; + const diff = await new ExtensionIde().getDiff(); + return [ + { + description: "The current git diff", + content: diff, + name: "Git Diff", + id: { + providerTitle: "diff", + itemId: v4(), + }, + }, + ]; } async load(): Promise {} } diff --git a/core/context/providers/TerminalContextProvider.ts b/core/context/providers/TerminalContextProvider.ts index e4c417c9a..fe4431dff 100644 --- a/core/context/providers/TerminalContextProvider.ts +++ b/core/context/providers/TerminalContextProvider.ts @@ -1,3 +1,4 @@ +import { v4 } from "uuid"; import { ContextProvider, ContextProviderDescription } from ".."; import { ExtensionIde } from "../../ide"; import { ContextItem } from "../../llm/types"; @@ -12,7 +13,18 @@ class TerminalContextProvider extends ContextProvider { }; async getContextItems(query: string): Promise { - return [await new ExtensionIde().getTerminalContents()]; + const content = await new ExtensionIde().getTerminalContents(); + return [ + { + description: "The contents of the terminal", + content, + name: "Terminal", + id: { + providerTitle: "terminal", + itemId: v4(), + }, + }, + ]; } async load(): Promise {} } diff --git a/core/ide/index.ts b/core/ide/index.ts index b2686ca6e..8ff8b3f04 100644 --- a/core/ide/index.ts +++ b/core/ide/index.ts @@ -40,7 +40,7 @@ export class ExtensionIde implements IDE { } async showVirtualFile(title: string, contents: string): Promise { - await r("showVirtualFile", { title, contents }); + await r("showVirtualFile", { name: title, content: contents }); } async openFile(path: string): Promise { diff --git a/extensions/vscode/src/continueIdeClient.ts b/extensions/vscode/src/continueIdeClient.ts index 7fcf060da..ffdc0d49d 100644 --- a/extensions/vscode/src/continueIdeClient.ts +++ b/extensions/vscode/src/continueIdeClient.ts @@ -1,28 +1,26 @@ +import * as io from "socket.io-client"; +import { v4 } from "uuid"; +import * as vscode from "vscode"; +import { FileEdit } from "../schema/FileEdit"; +import { FileEditWithFullContents } from "../schema/FileEditWithFullContents"; +import { RangeInFile } from "../schema/RangeInFile"; +import { windowId } from "./activation/activate"; +import { debugPanelWebview, getSidebarContent } from "./debugPanel"; +import { diffManager } from "./diffs"; import { - editorSuggestionsLocked, - showSuggestion as showSuggestionInEditor, SuggestionRanges, + acceptSuggestionCommand, + editorSuggestionsLocked, + rejectSuggestionCommand, + showSuggestion as showSuggestionInEditor, } from "./suggestions"; import { getUniqueId, openEditorAndRevealRange, uriFromFilePath, } from "./util/vscode"; -import { FileEdit } from "../schema/FileEdit"; -import { RangeInFile } from "../schema/RangeInFile"; -import * as vscode from "vscode"; -import { - acceptSuggestionCommand, - rejectSuggestionCommand, -} from "./suggestions"; -import { FileEditWithFullContents } from "../schema/FileEditWithFullContents"; -import { diffManager } from "./diffs"; const os = require("os"); const path = require("path"); -import { v4 } from "uuid"; -import { windowId } from "./activation/activate"; -import * as io from "socket.io-client"; -import { debugPanelWebview, getSidebarContent } from "./debugPanel"; const continueVirtualDocumentScheme = "continue"; @@ -322,7 +320,7 @@ class IdeProtocolClient { } break; case "showVirtualFile": - this.showVirtualFile(data.name, data.contents); + this.showVirtualFile(data.name, data.content); break; case "setSuggestionsLocked": this.setSuggestionsLocked(data.filepath, data.locked); @@ -780,7 +778,7 @@ class IdeProtocolClient { return ""; } - return repo.getDiff().join("\n"); + return (await repo.getDiff()).join("\n"); } getHighlightedCode(): RangeInFile[] { diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index bf109302e..1f5acfa79 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -266,7 +266,7 @@ export function getSidebarContent( break; } case "showVirtualFile": { - respond(await ide.showVirtualFile(data.title, data.contents)); + respond(await ide.showVirtualFile(data.name, data.content)); break; } case "getContinueDir": { diff --git a/gui/src/components/mainInput/ComboBox.tsx b/gui/src/components/mainInput/ComboBox.tsx index 855816eb9..bc1bb0ba2 100644 --- a/gui/src/components/mainInput/ComboBox.tsx +++ b/gui/src/components/mainInput/ComboBox.tsx @@ -340,7 +340,7 @@ const Li = styled.li<{ background-color: ${({ highlighted }) => highlighted ? buttonColor + "66" : "transparent"}; ${({ selected }) => selected && "font-weight: bold;"} - padding: 0.5rem 0.25rem; + padding: 0.35rem 0.5rem; display: flex; flex-direction: row; align-items: center; @@ -352,7 +352,7 @@ const Li = styled.li<{ // #endregion interface ComboBoxItem { - name: string; + title: string; description: string; id?: string; content?: string; @@ -423,7 +423,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { (state: RootStore) => state.state.config.slashCommands?.map((cmd) => { return { - name: `/${cmd.name}`, + title: `/${cmd.name}`, description: cmd.description, }; }) || [] @@ -446,8 +446,8 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { }, [currentlyInContextQuery]); const contextProviders = useSelector( - (state: RootStore) => state.state.config.contextProviders - ) as any[]; + (store: RootStore) => store.state.config.contextProviders + ); const goBackToContextProviders = () => { setCurrentlyInContextQuery(false); @@ -461,9 +461,9 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { setItems( contextProviders ?.map((provider) => ({ - name: provider.display_title, - description: provider.description, - id: provider.title, + title: provider.description.displayTitle, + description: provider.description.description, + id: provider.description.title, })) .sort((c, _) => (c.id === "file" ? -1 : 1)) || [] ); @@ -504,7 +504,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { // Hacky way of stopping bug where first context provider title is injected into input if ( prevInputValue === "" && - contextProviders?.some((p) => p.display_title === inputValue) + contextProviders?.some((p) => p.description.displayTitle === inputValue) ) { downshiftProps.setInputValue(""); setPrevInputValue(""); @@ -545,20 +545,21 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { contextProviders ?.filter( (provider) => - `@${provider.title}` + `@${provider.description.title}` .toLowerCase() .startsWith(inputValue.toLowerCase()) || - `@${provider.display_title}` + `@${provider.description.displayTitle}` .toLowerCase() .startsWith(inputValue.toLowerCase()) ) .map((provider) => ({ - name: provider.display_title, - description: provider.description, - id: provider.title, + name: provider.description.displayTitle, + description: provider.description.description, + id: provider.description.title, + title: provider.description.displayTitle, })) .sort((c, _) => (c.id === "file" ? -1 : 1)) || []; - setItems(filteredItems); + setItems(filteredItems.map((item) => item)); setCurrentlyInContextQuery(true); } return; @@ -574,7 +575,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { // Handle slash commands setItems( availableSlashCommands?.filter((slashCommand) => { - const sc = slashCommand.name.toLowerCase(); + const sc = slashCommand.title.toLowerCase(); const iv = inputValue.toLowerCase(); return sc.startsWith(iv) && sc !== iv; }) || [] @@ -610,7 +611,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { return ( res?.hits.map((hit) => { return { - name: hit.name, + title: hit.name, description: hit.description, id: hit.id, content: hit.content, @@ -627,7 +628,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { onInputValueChange: onInputValueChangeCallback, items, itemToString(item) { - return item ? item.name : ""; + return item ? item.title : ""; }, }); @@ -775,9 +776,9 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { const selectContextItemFromDropdown = useCallback( (event: any) => { const newItem = items[downshiftProps.highlightedIndex]; - const newProviderName = newItem?.name; + const newProviderName = newItem?.title; const newProvider = contextProviders.find( - (provider) => provider.display_title === newProviderName + (provider) => provider.description.displayTitle === newProviderName ); if (!newProvider) { @@ -798,14 +799,17 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { (event.nativeEvent as any).preventDownshiftDefault = true; event.preventDefault(); return; - } else if (newProvider.dynamic && newProvider.requires_query) { + } else if ( + newProvider.description.dynamic && + newProvider.description.requiresQuery + ) { // This is a dynamic context provider that requires a query, like URL / Search setInQueryForContextProvider(newProvider); - downshiftProps.setInputValue(`@${newProvider.title} `); + downshiftProps.setInputValue(`@${newProvider.description.title} `); (event.nativeEvent as any).preventDownshiftDefault = true; event.preventDefault(); return; - } else if (newProvider.dynamic) { + } else if (newProvider.description.dynamic) { // This is a normal dynamic context provider like Diff or Terminal if (!newItem.id) return; @@ -817,11 +821,11 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { selectContextItem(newItem.id, query); if (downshiftProps.inputValue.includes("@")) { const selectedNestedContextProvider = contextProviders.find( - (provider) => provider.title === newItem.id + (provider) => provider.description.title === newItem.id ); if ( !nestedContextProvider && - !selectedNestedContextProvider?.dynamic + !selectedNestedContextProvider?.description.dynamic ) { downshiftProps.setInputValue(`@${newItem.id} `); setNestedContextProvider(selectedNestedContextProvider); @@ -841,12 +845,13 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { } setNestedContextProvider(newProvider); - downshiftProps.setInputValue(`@${newProvider.title} `); + downshiftProps.setInputValue(`@${newProvider.description.title} `); (event.nativeEvent as any).preventDownshiftDefault = true; event.preventDefault(); - getFilteredContextItemsForProvider(newProvider.title, "").then((items) => - setItems(items) - ); + getFilteredContextItemsForProvider( + newProvider.description.title, + "" + ).then((items) => setItems(items)); }, [ items, @@ -1300,9 +1305,9 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { event.key === "Tab" && downshiftProps.isOpen && items.length > 0 && - items[downshiftProps.highlightedIndex]?.name.startsWith("/") + items[downshiftProps.highlightedIndex]?.title.startsWith("/") ) { - downshiftProps.setInputValue(items[0].name); + downshiftProps.setInputValue(items[0].title); event.preventDefault(); } else if (event.key === "Tab") { (event.nativeEvent as any).preventDownshiftDefault = true; @@ -1584,7 +1589,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { borderTop: index === 0 ? "none" : `0.5px solid ${lightGray}`, }} - key={`${item.name}${index}`} + key={`${item.title}${index}`} {...downshiftProps.getItemProps({ item, index })} highlighted={downshiftProps.highlightedIndex === index} selected={downshiftProps.selectedItem === item} @@ -1601,12 +1606,12 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { )} - + - {item.name} + {item.title} {" "} { {contextProviders ?.filter( - (provider) => !provider.dynamic || provider.requires_query + (provider) => + !provider.description.dynamic || + provider.description.requiresQuery ) - .find((provider) => provider.title === item.id) && ( + .find( + (provider) => provider.description.title === item.id + ) && ( ({}); - const [providerDescriptions, setProviderDescriptions] = useState< - ContextProviderDescription[] - >([]); - - const providerConfig = useSelector( - (store: RootStore) => store.state.config.contextProviders || [] + const contextProviders = useSelector( + (state: RootStore) => state.state.config.contextProviders || [] ); - useEffect(() => { - let providersList = []; - let descriptionsList = []; - for (const [name, options] of Object.entries(providerConfig)) { - const provider = contextProviderClassFromName( - name as ContextProviderName - ); - if (!provider) continue; - providersList.push((provider as any)(options)); - descriptionsList.push(provider.description); - } - - setProviders(providers); - setProviderDescriptions(descriptionsList); - }, [providerConfig]); - async function getContextItems( name: string, query: string ): Promise { - const provider = providers[name]; + const provider = contextProviders.find((p) => p.description.title === name); if (!provider) { throw new Error(`Unknown provider ${name}`); } return await provider.getContextItems(query); } - return { providerDescriptions, getContextItems }; + return { getContextItems }; } export default useContextProviders;