diff --git a/doc_comments_ai/utils.py b/doc_comments_ai/utils.py index 9cc0bf9..754e0c1 100644 --- a/doc_comments_ai/utils.py +++ b/doc_comments_ai/utils.py @@ -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: @@ -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:] )