Skip to content
Open
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
30 changes: 14 additions & 16 deletions aider/coders/base_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,33 +607,31 @@ def get_abs_fnames_content(self):
yield fname, content

def choose_fence(self):
all_content = ""
found_fences = set()

def add_found_fences(content):
for line in content.splitlines():
for fence_open, fence_close in self.fences:
if line.startswith(fence_open) or line.startswith(fence_close):
found_fences.add((fence_open, fence_close))
break

for _fname, content in self.get_abs_fnames_content():
all_content += content + "\n"
add_found_fences(content)
for _fname in self.abs_read_only_fnames:
content = self.io.read_text(_fname)
if content is not None:
all_content += content + "\n"

lines = all_content.splitlines()
good = False
for fence_open, fence_close in self.fences:
if any(line.startswith(fence_open) or line.startswith(fence_close) for line in lines):
continue
good = True
break
add_found_fences(content)

if good:
self.fence = (fence_open, fence_close)
else:
try:
self.fence = next(f for f in self.fences if f not in found_fences)
except StopIteration:
self.fence = self.fences[0]
self.io.tool_warning(
"Unable to find a fencing strategy! Falling back to:"
f" {self.fence[0]}...{self.fence[1]}"
)

return

def get_files_content(self, fnames=None):
if not fnames:
fnames = self.abs_fnames
Expand Down