Skip to content

Commit

Permalink
what
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher David committed Dec 1, 2023
1 parent 66c4fde commit f875750
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/Services/Patcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ private function determinePatchForRemoteFile($filePath, $fileContent, $issue)
print_r("Trying code block for {$filePath}, attempt #{$retryCount}\n");
// Construct the prompt for getting the 'Before' and 'After' contents
$actionPrompt2 = "Identify which code block needs to be changed (mark it up with \"Before:\") and output the change (mark it up with \"After:\"). Make your change match the coding style of the original file.";
// print_r($prompt . $actionPrompt2 . "\n");
$change = $this->complete($prompt . $actionPrompt2);
// print_r($change);

if (strpos($change, "Before:") === false || strpos($change, "After:") === false) {
dd("Warning: incorrect output format\n");
Expand All @@ -56,7 +58,7 @@ private function determinePatchForRemoteFile($filePath, $fileContent, $issue)
$pattern = "/\s*" . str_replace("\n", "\s*", $escapedBefore) . "\s*/s";

if (!preg_match($pattern, $fileContent)) {
print_r("didn't match");
print_r("didnt match");
if (++$retryCount >= $maxRetries) {
dd("Warning: exceeded maximum retries for finding `Before` block\n");
return null;
Expand All @@ -69,7 +71,7 @@ private function determinePatchForRemoteFile($filePath, $fileContent, $issue)
$after .= "\n";
}

// Ensure that the 'after' block begins with a newline character
// Ensure that the 'after block begins with a newline character
if (!str_starts_with($after, "\n")) {
$after = "\n" . $after;
}
Expand All @@ -78,6 +80,7 @@ private function determinePatchForRemoteFile($filePath, $fileContent, $issue)
$newFileContent = preg_replace($pattern, $after, $fileContent, 1);

// Additional step to ensure proper spacing between lines if necessary
// This step can be adjusted based on the specific formatting issues you are encountering
$newFileContent = preg_replace('/([;}])it/', "$1\nit", $newFileContent);

return [
Expand Down

0 comments on commit f875750

Please sign in to comment.