@@ -33,7 +33,7 @@ def __init__(self, command_ordinal: int, description: str):
3333
3434 previous_cmd_notes = (
3535 f", bearing in mind the file was updated and now contains all changes expressed in "
36- f"commands { items } "
36+ f"commands { items } . "
3737 )
3838 if 'syntax' in description .casefold ():
3939 probability_indicator = "most probably"
@@ -43,10 +43,11 @@ def __init__(self, command_ordinal: int, description: str):
4343 note = (
4444 f"<note>*ALL* commands *before* command #{ command_ordinal } "
4545 "were applied and *their changes are already committed*. "
46- f"Re-read the file to catch up with the applied changes."
46+ f"So, it's *CRUCIAL* to re-analyze the file to catch up with the applied changes "
47+ "and understand what still needs to be done. "
4748 f"ATTENTION: The previous command (#{ command_ordinal - 1 } ) { probability_indicator } "
4849 f"caused command #{ command_ordinal } to fail "
49- f"due to changes that left the file in an invalid state (check that by re-analyzing the file!)</note>"
50+ f"due to changes that left the file in an invalid state (check that by re-reading the file!)</note>"
5051 )
5152 super ().__init__ (
5253 f"<error-details><error-location>COMMAND #{ command_ordinal } </error-location>{ note } "
@@ -57,7 +58,7 @@ def __init__(self, command_ordinal: int, description: str):
5758 "the state at which the file was left (saying what needs to be done now), "
5859 f"then write new commands that will fix the problem{ previous_cmd_notes } "
5960 "(you'll get a one-million dollar tip if you get it right!) "
60- "Use descriptive comment before each command. </suggestion></error-details>"
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>"
6162 )
6263
6364
@@ -197,26 +198,34 @@ def identifier_resolver(m: Marker):
197198 )
198199 dest_indent = dest_range .indent
199200 content = move_src_range .read (lines )
200- count = dest_indent + (relindent or 0 )
201+ shift_count = dest_indent + (relindent or 0 )
201202 content = IndentationInfo .from_content (content ).shift_indentation (
202- content , count
203+ content , shift_count
203204 )
204205 case _:
205206 raise ValueError (f'Invalid content: { content } ' )
206207
207- self ._apply_action (action , lines , search_range , content )
208+ self ._apply_action (action , lines , search_range , content , range_spec_to_delete = move_src_range )
208209
209210 write_file (file_path , lines )
210211
211212 return f"Updated { target if target else 'file' } in { file_path } \n -> { action } "
212213
213214 @staticmethod
214- def _apply_action (action : EditingAction , lines : Sequence [str ], range_spec : RangeSpec , content : str | None = None ):
215+ def _apply_action (
216+ action : EditingAction , lines : Sequence [str ], range_spec : RangeSpec , content : str | None = None ,
217+ range_spec_to_delete : RangeSpec | None = None
218+ ):
215219 match action :
216220
217221 case MoveClause (insert_position = insert_position , to_other_file = other_file , relative_indentation = relindent ):
218222 # TODO Move from 'lines' to the same file or to 'other_file'
219- range_spec .write (content , lines )
223+ if range_spec <= range_spec_to_delete :
224+ range_spec_to_delete .delete (lines )
225+ range_spec .write (content , lines )
226+ else :
227+ range_spec .write (content , lines )
228+ range_spec_to_delete .delete (lines )
220229
221230 case DeleteClause ():
222231 range_spec .delete (lines )
@@ -339,8 +348,8 @@ def restrict_search_range_for_marker(
339348 case InsertClause ():
340349 if action .insert_position .qualifier == RelativePositionType .BEFORE :
341350 search_range = search_range .inc ()
342- case DeleteClause ():
343- search_range = search_range .set_length (1 )
351+ case RegionClause ():
352+ search_range = search_range .set_line_count (1 )
344353 case _:
345354 identifier_boundaries = identifier_resolver (marker )
346355 if not identifier_boundaries :
0 commit comments