-
Notifications
You must be signed in to change notification settings - Fork 1
Add support for syntax highlighting in PyREPL #89
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
Conversation
627056f
to
aebc35f
Compare
4ab5a7b
to
31c48b2
Compare
for c in buffer: | ||
while colors and colors[0].span.end < start_index: | ||
# move past irrelevant spans | ||
colors.pop(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this list is not big enough that it matters but it would recommend modifying this to figure out the cutting index and then slicing once
pre_color = "" | ||
post_color = "" | ||
|
||
if colors and colors[0].span.start < i and colors[0].span.end > i: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach assumes the next call to disp_str() will properly handle the color continuation. If any buffer modification happens between calls, or if the next call uses different parameters, you'll get incorrect highlighting no?
Maybe this is a no problem but I would recommend to either add some defensive check or an assert
SYNC"]
# Then in the next call, verify consistency
if pending_color_span and colors and colors[0].span == pending_color_span.span:
# Spans match, continue highlighting
pre_color = TAG_TO_ANSI[colors[0].tag]
else:
…
post_color = TAG_TO_ANSI["SYNC"] | ||
colors.pop(0) | ||
|
||
chars[-1] = pre_color + chars[-1] + post_color |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this matters but this being in a tight loop may be a performance problem
@@ -355,3 +362,60 @@ def test_setpos_from_xy_for_non_printing_char(self): | |||
reader, _ = handle_all_events(events) | |||
reader.setpos_from_xy(8, 0) | |||
self.assertEqual(reader.pos, 7) | |||
|
|||
def test_syntax_highlighting_basic(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend adding some extra test for edge cases and failure modes such as incomplete code blocks, syntax errors and other known failure conditions so we know how this will behave
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this LGTM so I am approving it but left some comments.
31c48b2
to
f9f4722
Compare
aebc35f
to
35f01ca
Compare
Moved on to python#131562. |
No description provided.