Skip to content

Commit 49ceae8

Browse files
committed
refactor(text_editor.py): rename expected_hash to expected_file_hash for clarity and consistency in the edit_file_contents method
1 parent 9ae692e commit 49ceae8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/mcp_text_editor/text_editor.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def read_file_contents(
180180
async def edit_file_contents(
181181
self,
182182
file_path: str,
183-
expected_hash: str,
183+
expected_file_hash: str,
184184
patches: List[Dict[str, Any]],
185185
encoding: str = "utf-8",
186186
) -> Dict[str, Any]:
@@ -189,7 +189,7 @@ async def edit_file_contents(
189189
190190
Args:
191191
file_path (str): Path to the file to edit
192-
expected_hash (str): Expected hash of the file before editing
192+
expected_file_hash (str): Expected hash of the file before editing
193193
patches (List[EditPatch]): List of patches to apply
194194
- line_start (int): Starting line number (1-based, optional, default: 1)
195195
- line_end (Optional[int]): Ending line number (inclusive)
@@ -198,7 +198,7 @@ async def edit_file_contents(
198198
199199
Args:
200200
file_path (str): Path to the file to edit (parent directories are created automatically)
201-
expected_hash (str): Expected hash of the file before editing (empty string for new files)
201+
expected_file_hash (str): Expected hash of the file before editing (empty string for new files)
202202
patches (List[Dict[str, Any]]): List of patches to apply, each containing:
203203
- line_start (int): Starting line number (1-based)
204204
- line_end (Optional[int]): Ending line number (inclusive)
@@ -208,7 +208,7 @@ async def edit_file_contents(
208208
Returns:
209209
Dict[str, Any]: Results of the operation containing:
210210
- result: "ok" or "error"
211-
- hash: New file hash if successful, None if error
211+
- file_hash: New file hash if successful, None if error
212212
- reason: Error message if result is "error"
213213
"content": None,
214214
}
@@ -218,7 +218,7 @@ async def edit_file_contents(
218218
self._validate_file_path(file_path)
219219
try:
220220
if not os.path.exists(file_path):
221-
if expected_hash not in ["", None]: # Allow null hash
221+
if expected_file_hash not in ["", None]: # Allow null hash
222222
return {
223223
"result": "error",
224224
"reason": "File not found and non-empty hash provided",
@@ -253,14 +253,14 @@ async def edit_file_contents(
253253
current_content = ""
254254
current_hash = ""
255255
lines = []
256-
elif current_content and expected_hash == "":
256+
elif current_content and expected_file_hash == "":
257257
return {
258258
"result": "error",
259259
"reason": "Unexpected error - Cannot treat existing file as new",
260260
"file_hash": None,
261261
"content": None,
262262
}
263-
elif current_hash != expected_hash:
263+
elif current_hash != expected_file_hash:
264264
return {
265265
"result": "error",
266266
"reason": "FileHash mismatch - Please use get_text_file_contents tool to get current content and hashes, then retry with the updated hashes.",
@@ -298,7 +298,7 @@ async def edit_file_contents(
298298
return {
299299
"result": "error",
300300
"reason": "Overlapping patches detected",
301-
"hash": None,
301+
"file_hash": None,
302302
"content": None,
303303
}
304304

@@ -327,7 +327,7 @@ async def edit_file_contents(
327327
if (
328328
os.path.exists(file_path)
329329
and current_content
330-
and expected_hash == ""
330+
and expected_file_hash == ""
331331
):
332332
return {
333333
"result": "error",

0 commit comments

Comments
 (0)