Skip to content

Commit 7300ee3

Browse files
author
Abderraouf Belalia
committed
refactor: address PR review feedback for line numbering feature
- Remove manual CHANGELOG.md entry (auto-generated at release) - Revert docs/capabilities.md changes (auto-generated via mcp-discovery) - Improve documentation clarity for with_line_numbers parameter format - Add test for Windows line endings (\r\n) - Add edge case tests for newline-only content Addresses review comments on PR #61 [agent commit]
1 parent b3740aa commit 7300ee3

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

CHANGELOG.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
# Changelog
22

3-
## [Unreleased]
4-
5-
### 🚀 Features
6-
7-
* Add optional line numbering to read_text_file tool ([#60](https://github.com/rust-mcp-stack/rust-mcp-filesystem/issues/60))
8-
- Added `with_line_numbers` optional parameter to `read_text_file` tool
9-
- When enabled, prefixes each line with right-aligned line numbers and pipe separator
10-
- Useful for AI agents that need to target specific lines for code patches
11-
- Maintains backward compatibility with existing usage
12-
133
## [0.3.6](https://github.com/rust-mcp-stack/rust-mcp-filesystem/compare/v0.3.5...v0.3.6) (2025-10-15)
144

155

docs/capabilities.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,10 @@
230230
<td>
231231
<code><b>read_text_file</b></code>
232232
</td>
233-
<td>Read the complete contents of a text file from the file system as text. Handles various text encodings and provides detailed error messages if the file cannot be read. Use this tool when you need to examine the contents of a single file. Optionally include line numbers for precise code targeting. Only works within allowed directories.</td>
233+
<td>Read the complete contents of a text file from the file system as text. Handles various text encodings and provides detailed error messages if the file cannot be read. Use this tool when you need to examine the contents of a single file. Only works within allowed directories.</td>
234234
<td>
235235
<ul>
236236
<li> <code>path</code> : string<br /></li>
237-
<li> <code>with_line_numbers</code> : boolean<br /></li>
238237
</ul>
239238
</td>
240239
</tr>

src/tools/read_text_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub struct ReadTextFile {
2424
/// The path of the file to read.
2525
pub path: String,
2626
/// Optional: Include line numbers in output (default: false).
27-
/// When enabled, each line is prefixed with its line number (1-based).
28-
/// Useful for AI agents that need to target specific lines for code patches.
27+
/// When enabled, each line is prefixed with a right-aligned, 1-based line number
28+
/// Followed by a space, a vertical bar (`|`), and another space in the format: ` 123 | <original line content>`
2929
#[serde(default)]
3030
pub with_line_numbers: Option<bool>,
3131
}

tests/test_fs_service.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,42 @@ async fn test_read_text_file_with_line_numbers_large_file() {
306306
assert!(content.contains(" 1000 | line1000"));
307307
}
308308

309+
#[tokio::test]
310+
async fn test_read_text_file_with_line_numbers_windows_line_endings() {
311+
let (temp_dir, service, _allowed_dirs) = setup_service(vec!["dir1".to_string()]);
312+
let file_path = create_temp_file(
313+
temp_dir.join("dir1").as_path(),
314+
"windows.txt",
315+
"line1\r\nline2\r\nline3",
316+
);
317+
let content = service.read_text_file(&file_path, true).await.unwrap();
318+
assert_eq!(content, " 1 | line1\n 2 | line2\n 3 | line3");
319+
}
320+
321+
#[tokio::test]
322+
async fn test_read_text_file_with_line_numbers_single_newline_unix() {
323+
let (temp_dir, service, _allowed_dirs) = setup_service(vec!["dir1".to_string()]);
324+
// A file with just "\n" is treated by lines() as having one empty line before the newline
325+
// To get two empty lines, we need "\n\n"
326+
let file_path = create_temp_file(temp_dir.join("dir1").as_path(), "newline_unix.txt", "\n\n");
327+
let content = service.read_text_file(&file_path, true).await.unwrap();
328+
assert_eq!(content, " 1 | \n 2 | ");
329+
}
330+
331+
#[tokio::test]
332+
async fn test_read_text_file_with_line_numbers_single_newline_windows() {
333+
let (temp_dir, service, _allowed_dirs) = setup_service(vec!["dir1".to_string()]);
334+
// A file with just "\r\n" is treated by lines() as having one empty line
335+
// To get two empty lines, we need "\r\n\r\n"
336+
let file_path = create_temp_file(
337+
temp_dir.join("dir1").as_path(),
338+
"newline_windows.txt",
339+
"\r\n\r\n",
340+
);
341+
let content = service.read_text_file(&file_path, true).await.unwrap();
342+
assert_eq!(content, " 1 | \n 2 | ");
343+
}
344+
309345
#[tokio::test]
310346
async fn test_create_directory() {
311347
let (temp_dir, service, _allowed_dirs) = setup_service(vec!["dir1".to_string()]);

0 commit comments

Comments
 (0)