mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
refactor: replace file operations with io.read_text()
This commit is contained in:
parent
f872b20a97
commit
bb1b3fdca1
1 changed files with 13 additions and 15 deletions
|
@ -102,14 +102,12 @@ class FileWatcher:
|
||||||
|
|
||||||
# Check if file contains AI markers
|
# Check if file contains AI markers
|
||||||
try:
|
try:
|
||||||
with open(path_abs, encoding=self.encoding, errors="ignore") as f:
|
content = self.io.read_text(str(path_abs))
|
||||||
content = f.read()
|
res = bool(re.search(r"(?:#|//) *ai\b", content, re.IGNORECASE))
|
||||||
|
if self.verbose:
|
||||||
res = bool(re.search(r"(?:#|//) *ai\b", content, re.IGNORECASE))
|
dump(res)
|
||||||
if self.verbose:
|
return res
|
||||||
dump(res)
|
except Exception as err:
|
||||||
return res
|
|
||||||
except (IOError, UnicodeDecodeError) as err:
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("error")
|
print("error")
|
||||||
dump(err)
|
dump(err)
|
||||||
|
@ -198,13 +196,13 @@ class FileWatcher:
|
||||||
"""Extract all AI comments from a file"""
|
"""Extract all AI comments from a file"""
|
||||||
comments = []
|
comments = []
|
||||||
try:
|
try:
|
||||||
with open(filepath, encoding=encoding, errors="ignore") as f:
|
content = self.io.read_text(filepath)
|
||||||
for line in f:
|
for line in content.splitlines():
|
||||||
if match := re.search(r"(?:#|//) *(ai\b.*|ai)", line, re.IGNORECASE):
|
if match := re.search(r"(?:#|//) *(ai\b.*|ai)", line, re.IGNORECASE):
|
||||||
comment = match.group(0).strip()
|
comment = match.group(0).strip()
|
||||||
if comment:
|
if comment:
|
||||||
comments.append(comment)
|
comments.append(comment)
|
||||||
except (IOError, UnicodeDecodeError):
|
except Exception:
|
||||||
return None
|
return None
|
||||||
return comments if comments else None
|
return comments if comments else None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue