-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
repl: add support for multiline history #57400
repl: add support for multiline history #57400
Conversation
9137def
to
5f9b8f1
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #57400 +/- ##
==========================================
+ Coverage 90.20% 90.24% +0.03%
==========================================
Files 630 630
Lines 185307 185613 +306
Branches 36269 36400 +131
==========================================
+ Hits 167162 167507 +345
+ Misses 11084 10994 -90
- Partials 7061 7112 +51
🚀 New features to boost your workflow:
|
5f9b8f1
to
8b261ae
Compare
/cc @nodejs/repl |
@BridgeAR you, being the requestor, maybe want to give this a shot 😄 |
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 is a great start!
I did play around with it and I found the following issues:
- A history item is now not properly deduplicated anymore if it spans over multiple lines. That is the case with other entries when jumping through the history.
- When entering a multiline command that fails to evaluate, it is handled as individual lines. Especially those cases would be great to "correct". For comfort reasons, I would even consider deleting the broken one, if that one is edited and saved successfully right as following command.
- Moving up and down while working on a multiline entry feels somewhat off. It is opinionated, but I believe the former history entry should only be shown in case the cursor is at the top line while editing a multiline input. The reason is, that I likely want to finish the input and not change to the former history entry.
I would also change the ...
to |
. That way the indentation while entering something is identical. I guess we can still look into doing this potentially while going through the entries in the history but at least it is nicer during initial entry.
a434fe4
to
8e71cdf
Compare
897b341
to
3418b3b
Compare
3418b3b
to
b41273a
Compare
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 is great work! I am looking forward to landing this change!
I left a few comments, mainly to understand some things better.
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.
seems good
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.
It is a bit difficult to tell if this change should be considered as minor or major. Any further opinion?
Since using an old version of node corrupts the history to split lines, i'd say it's major. If we can come up with a way to avoid that, then it'd be minor, and aggresively backportable, which would be ideal. |
f2e778e
to
37c339b
Compare
Introducing a new history file formatsomething new, a 🟢 Pros: there is no complicated logic to determine which history you want to load. If you have new node, read the new history file with the new format, otherwise the old history file with the old node. Introducing an additional "metadata" history filesomething new, a 🟢 Pros: there is no complicated logic to determine which history you want to load. If you have new node, read the new history "metadata" file and parse the history file accordingly, otherwise don't parse the "metadata" file and just read the history file. Parsing the history file and trying to restore multiline structures from the old history filewhen the old node lands and people start using it, it could try to parse the history file and understand, line by line, if a group of lines would be a single multiline structure. 🟢 Pros: you only handle a single history file. |
37c339b
to
8f52797
Compare
I was wondering if there's a way to avoid that parse by using unicode newlines instead of normal ones, such that older node handles it normally but newer node recognizes it as multiline input? |
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
After looking into this again, I do not believe that it's possible to get the unicode line breaks to work in older Node.js versions. So the only way I believe is viable without renaming the file is to accept that switching to an older version removes the multilines for those history entries. |
fcf01f7
to
603b1d3
Compare
603b1d3
to
23f7e47
Compare
This will make it consistent when loading the new history format with an old node binary
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.
LGTM! Thank you for the great work! 🥳
Landed in 4a4aa58 |
Previously, when navigating the history in the Node.js REPL, multiline commands were displayed line by line, making it difficult to review and edit complete blocks of input.
This PR improves the REPL history behavior by treating multiline commands as a single entry. Now, when scrolling through history, entire blocks of multiline input are displayed together, improving usability and consistency.
Key changes:
...
to|
, to keep the indentation consistentImportant:
This change relies on the fact that I am now formatting new history entries and saving them in the
.node_replhistory
file in a specific format. While this does not break backward compatibility, it does mean that switching between older and newer versions (i.e., versions without and with this change) will result in multiline history entries not being preserved if they were created with the latest changes.Impact:
This change significantly enhances the REPL experience for users who frequently enter complex or multiline expressions, making command recall and editing more intuitive.
Testing:
Demos
Before:
After: