From bded0d389c1db074d0fede0f99746589a0f98e68 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Tue, 29 Jul 2025 18:52:36 -0700 Subject: [PATCH] feat: add mercury-specific functions --- .../templating/mercuryCoderNextEdit.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 core/nextEdit/templating/mercuryCoderNextEdit.ts diff --git a/core/nextEdit/templating/mercuryCoderNextEdit.ts b/core/nextEdit/templating/mercuryCoderNextEdit.ts new file mode 100644 index 000000000..a7f79962b --- /dev/null +++ b/core/nextEdit/templating/mercuryCoderNextEdit.ts @@ -0,0 +1,63 @@ +import { Position, Range } from "../.."; +import { CODE_TO_EDIT_CLOSE, CODE_TO_EDIT_OPEN, CURSOR } from "../constants"; +import { insertCursorToken } from "./utils"; + +export function recentlyViewedCodeSnippetsBlock( + recentlyViewedCodeSnippets: { filepath: string; content: string }[], +) { + return [ + recentlyViewedCodeSnippets.reduce((acc, snippet) => { + const block = [ + `code_snippet_file_path: ${snippet.filepath}`, + snippet.content, + ].join("\n"); + + return acc + block; + }, ""), + ].join("\n"); +} + +export function currentFileContentBlock( + currentFileContent: string, + editableRegionStartLine: number, + editableRegionEndLine: number, + cursorPosition: Position, +) { + const currentFileContentLines = currentFileContent.split("\n"); + + const insertedCursorLines = insertCursorToken( + currentFileContentLines, + cursorPosition, + CURSOR, + ); + + const instrumentedLines = [ + ...insertedCursorLines.slice(0, editableRegionStartLine), + CODE_TO_EDIT_OPEN, + ...insertedCursorLines.slice( + editableRegionStartLine, + editableRegionEndLine + 1, + ), + CODE_TO_EDIT_CLOSE, + ...insertedCursorLines.slice(editableRegionEndLine + 1), + ]; + + return instrumentedLines.join("\n"); +} + +export function editHistoryBlock( + editDiffHistory: string, // could be a singe large unified diff +) { + return editDiffHistory; +} + +function mercuryNextEditTemplateBuilder( + recentlyViewedCodeSnippets: { filepath: string; code: string }[], + currentFileContent: string, + codeToEdit: string, + codeToEditRange: Range, + cursorPosition: Position, + editDiffHistory: string, // could be a singe large unified diff +): string { + return ""; +}