Skip to content

Commit af2df77

Browse files
committed
fix(text_editor.py): calculate file hash after reading file content to ensure accurate hash representation
refactor(text_editor.py): store file content in a variable for better readability and reuse when calculating hash
1 parent f6354b9 commit af2df77

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/mcp_text_editor/text_editor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ async def read_file_contents(
162162
try:
163163
with open(file_path, "r", encoding="utf-8") as f:
164164
lines = f.readlines()
165-
165+
file_content = "".join(lines)
166+
file_hash = self.calculate_hash(file_content)
166167
# Adjust line numbers to 0-based index
167168
line_start = max(1, line_start) - 1
168169
line_end = len(lines) if line_end is None else min(line_end, len(lines))
@@ -179,7 +180,7 @@ async def read_file_contents(
179180
content,
180181
line_start + 1,
181182
line_end,
182-
self.calculate_hash(content),
183+
file_hash,
183184
len(lines),
184185
len(content),
185186
)

0 commit comments

Comments
 (0)