Skip to content

Commit 4e8c675

Browse files
committed
Fixes
1 parent 6f445f9 commit 4e8c675

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/cedarscript_editor/cedarscript_editor.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
InsertClause, ReplaceClause, EditingAction, BodyOrWhole, RegionClause, MarkerType
88
from cedarscript_ast_parser.cedarscript_ast_parser import MarkerCompatible, RelativeMarker, \
99
RelativePositionType
10-
from text_manipulation.indentation_kit import IndentationInfo
11-
from text_manipulation.range_spec import IdentifierBoundaries, RangeSpec
12-
from text_manipulation.text_editor_kit import read_file, write_file, bow_to_search_range
10+
from text_manipulation import IndentationInfo
11+
from text_manipulation import IdentifierBoundaries, RangeSpec
12+
from text_manipulation import read_file, write_file, bow_to_search_range
1313

1414
from .identifier_selector import select_finder
1515

@@ -58,7 +58,9 @@ def __init__(self, command_ordinal: int, description: str):
5858
"the state at which the file was left (saying what needs to be done now), "
5959
f"then write new commands that will fix the problem{previous_cmd_notes} "
6060
"(you'll get a one-million dollar tip if you get it right!) "
61-
"Use descriptive comment before each command; If showing CEDARScript commands to the user, *DON'T* enclose them in ```CEDARSCript and ``` otherwise they will be executed!</suggestion></error-details>"
61+
"Use descriptive comment before each command; If showing CEDARScript commands to the user, "
62+
"*DON'T* enclose them in ```CEDARSCript and ``` otherwise they will be executed!"
63+
"</suggestion></error-details>"
6264
)
6365

6466

@@ -150,7 +152,7 @@ def _update_command(self, cmd: UpdateCommand):
150152
src = read_file(file_path)
151153
lines = src.splitlines()
152154

153-
source_info: tuple[LiteralString | str | bytes, str | Sequence[str]] = (file_path, src)
155+
source_info: tuple[str | bytes, str | Sequence[str]] = (file_path, src)
154156

155157
def identifier_resolver(m: Marker):
156158
return self.find_identifier(source_info, m)

src/text_manipulation/range_spec.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
MATCH_TYPES = ('exact', 'stripped', 'normalized', 'partial')
1111

12+
1213
@total_ordering
1314
class RangeSpec(NamedTuple):
1415
start: int
@@ -40,7 +41,7 @@ def as_index(self) -> int | None:
4041

4142
@property
4243
def collapsed(self):
43-
return self.set_length(0)
44+
return self.set_line_count(0)
4445

4546
def set_line_count(self, range_len: int):
4647
return self._replace(end=self.start + range_len)
@@ -156,16 +157,19 @@ def from_line_marker(
156157
if search_term.offset is None and match_type_count > 1:
157158
raise ValueError(
158159
f"There are {match_type_count} lines matching `{search_term.value}`. "
159-
f"Suggestions: 1) Try using a *different line* as marker (a couple lines before or after the one you tried); "
160-
f"2) If you wanted to *REPLACE* line, try instead to replace a *SEGMENT* of a couple of lines."
161-
# f"Add an `OFFSET` (after the line marker) and a number between 0 and {match_type_count - 1} to determine how many to skip. "
162-
# f"Example to reference the *last* one of those: `LINE '{search_term.value.strip()}' OFFSET {match_type_count - 1}`"
160+
"Suggestions: 1) Try using a *different line* as marker (a couple lines before or after the one "
161+
"you tried); 2) If you wanted to *REPLACE* line, "
162+
"try instead to replace a *SEGMENT* of a couple of lines."
163+
# f"Add an `OFFSET` (after the line marker) and a number between 0 and {match_type_count - 1}
164+
# to determine how many to skip. "
165+
# f"Example to reference the *last* one of those:
166+
# `LINE '{search_term.value.strip()}' OFFSET {match_type_count - 1}`"
163167
# ' (See `offset_clause` in `<grammar.js>` for details on OFFSET)'
164168
)
165169
if match_type_count and (search_term.offset or 0) >= match_type_count:
166170
raise ValueError(
167171
f"There are only {match_type_count} lines matching `{search_term.value}`, "
168-
f"but 'OFFSET' was set to {search_term.offset} (you can skip at most {match_type_count - 1} of those)"
172+
f"but 'OFFSET' was set to {search_term.offset} (you can skip at most {match_type_count-1} of those)"
169173
)
170174

171175
if offset < match_type_count:

0 commit comments

Comments
 (0)