-
Notifications
You must be signed in to change notification settings - Fork 30k
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: handling multiline history needs some case guards #24231
Comments
Thanks. I will have a look at it today. |
@vsemozhetbyt: The second issue, I guess I couldn't able to reproduce it (atleast on master).
First one yes, its an issue. Good catch. |
@antsmartian H'm, I cannot reproduce now as well. Maybe I've got some flaky condition then. But we still have an issue: line breaks are part of the code in multiline template literals, they may need to be saved so that restored line would be the |
Hmmm, but current history doesn't show as |
I mean, for me it seems these cases should be handled equally:
Otherwise, we had wrong value second time. |
@vsemozhetbyt The way I see it to handle the |
@shobhitchittora : Yes you are right. But fundamentally, on multiline we call |
The current way how multilines are saved is just wrong. A line is detected when the newline character ( I tried to fix that by adding the new lines but I ran into new issues when doing that due to another bug in the implementation. Both are outlines above and in #24781. |
Copying from #24781 (comment) Is there no way for us to keep the line breaks? That's what |
@targos I tried that but this caused new issues with a different bug that caused the history to become malformed. It will also move the line upwards and if you then move up in the history to e.g. a single line entry, the lower end of the terminal will be empty. I guess this would be the best we can do at the moment? |
Yes this happens on line breaks statements for example string literals, code with comments. Other things like function, object, class declarations seems to be working fine. (fundamentally the implementation is based on |
@antsmartian they work by chance. The input is still manipulated for all input by removing the newline. Another example with a function:
This fails in the However, there is more weirdness going on in the new history: it does not memorize the correct order when an error happened while trying to evaluate a statement. |
@BridgeAR Ack. I got what you are saying here. Seems to be bit tricky. Thanks for your time on this. My bad, seems to be this feature broken history a bit :( Will see, how we can rectify this. |
Another unintended fix are ASI cases: > (function () {
... return
... console.log('should not be logged')
... })()
undefined
>
> (function () { return console.log('not logged')})()
should not be logged
undefined
> |
I'm planning to do this:
cc @BridgeAR @vsemozhetbyt @targos thoughts? |
This sounds very hackish and people will be confused that it works one way in the current session and different from entries from before. I for example often leave the repl and open it again and go back in the history. I believe we should give this a bit more thought. The main problem I see is the format how we save the history currently. It is simple plain text, line by line and if we want to keep on using that it requires to either add some magic characters (e.g., a rarely used control character sequence) that we replace with newlines when reading the entry. However, this is not ideal. It would be much simpler if the format would not be plain text but this decision was made early on in io.js 3.0 by @Fishrock123 (#2224). I personally believe a JSON file with an array as content would be better. But that would be a significant change to the format and I am not sure it's worth the hassle. Other opinions / thoughts? // cc @silverwind as you have also been involved with the history before. Update: I removed a suggestion which turned out as impossible. |
i would keep history with the newlines, and then just print/clean the multiple newlines that occur when traversing it |
@BridgeAR Moving to JSON format ofcourse is a good idea to solve this problem. I would be happy to implement it, but need other's thought. Keeping |
But looking from #2224, seems to be that we have moved from JSON to text file. Not sure, whats the real reason behind it. |
@devsnek can you elaborate on the that? If I understand correct you want to add empty lines in the history that mark a multiline statement, am I correct? This should be possible. @antsmartian you could try this. |
@BridgeAR Yes, I guess that's what @devsnek suggesting here. To be on the same page, this is how history looks like, if we implement the logic:
On processing, we need to change
I'm actually trying to implement it. |
@antsmartian the second entry should look like: |
@BridgeAR : Yup, its a typo. Fixed. |
@antsmartian just as another hint: to keep backwards compatibility with the current format you actually have to do exactly the opposite of how you want the history to look like:
Otherwise all existing history entries become a huge multiline statement and we don't want that ;-). |
This reverts commit eb42c1e. PR-URL: nodejs#24804 Refs: nodejs#24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit dd7a3d2. PR-URL: nodejs#24804 Refs: nodejs#24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit eb42c1e. PR-URL: #24804 Refs: #24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit dd7a3d2. PR-URL: #24804 Refs: #24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit eb42c1e. PR-URL: #24804 Refs: #24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit dd7a3d2. PR-URL: #24804 Refs: #24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit eb42c1e. PR-URL: #24804 Refs: #24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit dd7a3d2. PR-URL: #24804 Refs: #24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit eb42c1e. PR-URL: nodejs#24804 Refs: nodejs#24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This reverts commit dd7a3d2. PR-URL: nodejs#24804 Refs: nodejs#24231 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
I am closing this, since the feature itself was reverted and has not been added back so far. |
This is relevant if someone pastes copied code blocks with line comments in the REPL. It seems comments need to be stripped.
cc @antsmartian
The text was updated successfully, but these errors were encountered: