Skip to content

Updated dependency: cedarscript-ast-parser>=0.2.1 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers = [
]
keywords = ["cedarscript", "code-editing", "refactoring", "code-analysis", "sql-like", "ai-assisted-development"]
dependencies = [
"cedarscript-ast-parser>=0.2.0",
"cedarscript-ast-parser>=0.2.1",
"rope>=1.13.0"
]
requires-python = ">=3.8"
Expand Down
2 changes: 1 addition & 1 deletion src/cedarscript_editor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cedarscript_editor.cedarscript_editor import CEDARScriptEditor

__version__ = "0.2.0"
__version__ = "0.2.1"

__all__ = ["CEDARScriptEditor"]

22 changes: 13 additions & 9 deletions src/cedarscript_editor/cedarscript_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ def __init__(self, command_ordinal: int, description: str):
if 'syntax' in description.casefold():
probability_indicator = "most probably"
else:
probability_indicator= "might have"
probability_indicator = "might have"

note = (
f"<note>*ALL* commands *before* command #{command_ordinal} were applied and *their changes are already committed*. "
f"<note>*ALL* commands *before* command #{command_ordinal} "
"were applied and *their changes are already committed*. "
f"Re-read the file to catch up with the applied changes."
f"ATTENTION: The previous command (#{command_ordinal - 1}) {probability_indicator} caused command #{command_ordinal} to fail "
f"ATTENTION: The previous command (#{command_ordinal - 1}) {probability_indicator} "
f"caused command #{command_ordinal} to fail "
f"due to changes that left the file in an invalid state (check that by re-analyzing the file!)</note>"
)
super().__init__(
f"<error-details><error-location>COMMAND #{command_ordinal}</error-location>{note}"
f"<description>{description}</description>"
"<suggestion>NEVER apologize; just relax, take a deep breath, think step-by-step and write an in-depth analysis of what went wrong "
"(specifying which command ordinal failed), then acknowledge which commands were already applied and concisely describe the state at which the file was left "
"(saying what needs to be done now), "
"<suggestion>NEVER apologize; just relax, take a deep breath, think step-by-step and write "
"an in-depth analysis of what went wrong (specifying which command ordinal failed), "
"then acknowledge which commands were already applied and concisely describe "
"the state at which the file was left (saying what needs to be done now), "
f"then write new commands that will fix the problem{previous_cmd_notes} "
"(you'll get a one-million dollar tip if you get it right!) "
"Use descriptive comment before each command.</suggestion></error-details>"
Expand Down Expand Up @@ -85,9 +88,9 @@ def apply_commands(self, commands: Sequence[Command]):
# result.append(self._create_command(cmd))
case RmFileCommand() as cmd:
result.append(self._rm_command(cmd))
case MvFileCommand() as cmd:
case MvFileCommand():
raise ValueError('Noy implemented: MV')
case SelectCommand() as cmd:
case SelectCommand():
raise ValueError('Noy implemented: SELECT')
case _ as invalid:
raise ValueError(f"Unknown command '{type(invalid)}'")
Expand Down Expand Up @@ -208,7 +211,8 @@ def identifier_resolver(m: Marker):

return f"Updated {target if target else 'file'} in {file_path}\n -> {action}"

def _apply_action(self, action: EditingAction, lines: Sequence[str], range_spec: RangeSpec, content: str | None = None):
@staticmethod
def _apply_action(action: EditingAction, lines: Sequence[str], range_spec: RangeSpec, content: str | None = None):
match action:

case MoveClause(insert_position=insert_position, to_other_file=other_file, relative_indentation=relindent):
Expand Down
6 changes: 4 additions & 2 deletions src/text_manipulation/indentation_kit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
from collections import Counter
from collections.abc import Sequence
from math import gcd
Expand Down Expand Up @@ -225,7 +224,10 @@ def apply_relative_indents[S: Sequence[str]](self, content: str | S, context_ind
if len(parts) == 2 and parts[0].startswith('@'):
relative_indent_level = int(parts[0][1:])
absolute_indent_level = context_indent_level + relative_indent_level
assert absolute_indent_level >= 0, f"Final indentation for line `{line.strip()}` cannot be negative ({absolute_indent_level})"
assert absolute_indent_level >= 0, (
f"Final indentation for line `{line.strip()}` cannot be negative "
f"({absolute_indent_level})"
)
lines[i] = self.level_to_chars(absolute_indent_level) + parts[1].lstrip()
else:
absolute_indent_level = context_indent_level
Expand Down
10 changes: 8 additions & 2 deletions src/text_manipulation/range_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ def from_line_marker[T: RangeSpec](
if search_end_index < 0:
search_end_index = len(lines)

assert search_start_index < len(lines), f"search start index ({search_start_index}) must be less than line count ({len(lines)})"
assert search_end_index <= len(lines), f"search end index ({search_end_index}) must be less than or equal to line count ({len(lines)})"
assert search_start_index < len(lines), (
f"search start index ({search_start_index}) "
f"must be less than line count ({len(lines)})"
)
assert search_end_index <= len(lines), (
f"search end index ({search_end_index}) "
f"must be less than or equal to line count ({len(lines)})"
)

for i in range(search_start_index, search_end_index):
line = lines[i]
Expand Down
12 changes: 10 additions & 2 deletions src/text_manipulation/text_editor_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def marker_or_segment_to_search_range_impl(
match self:
case Marker(type=MarkerType.LINE):
result = RangeSpec.from_line_marker(lines, self, search_range)
assert result is not None, f"Unable to find `{self}`; Try: 1) Double-checking the marker (maybe you specified the the wrong one); or 2) using *exactly* the same characters from source; or 3) using another marker"
assert result is not None, (
f"Unable to find `{self}`; Try: 1) Double-checking the marker "
f"(maybe you specified the the wrong one); or 2) using *exactly* the same characters from source; "
f"or 3) using another marker"
)
# TODO check under which circumstances we should return a 1-line range instead of an empty range
return result
case Segment(start=s, end=e):
Expand All @@ -77,7 +81,11 @@ def segment_to_search_range(
assert len(lines), "`lines` is empty"

start_match_result = RangeSpec.from_line_marker(lines, start_relpos, search_range)
assert start_match_result, f"Unable to find segment start `{start_relpos}`; Try: 1) Double-checking the marker (maybe you specified the the wrong one); or 2) using *exactly* the same characters from source; or 3) using a marker from above"
assert start_match_result, (
f"Unable to find segment start `{start_relpos}`; Try: "
f"1) Double-checking the marker (maybe you specified the the wrong one); or "
f"2) using *exactly* the same characters from source; or 3) using a marker from above"
)

start_index_for_end_marker = start_match_result.as_index
if start_relpos.qualifier == RelativePositionType.AFTER:
Expand Down