You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
repl: handling multiline history needs some case guards #24231
Recently added REPL multiline history handling streamlines multiline expressions into one-line expressions, but line comments may change syntax and hang execution:
>[
... 1// comment...][1]>[1// comment]...
This is relevant if someone pastes copied code blocks with line comments in the REPL. It seems comments need to be stripped.
Another case that needs special handling, multiline template literals:
changed the title [-]repl: handling multiline history needs comment stripping[/-][+]repl: handling multiline history needs some case guards[/+]on Nov 7, 2018
@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 `a\nb\nc`, not the `abc`.
Hmmm, but current history doesn't show as \n indeed. Its the result of an expression, but history just saves what user types right? Not the result. Thoughts?
@vsemozhetbyt The way I see it to handle the comment, you need to check for every line in repl and check if it has a comment. Also you'll want to skip this check for string literals. Weird cases to check thought ! 😛
@shobhitchittora : Yes you are right. But fundamentally, on multiline we call acron parser to see if we can expect more tokens or give up with errors. So in the same way, we need to handle this as well. Because code with comment, might not run in history as @vsemozhetbyt shown above. To me its a bug.
The current way how multilines are saved is just wrong. A line is detected when the newline character (\n) is detected. Now that line is added to potential former ones and therefore stripping the new lines. This is changing the actual input and causes multiple issues.
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.
@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?
The current way how multilines are saved is just wrong. A line is detected when the newline character >(\n) is detected. Now that line is added to potential former ones and therefore stripping the new lines. >This is changing the actual input and causes multiple issues.
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 kBufferedCommandSymbol on repl, I guess that's the sole reason here as it doesn't work for template literals and like)
@antsmartian they work by chance. The input is still manipulated for all input by removing the newline.
Another example with a function:
function broken() { con
sole.log(5) }
This fails in the repl and it should because it's a syntax error. Going back with the history will now "fix" the syntax error.
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.
@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:
var a = 5
{
a:3
}
var b = 5
Otherwise all existing history entries become a huge multiline statement and we don't want that ;-).
Activity
[-]repl: handling multiline history needs comment stripping[/-][+]repl: handling multiline history needs some case guards[/+]antsmartian commentedon Nov 8, 2018
Thanks. I will have a look at it today.
antsmartian commentedon Nov 8, 2018
@vsemozhetbyt: The second issue, I guess I couldn't able to reproduce it (atleast on master).
First one yes, its an issue. Good catch.
vsemozhetbyt commentedon Nov 8, 2018
@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
`a\nb\nc`, not the`abc`.antsmartian commentedon Nov 8, 2018
Hmmm, but current history doesn't show as
\nindeed. Its the result of an expression, but history just saves what user types right? Not the result. Thoughts?vsemozhetbyt commentedon Nov 8, 2018
I mean, for me it seems these cases should be handled equally:
Otherwise, we had wrong value second time.
shobhitchittora commentedon Nov 13, 2018
@vsemozhetbyt The way I see it to handle the
comment, you need to check for every line inrepland check if it has a comment. Also you'll want to skip this check for string literals. Weird cases to check thought ! 😛antsmartian commentedon Nov 16, 2018
@shobhitchittora : Yes you are right. But fundamentally, on multiline we call
acronparser to see if we can expect more tokens or give up with errors. So in the same way, we need to handle this as well. Because code with comment, might not run in history as @vsemozhetbyt shown above. To me its a bug.BridgeAR commentedon Dec 2, 2018
The current way how multilines are saved is just wrong. A line is detected when the newline character (
\n) is detected. Now that line is added to potential former ones and therefore stripping the new lines. This is changing the actual input and causes multiple issues.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.
targos commentedon Dec 2, 2018
Copying from #24781 (comment)
Is there no way for us to keep the line breaks? That's what
zshdoes.BridgeAR commentedon Dec 2, 2018
@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?
antsmartian commentedon Dec 2, 2018
@BridgeAR
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
kBufferedCommandSymbolon repl, I guess that's the sole reason here as it doesn't work for template literals and like)BridgeAR commentedon Dec 2, 2018
@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
repland it should because it's a syntax error. Going back with the history will now "fix" the syntax error.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.
antsmartian commentedon Dec 2, 2018
@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.
8 remaining items
BridgeAR commentedon Dec 3, 2018
@antsmartian the second entry should look like:
'{\na:3\n}'.antsmartian commentedon Dec 3, 2018
@BridgeAR : Yup, its a typo. Fixed.
BridgeAR commentedon Dec 4, 2018
@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 ;-).
Revert "repl: handle buffered string logic on finish"
Revert "lib: repl multiline history support"
Revert "repl: handle buffered string logic on finish"
Revert "lib: repl multiline history support"
Revert "repl: handle buffered string logic on finish"
Revert "lib: repl multiline history support"
Revert "repl: handle buffered string logic on finish"
Revert "lib: repl multiline history support"
Revert "repl: handle buffered string logic on finish"
Revert "lib: repl multiline history support"
BridgeAR commentedon Dec 13, 2019
I am closing this, since the feature itself was reverted and has not been added back so far.