mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-14 10:19:02 +00:00
Apply TextUtils, ensuring consistent line numbering
* in search_text * in MatchedConsecutiveLines.from_file_contents
This commit is contained in:
1 parent
9208a3ae87
commit
97c9b8c05d
2 files changed
+7
-5
No files matched your search
+3
-1
@@ -33,7 +33,9 @@ Status of the `main` branch. Changes prior to the next official version change w
|
||||
- During project creation, language composition percentages are now computed relative to the total number
|
||||
of recognised source files instead of all files, i.e. unrecognised files are ignored in the percentage
|
||||
computation.
|
||||
- Fix: Use LSP-compliant line splitting ("\n", "\r\n" and "\r" can define line breaks)
|
||||
- Fix: Use LSP-compliant line splitting ("\n", "\r\n" and "\r" can define line breaks); previously only "\n" considered
|
||||
- Fix: Apply consistent line splitting across tools, uniformly applying the LSP splitting semantics;
|
||||
affects `search_text` used by `search_for_pattern` tool (reported in #1684)
|
||||
|
||||
* CLI:
|
||||
- Fix `--project-from-cwd` hijacking git worktrees nested under a Serena project. `find_project_root`
|
||||
|
||||
@@ -100,7 +100,7 @@ class MatchedConsecutiveLines:
|
||||
def from_file_contents(
|
||||
cls, file_contents: str, line: int, context_lines_before: int = 0, context_lines_after: int = 0, source_file_path: str | None = None
|
||||
) -> Self:
|
||||
line_contents = file_contents.split("\n")
|
||||
line_contents = TextUtils.split_lines(file_contents)
|
||||
start_lineno = max(0, line - context_lines_before)
|
||||
end_lineno = min(len(line_contents) - 1, line + context_lines_after)
|
||||
text_lines: list[TextLine] = []
|
||||
@@ -169,7 +169,7 @@ def search_text(
|
||||
raise ValueError("Pass either content or source_file_path")
|
||||
|
||||
matches = []
|
||||
lines = content.splitlines()
|
||||
lines = TextUtils.split_lines(content)
|
||||
total_lines = len(lines)
|
||||
|
||||
# Convert pattern to a compiled regex if it's a string
|
||||
@@ -185,8 +185,8 @@ def search_text(
|
||||
end_pos = match.end()
|
||||
|
||||
# Find the line numbers for the start and end positions
|
||||
start_line_num = content[:start_pos].count("\n")
|
||||
end_line_num = content[:end_pos].count("\n")
|
||||
start_line_num = TextUtils.get_line_from_index(content, start_pos)
|
||||
end_line_num = TextUtils.get_line_from_index(content, end_pos)
|
||||
|
||||
# Calculate the range of lines to include in the context
|
||||
context_start = max(0, start_line_num - context_lines_before)
|
||||
|
||||
Reference in new issue
Block a user