Elffuss BraidHub

kikocis/continue public

4940c71be2bf · 1.7 KiBRawPermalink
1import { Position, Range } from "../..";
2import { CODE_TO_EDIT_CLOSE, CODE_TO_EDIT_OPEN, CURSOR } from "../constants";
3import { insertCursorToken } from "./utils";
4
5export function recentlyViewedCodeSnippetsBlock(
6 recentlyViewedCodeSnippets: { filepath: string; content: string }[],
7) {
8 return recentlyViewedCodeSnippets.reduce((acc, snippet, i) => {
9 const block = [
10 `code_snippet_file_path: ${snippet.filepath}`,
11 snippet.content,
12 ].join("\n");
13
14 return (
15 acc + block + (i === recentlyViewedCodeSnippets.length - 1 ? "" : "\n")
16 );
17 }, "");
18}
19
20export function currentFileContentBlock(
21 currentFileContent: string,
22 editableRegionStartLine: number,
23 editableRegionEndLine: number,
24 cursorPosition: Position,
25) {
26 const currentFileContentLines = currentFileContent.split("\n");
27
28 const insertedCursorLines = insertCursorToken(
29 currentFileContentLines,
30 cursorPosition,
31 CURSOR,
32 );
33
34 const instrumentedLines = [
35 ...insertedCursorLines.slice(0, editableRegionStartLine),
36 CODE_TO_EDIT_OPEN,
37 ...insertedCursorLines.slice(
38 editableRegionStartLine,
39 editableRegionEndLine + 1,
40 ),
41 CODE_TO_EDIT_CLOSE,
42 ...insertedCursorLines.slice(editableRegionEndLine + 1),
43 ];
44
45 return instrumentedLines.join("\n");
46}
47
48export function editHistoryBlock(
49 editDiffHistory: string, // could be a singe large unified diff
50) {
51 return editDiffHistory;
52}
53
54function mercuryNextEditTemplateBuilder(
55 recentlyViewedCodeSnippets: { filepath: string; code: string }[],
56 currentFileContent: string,
57 codeToEdit: string,
58 codeToEditRange: Range,
59 cursorPosition: Position,
60 editDiffHistory: string, // could be a singe large unified diff
61): string {
62 return "";
63}