Skip to content

repl: handling multiline history needs some case guards #24231

Description

@vsemozhetbyt
  • Version: master
  • Platform: Windows 7 x64
  • Subsystem: repl
  1. 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.

  1. Another case that needs special handling, multiline template literals:
> `a
... b
... c`
'a\nb\nc'
> bc`
...

cc @antsmartian

Activity

  1. added
    replIssues and PRs related to the REPL subsystem.
    on Nov 7, 2018
  2. changed the title [-]repl: handling multiline history needs comment stripping[/-] [+]repl: handling multiline history needs some case guards[/+] on Nov 7, 2018
  3. antsmartian commented on Nov 8, 2018

    @antsmartian
    Contributor

    Thanks. I will have a look at it today.

  4. antsmartian commented on Nov 8, 2018

    @antsmartian
    Contributor

    @vsemozhetbyt: The second issue, I guess I couldn't able to reproduce it (atleast on master).

    > `a
    ... b
    ... c`
    'a\nb\nc'
    > `abc`
    

    First one yes, its an issue. Good catch.

  5. vsemozhetbyt commented on Nov 8, 2018

    @vsemozhetbyt
    ContributorAuthor

    @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`.

  6. antsmartian commented on Nov 8, 2018

    @antsmartian
    Contributor

    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?

  7. vsemozhetbyt commented on Nov 8, 2018

    @vsemozhetbyt
    ContributorAuthor

    I mean, for me it seems these cases should be handled equally:

    > `a\nb\nc`
    'a\nb\nc'
    > `a\nb\nc` // UP ARROW
    'a\nb\nc'
    > `a
    ... b
    ... c`
    'a\nb\nc'
    > `abc` // UP ARROW
    'abc'
    

    Otherwise, we had wrong value second time.

  8. shobhitchittora commented on Nov 13, 2018

    @shobhitchittora
    Contributor

    @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 ! 😛

  9. antsmartian commented on Nov 16, 2018

    @antsmartian
    Contributor

    @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.

  10. BridgeAR commented on Dec 2, 2018

    @BridgeAR
    Member

    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.

  11. targos commented on Dec 2, 2018

    @targos
    Member

    Copying from #24781 (comment)

    Is there no way for us to keep the line breaks? That's what zsh does.

  12. BridgeAR commented on Dec 2, 2018

    @BridgeAR
    Member

    @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?

  13. antsmartian commented on Dec 2, 2018

    @antsmartian
    Contributor

    @BridgeAR

    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)

  14. BridgeAR commented on Dec 2, 2018

    @BridgeAR
    Member

    @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.

  15. antsmartian commented on Dec 2, 2018

    @antsmartian
    Contributor

    @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.

  16. 8 remaining items

  17. BridgeAR commented on Dec 3, 2018

    @BridgeAR
    Member

    @antsmartian the second entry should look like: '{\na:3\n}'.

  18. antsmartian commented on Dec 3, 2018

    @antsmartian
    Contributor

    @BridgeAR : Yup, its a typo. Fixed.

  19. BridgeAR commented on Dec 4, 2018

    @BridgeAR
    Member

    @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 ;-).

  20. BridgeAR commented on Dec 13, 2019

    @BridgeAR
    Member

    I am closing this, since the feature itself was reverted and has not been added back so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions