Elffuss BraidHub

kikocis/continue public

0a1f7aa3091d · 2.1 KiBRawPermalink
1import { Position, Range } from "../..";
2import {
3 MERCURY_CODE_TO_EDIT_CLOSE,
4 MERCURY_CODE_TO_EDIT_OPEN,
5 MERCURY_CURSOR,
6} from "../constants";
7import { insertCursorToken } from "./utils";
8
9export function recentlyViewedCodeSnippetsBlock(
10 recentlyViewedCodeSnippets: { filepath: string; content: string }[],
11) {
12 return recentlyViewedCodeSnippets.reduce((acc, snippet, i) => {
13 const block = [
14 `code_snippet_file_path: ${snippet.filepath}`,
15 snippet.content,
16 ].join("\n");
17
18 return (
19 acc + block + (i === recentlyViewedCodeSnippets.length - 1 ? "" : "\n")
20 );
21 }, "");
22}
23
24export function currentFileContentBlock(
25 currentFileContent: string,
26 editableRegionStartLine: number,
27 editableRegionEndLine: number,
28 cursorPosition: Position,
29) {
30 const currentFileContentLines = currentFileContent.split("\n");
31
32 const insertedCursorLines = insertCursorToken(
33 currentFileContentLines,
34 cursorPosition,
35 MERCURY_CURSOR,
36 );
37
38 const instrumentedLines = [
39 ...insertedCursorLines.slice(0, editableRegionStartLine),
40 MERCURY_CODE_TO_EDIT_OPEN,
41 ...insertedCursorLines.slice(
42 editableRegionStartLine,
43 editableRegionEndLine + 1,
44 ),
45 MERCURY_CODE_TO_EDIT_CLOSE,
46 ...insertedCursorLines.slice(editableRegionEndLine + 1),
47 ];
48
49 return instrumentedLines.join("\n");
50}
51
52export function editHistoryBlock(
53 editDiffHistory: string[], // could be a singe large unified diff
54) {
55 // diffHistory is made from createDiff.
56 // This uses createPatch from npm diff library, which includes an index line and a separator.
57 // We get rid of these first two lines.
58 return editDiffHistory
59 .map((diff) => diff.split("\n").slice(2).join("\n"))
60 .join("\n");
61 // return editDiffHistory.split("\n").slice(2).join("\n");
62}
63
64function mercuryNextEditTemplateBuilder(
65 recentlyViewedCodeSnippets: { filepath: string; code: string }[],
66 currentFileContent: string,
67 codeToEdit: string,
68 codeToEditRange: Range,
69 cursorPosition: Position,
70 editDiffHistory: string, // could be a singe large unified diff
71): string {
72 return "";
73}