-
Notifications
You must be signed in to change notification settings - Fork 379
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
feat(gnovm): Add Basic Code Indentation in REPL #1596
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1596 +/- ##
==========================================
+ Coverage 54.62% 58.21% +3.58%
==========================================
Files 581 389 -192
Lines 77955 65077 -12878
==========================================
- Hits 42584 37884 -4700
+ Misses 32194 24377 -7817
+ Partials 3177 2816 -361
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Thanks Joon. There are some cases here where the indentation feature exhibits strange behavior when indentation-causing characters are part of string literals rather than the code. Have any ideas how to solve this?
Memo: Once this PR is merged, I plan to implement the cursor movement and history save/load features proposed in issue #1416. Additionally, to achieve more sophisticated indentation control, I intend to process while keeping the terminal in raw mode, as it requires the ability to read user inputs directly. |
@@ -108,6 +108,11 @@ type Repl struct { | |||
stdin io.Reader | |||
} | |||
|
|||
// Read implements io.Reader. | |||
func (r *Repl) Read(p []byte) (n int, err error) { |
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.
Is this necessary? Things seem to work okay without it.
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.
Oh, i added that line to test the raw terminal mode. i forget to remove this.
trimmedLine := strings.TrimSpace(line) | ||
|
||
indentLevel = updateIndentLevel(trimmedLine, indentLevel) | ||
line, inEdit = handleEditor(line) |
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 change breaks the editor mode. I'd recommend restoring it since it is only called from this one location and moving it to its own function doesn't have too much benefit. The issue can by entering editor mode with /editor
and then doing some variable assignments. Notice that editor mode is exited after doing a single variable assignment when it should remain in editor mode until the semicolon is encountered.
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.
Thanks for the updates. It looks a lot better 👍 . Please see the comments I left. A few things seem to be broken and a couple others unnecessary. The remaining comments are just suggestions.
Thank you for the detailed review again. I'll try to get it done as soon as possible this week. 👍👍 |
Co-authored-by: deelawn <dboltz03@gmail.com>
Hey @notJoon, what's the status on this PR? Can you please merge in the latest |
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'm a bit skeptical about this pull request.
The code is redundant with parsing capabilities present elsewhere to analyze the source, and I'm not convinced of its usefulness: if you enter a block with the REPL, it is already reformatted and displayed correctly, even if not indented correctly, as following:
gno> func d() string { return "a" +
... "b" + "x" }
func d() string {
return "a" +
"b" + "x"
}
gno>
What about using ast/parser then ast/format? |
That would be practical. I'll ping you after update current code. 👍 |
Description
Indent for code
Updated the code in the REPL to adjust the indent level when an indent rule is detected.
I was considering enhancing the situation where closing parentheses feel tightly attached to the beginning of the previous line. In this case, it seems like setting the terminal to raw mode and directly recognizing the user's key inputs to adjust the level would suffice. (maybe later?)
Example
Add Clear Command
Added the
/clear
command to clear the repl's screen. For testing, I used dependency injection.