diff --git a/extensions/void/src/common/sendLLMMessage.ts b/extensions/void/src/common/sendLLMMessage.ts index c0e1a8b4..9e47a80a 100644 --- a/extensions/void/src/common/sendLLMMessage.ts +++ b/extensions/void/src/common/sendLLMMessage.ts @@ -64,14 +64,9 @@ const sendClaudeMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinal const anthropic = new Anthropic({ apiKey: apiConfig.anthropic.apikey, dangerouslyAllowBrowser: true }); // defaults to process.env["ANTHROPIC_API_KEY"] - console.log('max_tokens:' + apiConfig.anthropic.maxTokens) - - let max_tokens = parseInt(apiConfig.anthropic.maxTokens) - if (isNaN(max_tokens)) { max_tokens = 4000 } // TODO make a default max_tokens - const stream = anthropic.messages.stream({ model: apiConfig.anthropic.model, - max_tokens: max_tokens, + max_tokens: parseInt(apiConfig.anthropic.maxTokens), messages: messages, }); @@ -226,8 +221,6 @@ const sendGreptileMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFin export const sendLLMMessage: SendLLMMessageFnTypeExternal = ({ messages, onText, onFinalMessage, apiConfig }) => { if (!apiConfig) return { abort: () => { } } - console.log(`void: sending LLMMessage to ${apiConfig.whichApi}`) - const whichApi = apiConfig.whichApi if (whichApi === 'anthropic') { diff --git a/extensions/void/src/extension.ts b/extensions/void/src/extension.ts index aa5a69d1..2a89a9e9 100644 --- a/extensions/void/src/extension.ts +++ b/extensions/void/src/extension.ts @@ -7,7 +7,7 @@ import { ApiConfig } from './common/sendLLMMessage'; const readFileContentOfUri = async (uri: vscode.Uri) => { return Buffer.from(await vscode.workspace.fs.readFile(uri)).toString('utf8') - .replace(/\r\n/g, '\n') // must remove windows \r or every line will appear different because of it + .replace(/\r\n/g, '\n') // replace windows \r\n with \n } @@ -57,7 +57,7 @@ export function activate(context: vscode.ExtensionContext) { // vscode.commands.executeCommand('vscode.moveViewToPanel', CustomViewProvider.viewId); // move to aux bar // get the text the user is selecting - const selectionStr = editor.document.getText(editor.selection); 5 + const selectionStr = editor.document.getText(editor.selection); // get the range of the selection const selectionRange = editor.selection; @@ -72,7 +72,6 @@ export function activate(context: vscode.ExtensionContext) { // 3. Show an approve/reject codelens above each change const displayChangesProvider = new DisplayChangesProvider(); - console.log(`void: Creating DisplayChangesProvider`) context.subscriptions.push(vscode.languages.registerCodeLensProvider('*', displayChangesProvider)); // 4. Add approve/reject commands diff --git a/extensions/void/src/findDiffs.ts b/extensions/void/src/findDiffs.ts index eafa5143..ee432200 100644 --- a/extensions/void/src/findDiffs.ts +++ b/extensions/void/src/findDiffs.ts @@ -174,3 +174,104 @@ export const findDiffs = (oldText: string, newText: string): BaseDiff[] => { // } + + + + + + + + + + +// import { diffLines, Change } from 'diff'; + +// export type SuggestedEdit = { +// // start/end of current file +// startLine: number; +// endLine: number; + +// // start/end of original file +// originalStartLine: number, +// originalEndLine: number, + +// // original content (originalfile[originalStart...originalEnd]) +// originalContent: string; +// newContent: string; +// } + +// export function getDiffedLines(oldStr: string, newStr: string) { +// // an ordered list of every original line, line added to the new file, and line removed from the old file (order is unambiguous, think about it) +// const lineByLineChanges: Change[] = diffLines(oldStr, newStr); +// console.debug('Line by line changes', lineByLineChanges) + +// lineByLineChanges.push({ value: '' }) // add a dummy so we flush any streaks we haven't yet at the very end (!line.added && !line.removed) + +// let oldFileLineNum: number = 0; +// let newFileLineNum: number = 0; + +// let streakStartInNewFile: number | undefined = undefined +// let streakStartInOldFile: number | undefined = undefined + +// let oldStrLines = oldStr.split('\n') +// let newStrLines = newStr.split('\n') + +// const replacements: SuggestedEdit[] = [] + +// for (let line of lineByLineChanges) { +// // no change on this line +// if (!line.added && !line.removed) { +// // if we were on a streak, add it +// if (streakStartInNewFile !== undefined) { + +// const startLine = streakStartInNewFile +// const endLine = newFileLineNum - 1 // don't include current line, the edit was up to this line but not including it +// const newContent = newStrLines.slice(startLine, endLine + 1).join('\n') + +// const originalStartLine = streakStartInOldFile! +// const originalEndLine = oldFileLineNum - 1 // don't include current line, the edit was up to this line but not including it +// const originalContent = oldStrLines.slice(originalStartLine, originalEndLine + 1).join('\n') + +// const replacement: SuggestedEdit = { startLine, endLine, newContent, originalStartLine, originalEndLine, originalContent } + +// replacements.push(replacement) +// streakStartInNewFile = undefined +// streakStartInOldFile = undefined +// } + +// oldFileLineNum += line.count ?? 0; +// newFileLineNum += line.count ?? 0; +// } + + +// // line was removed from old file +// else if (line.removed) { + +// // if we weren't on a streak, start one on this current line num +// if (streakStartInNewFile === undefined) { +// streakStartInNewFile = newFileLineNum +// streakStartInOldFile = oldFileLineNum +// } + +// oldFileLineNum += line.count ?? 0 // we processed the line so add 1 +// } + +// // line was added to new file +// else if (line.added) { + +// // if we weren't on a streak, start one on this current line num +// if (streakStartInNewFile === undefined) { +// streakStartInNewFile = newFileLineNum +// streakStartInOldFile = oldFileLineNum +// } + +// newFileLineNum += line.count ?? 0; // we processed the line so add 1 +// } + +// } // end for + +// console.debug('Replacements', replacements) + +// return replacements + +// } \ No newline at end of file diff --git a/extensions/void/src/sidebar/Sidebar.tsx b/extensions/void/src/sidebar/Sidebar.tsx index cfa8d3a7..82e633c1 100644 --- a/extensions/void/src/sidebar/Sidebar.tsx +++ b/extensions/void/src/sidebar/Sidebar.tsx @@ -186,13 +186,10 @@ const Sidebar = () => { const formRef = useRef(null) - const onSubmit = async (e: FormEvent) => { - console.log(`11111`) e.preventDefault() if (isLoading) return - console.log(`2222222`) setIsLoading(true) setInstructions(''); @@ -200,14 +197,9 @@ const Sidebar = () => { setSelection(null) setFiles([]) - - console.log(`AAAAAA`) - // request file content from vscode and await response getVSCodeAPI().postMessage({ type: 'requestFiles', filepaths: files }) - console.log(`BBBBB`) const relevantFiles = await awaitVSCodeResponse('files') - console.log(`CCCCCC`) // add message to chat history const content = userInstructionsStr(instructions, relevantFiles.files, selection) @@ -216,7 +208,6 @@ const Sidebar = () => { setChatHistory(chatMessageHistory => [...chatMessageHistory, newHistoryElt]) // send message to LLM - console.log(`DDDDD`) let { abort } = sendLLMMessage({ messages: [...chatMessageHistory.map(m => ({ role: m.role, content: m.content })), { role: 'user', content }], onText: (newText, fullText) => setMessageStream(fullText), @@ -232,9 +223,7 @@ const Sidebar = () => { }, apiConfig: apiConfig }) - console.log(`EEEEE`) abortFnRef.current = abort - console.log(`FFFF`) }