Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not fail if only removing lines from file #174

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,18 @@ export const createPromptFiles = (
maxPromptPayloadLength: number,
maxSurroundingLines?: number
): PromptFile[] => {
return files.map((file) => {
return files.reduce((result: PromptFile[], file) => {
const contentLines = file.fileContent.split("\n");
const changedLinesArray = file.changedLines.split("\n");

// Get the changed indices, total length, and min/max indices
const { changedIndices, totalChangedLinesLength, minIndex, maxIndex } =
getChangedIndicesAndLength(contentLines, changedLinesArray);

if (totalChangedLinesLength == 0) {
return result;
}

// Calculate remaining space and start/end positions
let remainingSpace =
maxPromptPayloadLength - totalChangedLinesLength - file.fileName.length;
Expand All @@ -145,9 +149,10 @@ export const createPromptFiles = (
contentLines
);

return {
result.push({
fileName: file.fileName,
promptContent: promptContent,
};
});
});
return result;
}, []);
};