Skip to content

Commit

Permalink
fix: line breaks before modified code snippet gets deleted after writ…
Browse files Browse the repository at this point in the history
…ing to file
  • Loading branch information
fynnfluegge committed Jan 21, 2024
1 parent 9891b74 commit 6a634c6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions doc_comments_ai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def write_code_snippet_to_file(
original_code (str): The original code snippet to be replaced.
modified_code (str): The modified code snippet.
"""
with open(file_path, "r") as file:
with open(file_path, "r", encoding="utf-8") as file:
file_content = file.read()
start_pos = file_content.find(original_code)
if start_pos != -1:
Expand All @@ -74,8 +74,7 @@ def write_code_snippet_to_file(
indented_modified_lines = [indentation + line for line in modeified_lines]
indented_modified_code = "\n".join(indented_modified_lines)
modified_content = (
file_content[:start_pos].rstrip()
+ "\n"
file_content[:start_pos]
+ indented_modified_code
+ file_content[end_pos:]
)
Expand Down

0 comments on commit 6a634c6

Please sign in to comment.