diff --git a/src/vs/workbench/contrib/void/browser/prompt/stringifyFiles.ts b/src/vs/workbench/contrib/void/browser/prompt/stringifyFiles.ts index 7cde3999..98d566e7 100644 --- a/src/vs/workbench/contrib/void/browser/prompt/stringifyFiles.ts +++ b/src/vs/workbench/contrib/void/browser/prompt/stringifyFiles.ts @@ -1,55 +1,25 @@ -import { URI } from '../../../../../base/common/uri.js'; +import { CodeSelection } from '../registerThreads.js'; +export const filesStr = (selections: CodeSelection[]) => { -export type LLMCodeSelection = { selectionStr: string; filePath: URI } -export type LLMFile = { content: string, filepath: URI } - -export const filesStr = (fullFiles: LLMFile[]) => { - return fullFiles.map(({ filepath, content }) => - ` -${filepath.fsPath} + return selections.map(({ fileURI, content, selectionStr }) => + `\ +File: ${fileURI.fsPath} \`\`\` ${content} -\`\`\``).join('\n') +\`\`\`${selectionStr === null ? '' : ` +Selection: ${selectionStr}`} +`).join('\n') } -export const userInstructionsStr = (instructions: string, files: LLMFile[], selection: LLMCodeSelection | null) => { +export const userInstructionsStr = (instructions: string, selections: CodeSelection[]) => { let str = ''; - - if (files.length > 0) { - str += filesStr(files); - } - - if (selection) { - str += ` -I am currently selecting this code: -\t\`\`\`${selection.selectionStr}\`\`\` -`; - } - - if (files.length > 0 && selection) { - str += ` -Please edit the selected code or the entire file following these instructions: -`; - } else if (files.length > 0) { - str += ` -Please edit the file following these instructions: -`; - } else if (selection) { - str += ` -Please edit the selected code following these instructions: -`; - } - - str += ` -\t${instructions} -`; - if (files.length > 0) { - str += ` -\tIf you make a change, rewrite the entire file. -`; // TODO don't rewrite the whole file on prompt, instead rewrite it when click Apply + if (selections.length > 0) { + str += filesStr(selections); + str += `Please edit the selected code following these instructions:\n` } + str += `${instructions}`; return str; }; diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index eefa19ba..8137a1e0 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -1,12 +1,12 @@ -import React, { FormEvent, useCallback, useRef, useState } from 'react'; +import React, { FormEvent, Fragment, useCallback, useRef, useState } from 'react'; import { useConfigState, useService, useThreadsState } from '../util/services.js'; -import { URI } from '../../../../../../../base/common/uri.js'; import { VSReadFile } from '../../../registerInlineDiffs.js'; import { sendLLMMessage } from '../util/sendLLMMessage.js'; import { generateDiffInstructions } from '../../../prompt/systemPrompts.js'; -import { LLMCodeSelection, userInstructionsStr } from '../../../prompt/stringifyFiles.js'; +import { userInstructionsStr } from '../../../prompt/stringifyFiles.js'; +import { CodeSelection, CodeStagingSelection } from '../../../registerThreads.js'; import { BlockCode } from '../markdown/BlockCode.js'; import { MarkdownRender } from '../markdown/MarkdownRender.js'; @@ -17,8 +17,7 @@ export type ChatMessage = role: 'user'; content: string; // content sent to the llm displayContent: string; // content displayed to user - selection: LLMCodeSelection | null; // the user's selection - files: URI[]; // the files sent in the message + selections: CodeSelection[] | null; // the user's selection } | { role: 'assistant'; @@ -40,37 +39,51 @@ const getBasename = (pathStr: string) => { return parts[parts.length - 1] } -export const SelectedFiles = ({ files, setFiles, }: { files: URI[]; setFiles: null | ((files: URI[]) => void) }) => { +export const SelectedFiles = ({ type, selections, setStagingSelns, }: + | { type: 'past', selections: CodeSelection[]; setStagingSelns?: undefined } + | { type: 'staging', selections: CodeStagingSelection[]; setStagingSelns: ((files: CodeStagingSelection[]) => void) } +) => { return ( - files.length !== 0 && ( + selections.length !== 0 && (