-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #1369 Print a newline after interpreted commands #3911
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
Conversation
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
@@ -272,7 +272,7 @@ class ReplDriver(settings: Array[String], | |||
( | |||
typeAliases.map("// defined alias " + _.symbol.showUser) ++ | |||
defs.map(rendering.renderMethod) ++ | |||
vals.map(rendering.renderVal).flatten | |||
vals.map(rendering.renderVal).distinct |
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.
How is scala> print("Hello"); print("Hello")
rendered with this fix?
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.
scala> print("Hello"); print("Hello")
HelloHello
scala>
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.
What about val foo = 2; (); val bar = 3
?
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.
scala> val foo = 2; (); val bar = 3
val foo: Int = 2
val bar: Int = 3
scala>
The sequence keeps the order. Maybe Units could be dropped if there's something else in the renderVal sequence.
That would produce this:
scala> print("Hello"); val foo = 2; (); val bar = 3
Helloval foo: Int = 2
val bar: Int = 3
scala>
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.
Yes, something like:
val renderedVals =
vals.flatMap(rendering.renderVal)
val toRender =
typeAliases.map("// defined alias " + _.symbol.showUser) ++
defs.map(rendering.renderMethod) ++
renderedVals
toRender.foreach(str => out.println(SyntaxHighlighting(str)))
if (renderedVals.isEmpty && vals.nonEmpty)
out.println() // prints new line for side-effectful unit value (see #1369)
I would also be fine with a solution, that prints an additional new line for each command interpreted.
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.
Yeah, this Unit based solution has many edge cases.
So something like this at ReplDriver.scala:195?
case parsed: Parsed if parsed.trees.nonEmpty =>
val newState = compile(parsed)
.withHistory(parsed.sourceCode :: state.history)
.newRun(compiler, rootCtx)
out.println()
newState
Can you add back the test case? Otherwise LGTM |
Sure. However I just realised that in this from it's not useful because end of line whitespaces are cut out by this function. So I will add it as a "whitespace sensitve" test, probably in a different folder. |
You can rebase to fix the CI failures |
Thank you! |
Can you give a motivation for changing the testing framework? We don't really want to test that the repl prints a new line or not but rather make sure that the repl is not going to eat the output of a command. Do you need to modify the testing framework to test something like: scala> print("foo")
foo If not, I'd rather keep the testing framework at it is. |
If I do something like this:
It still doesn't work in the tests with this fix.
So I'm not sure how to test this. |
Nice catch! The output of |
I have opened #3940, which should solve this problem |
#3940 has been merged. Can you rebase and append a test to https://github.com/dotty-staging/dotty/blob/f068bea112b7f3a9274a61ee5ea3f845e2c11c39/compiler/test-resources/repl/outputStream: scala> print("foo") // see #1369
foo |
Now the prints go to the proper place (after adding a print function to the ReplTest class). The reason seems to be that we don't call prompt printing in the tests, only the interpret function. |
Currently I don't have a better idea than doing something like echo 'print("asd") ' | ./bin/dotr And checking the output. But it's probably too slow. |
@allanrenucci Could you have another look at this PR and see what can be done to get it merged? Thanks. |
It used to capture output only from 'println(String | Object)'
@benkobalog I dropped the commit for the REPL tests. I'll fix them in a separate PR |
Sorry for the late review. Thanks @benkobalog 🎉 |
Keeping only one newline for Unit values if there are more of them in a command.